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

Easier way to make anonymous functions #25

Closed
pdeffebach opened this issue Mar 23, 2021 · 6 comments
Closed

Easier way to make anonymous functions #25

pdeffebach opened this issue Mar 23, 2021 · 6 comments

Comments

@pdeffebach
Copy link
Contributor

I'm imagining somehtin like @aside but which takes in _ and returns whatever the expression returns.

@chain 1 begin 
    @anon begin 
        _ + 2 * 1000
     end
     mean()
end

I've been thinking of doing an @anon macro in DataFramesMeta, since the infrastructure is all there to do it with Symbols. However this would need to be different, special-casing _.

@jkrumbiegel
Copy link
Owner

jkrumbiegel commented Mar 23, 2021

Can you give a more realistic example, what you wrote here works already without @anon around it

@pdeffebach
Copy link
Contributor Author

Yeah, I'm thinking intermediate variables as well

@chain 1 begin 
    @anon begin 
        x = 500 
        z = 78
        _ + x * z
    end
end

@jtrakk
Copy link

jtrakk commented Mar 23, 2021

Is that the same as this?

@chain 1 begin 
    y-> begin 
        x = 500 
        z = 78
       y + x * z
    end
end

@pdeffebach
Copy link
Contributor Author

hmmm yes it is. That's definitely easier.

Though I guess that solution incurs a compilation cost that could be avoided if we let things happen in the normal scope. (This goes against my @anon name)

It also enables the user to leave the world of _, which complicates things.

@jkrumbiegel
Copy link
Owner

@chain 1 begin 
    begin 
        x = 500 
        z = 78
        _ + x * z
    end
end

@pdeffebach
Copy link
Contributor Author

Oh no kidding. I thought I tried that. Excellent!

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

No branches or pull requests

3 participants