jkrumbiegel / Chain.jl

A Julia package for piping a value through a series of transformation expressions using a more convenient syntax than Julia's native piping functionality.
MIT License
368 stars 16 forks source link

Make default `begin ... end` rather than `let` #30

Open pdeffebach opened 3 years ago

pdeffebach commented 3 years ago

I think it's not uncommon to want things created in @aside blocks to be visible in the outer scope of a @chain block.

If we make the default "block" for @chain to be just a begin ... end block without introducing a new scope, the user can make the same behavior with

@chain df let
    ...
end

This is something I considered in AddToField.jl and settled on begin ... end.

pdeffebach commented 3 years ago

Well, what I really would like is some way to send variables to the outer scope easily, with something like @assign intermediate = _. And I don't think this is really feasible with everything in a let block.

jkrumbiegel commented 3 years ago

yeah I guess I could actually do that. I thought I wouldn't because of all the intermediary variables, but I guess they won't interfere much? I'm not sure if there's a speed difference at global scope because the intermediary variables would be non-const. I guess one could make them const as well though

pdeffebach commented 3 years ago

I was wrong about AddToField.jl working with let though. I will fix AddToField and then apply the same strategy to a PR here.

Aren't all the intermediate variables in @chain anonymous variables? Does that make things better?

jkrumbiegel commented 3 years ago

yes they are, I just chose let in the beginning to have no trace at all of these variables. But I do think exporting a variable once in a while or saving an intermediate step can be useful