4 ms·
Wouldn't this work: (destructuring-bind (a b c) '(10 20 30) c) ? Destructuring is also supported in the LOOP macro (http://www.cs.cmu.edu/Groups/AI/html/c
by klibertp 10y ago
Wouldn't this work:
(destructuring-bind (a b c) '(10 20 30) c)
? Destructuring is also supported in the LOOP macro (http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node252.html http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node252.html)
I don't think this article was written for the non-users of Lisp, it uses too many advanced language features without any explanation to be accessible to non-Lispers.
- abritinthebay 10y agoThats... similar but I wouldn't call it "more elegant". It's less clear in almost every way. Why c? Why the quote? Why not have elegant language syntax instead of that clunky macro?
- klibertp 10y agoI put `c` there because `destructuring-bind` is lexically scoped and only binds values to names inside of it. This may be a good or a bad thing, depending on your use case, but I prefer having the scopes clearly visible. The quote is a multi-purpose element of the syntax, unlike `[` in Python, which only serves a single purpose (actually, it doubles as an item getter syntax). Whether having a single, more universal construct which you can use in many situations, or having a few more specialized constructs is more elegant is debatable and I think a matter of taste. The problem with having specialized syntax for this is that it's not extensible. For example, we (I'm a Python programmer, too) had to wait for 3.4 (IIRC) for a very simple feture of `a, b, *c = range(10)`; with a language built on macros you can extend these constructs as much as you wish. For example adding support for destructuring hash-maps (if it's not supported already) shouldn't be a big problem; on the other hand adding a specialized syntax for dict destructuring in Python is impossible within a language.
- abritinthebay 10y agoGood explaination! Thank you! That does explain it very well but I'd also argue that a syntax that requires that much explaining probably can't be called "elegant". Powerful though? Yes. Lips syntax certainly is that.