Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify chain logic #54

Merged
merged 6 commits into from
Feb 22, 2024
Merged

Simplify chain logic #54

merged 6 commits into from
Feb 22, 2024

Conversation

jkrumbiegel
Copy link
Owner

@jkrumbiegel jkrumbiegel commented Feb 21, 2024

Fixes #51

Breaking: The rules for transforming chains were simplified.
Before, there was the two-arg block syntax (this was the only syntax originally):

@chain x begin
    y
    z
end

the inline syntax:

@chain x y z

and the one-arg block syntax:

@chain begin
    x
    y
    z
end

All of these are now a single syntax, derived from the rule that any begin ... end block in the inline syntax is flattened into its lines.
This means that you can also use multiple begin ... end blocks, and they can be in any position, which can be nice for interactive development of a chain in the REPL.

@chain x y begin
    x
    y
    z
end u v w begin
    g
    h
    i
end

This is only breaking if you were using a begin ... end block in the inline syntax at argument 3 or higher, but you also had to be using an underscore without chaining in that begin block, which is deemed quite unlikely given the intended use of the package.
All "normal" usage of the @chain macro should work as it did before.

As another consequence of the refactor, chains now do not error anymore for a single argument form @chain x but simply return x.

@jkrumbiegel
Copy link
Owner Author

jkrumbiegel commented Feb 21, 2024

@pdeffebach @bkamins any objections to this? I have not seen any @chain use in the wild that would be affected by the "breaking-ness" of this change. On the flipside it could potentially enable a more flexible way of working in the REPL and it simplifies the implementation.

@bkamins
Copy link

bkamins commented Feb 21, 2024

I think it is OK. In summary - now begin-end block is just flattened right? (so it has no special meaning except for following Julia parsing rules). I assume the same applies to (; ; ; ) blocks?

@jkrumbiegel
Copy link
Owner Author

jkrumbiegel commented Feb 22, 2024

@bkamins yes any block just decomposes into lines, and the three previous syntax options derive from that rule plus it removes some weird edge cases I had before.
And (; ; ;) blocks seem to parse as Expr(:block, as well, so yeah those will have the same flattening behavior.

@jkrumbiegel jkrumbiegel merged commit df30824 into master Feb 22, 2024
18 checks passed
@pdeffebach
Copy link
Contributor

Thanks! This will be helpful for tacking on extra things at the end for debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Single call inline chain fails
3 participants