-
Notifications
You must be signed in to change notification settings - Fork 15
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
Suggestion: let-binding #46
Comments
Hmm. The let-binding currently does not destructure -
If Do you think we ought to implement destructuring? |
Oh right; sorry I wasn't clear. I know we don't do any destructuring
right now, but I think making a change now to how let works will allow
it to be added in the future.
I think it's fairly uncontroversial to say that having destructuring is
a step forward; there is no runtime cost to it, and it makes for much
tidier code. Perhaps you could make the case that destructuring should
only be part of a separate pattern matching macro instead of part of let
though.
I just assumed the reason let didn't support destructuring was just
because it hadn't been implemented yet, but if you feel differently
about it I'd like to hear your opinion.
|
In that case, let's go with your syntax. Thinking only of Lua when I wrote the let-macro I did not think of destructuring. You're right it will make it much tidier. |
Perhaps, we could implement pattern matching:
The pattern matching would only work for We can define an interface for implementing pattern-matching for the let macro for other custom data structures It looks like a good challenge... |
I think I follow what you're saying here, but I would try to avoid the use of the term "pattern matching" for this as that already has a very specific meaning that could be very confusing because it overlaps with this in some ways: http://c2.com/cgi/wiki?PatternMatching I think l2l should have traditional pattern matching too, but what you're describing in the snippet above is more commonly referred to as destructuring. And it sounds like specifically you're saying that on line two if you want to bind to a function that returns multiple values, wrapping that in a table would be a better way to deal with the syntactic ambiguity than requiring every name/value pair to be delimited by parens a la Scheme's Naively it looks like this style would require more allocation overhead because it looks like a table is being constructed, but since that is statically determinable at compile time, it's easy to detect that case and bind directly to the values being returned so that the |
Ok. Yes that's exactly it. |
The destructuring is only implemented for tables and list currently. Example test cases:
|
Currently let-binding works like Clojure instead of the traditional Scheme/CL style:
In general I think this is nice; however, the difference between Clojure and l2l is that Clojure doesn't support multiple return values, so
(let [[a b] (f)] ...)
will destructure the return value off
into two locals. Since we have to support multiple return values, there is some ambiguity about whether binding to two locals would work with multiple values or whether it would destructure.Personally I am of the opinion that a data structure on the left-hand side should correspond with destructuring a data structure on the right-hand side. So how would it be possible to bind to multiple values? I think it could be done by reintroducing Scheme-style
let
which has an extra level of parens around each binding group:It is a little more syntactically noisy, but I believe it is more consistent and flexible if we want to allow the goals of both binding to multiple values and supporting destructuring of data structures.
What do you think?
The text was updated successfully, but these errors were encountered: