-
Notifications
You must be signed in to change notification settings - Fork 437
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
Add lambdas with statements / local functions in imp syntax #562
Comments
Another advantage of the second syntax is that it would be similar to python (except for the lack of |
I apologize for the off-topic comment. When I first saw Bend, during the recent hype cycle, I was very excited. Looking at the issues section, I'm in awe of your diligence. There is obviously great work happening here and I just want to leave you with these words of encouragement. I'm very impressed, and you should be proud of all this progress. |
Thank you very much for your words. If there's anything specific you'd like to see in Bend, please create an issue and we'll be happy to at least look into it. |
The main thing I noticed was lacking when I first looked was that there seemed to only be one datatype which was an integer of a certain size. That indicated to me a lack of maturity and because of it, I expected to encounter other things missing, if the project was still at such an early stage. Judging by the issues, floats have been added, which is good. I don't have a specific project in mind at the moment that Bend would be a good fit for, so I'm afraid I don't have much useful input regarding important next features. The current issue list seems good though. atan2 is for example a useful addition, as well as the lambda idea in this issue, and a file reading issue I saw. So I believe you're on a good track already. I'll be watching the project, and will have it in mind for any future projects. If I ever think of something useful, I'll suggest it, or contribute. Thanks again and good luck! |
Having some time to things about it, I think we should add both lambdas with statements and local functions. I'm thinking that we'll use high order functions a lot for error handling (things like In python this is not much of a concern since errors are exception that you catch and lambdas are very rare. |
While writing some more Bend code, I noticed that it would also be useful to have local functions in fun syntax. |
…-syntax #562 Local functions in imp syntax
Currently, in imp syntax there is no way of writing lambdas that have statements in them.
We can raise them to proper top-level functions, but then any captured variables must be passed through additional arguments, which increases the overhead.
But the main problem is that it's very inconvenient to do so. Instead we'd like a way to write lambdas with statements like we can do in Fun syntax.
I'll propose two possible syntaxes here.
Here
lambda x
defines a block for a local anonymous function bound to variablex
.I thought of this as just a simple lambda/closure, that can freely capture variables and doesn't get lifted into a separate definition.
Another option is
This defines a function that is raised as a top-level. Captured variables are passed as arguments implicitly through a
use
term, like thisThis allow local functions to be recursive, but adds an overhead compared to just a simple lambda. And if the lambda is affine, it will get floated anyway.
I don't know which is better, need to think more about it.
I think we don't need both syntaxes, but that could also be an option.
Also, note that either syntax could have either of the described behaviours, I just think that they sort of imply intuitively the behaviours i described.
The text was updated successfully, but these errors were encountered: