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

I searched for anonymous function (and lambda function) in the docs and didn't find it #40

Closed
danr opened this issue Aug 12, 2019 · 3 comments
Labels
docs Issue about documentation

Comments

@danr
Copy link

danr commented Aug 12, 2019

Anonymous functions (lambda functions) seem either to be missing for the docs or the language ;)

@tmccombs
Copy link

I could be wrong, but my impressions from the docs is that they aren't in the language. But given that most modern languages have some kind of closure/lambda, it would probably be good to explicitly state if zig doesn't have them, and why (or maybe there are plans to add them but it hasn't happened yet?). At the very least it seems like you should be able to statically define an anonymous function from a compile time function, similar to what you can do with a struct.

@gpanders
Copy link

Anonymous functions can be used by accessing an anonymous struct, e.g.:

struct {
    fn myfunc(x: u8, y: u8) u8 {
        return x + y;
    }
}.myfunc

This is not documented anywhere but you can find examples of it in the standard library.

@kristoff-it
Copy link
Member

Closures are not in the language but they are being discussed in ziglang/zig#229

Closing until that gets resolved

@kristoff-it kristoff-it added the docs Issue about documentation label Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Issue about documentation
Projects
None yet
Development

No branches or pull requests

4 participants