3 ms·
> I can't imagine that most folks are surprised by the general shape of most defun statements. The general shape of a LOOP expression is just a list of symbo
by kbp 8y ago
> I can't imagine that most folks are surprised by the general shape of most
defun statements.
The general shape of a LOOP expression is just a list of symbols and lists. A
complicated LOOP expression that uses many features at once doesn't end up
looking very Lispy, but a shorter one like (loop :repeat 10 :do (print
'hello)) shouldn't look at all foreign, especially if you write the keywords
as keywords, which many people do.
I guess when people talk about the regularity of Lisp syntax, I think they
usually mean that (op ...args) applies the operator OP to the list ARGS. LOOP
obeys this very well: the only LOOP syntax I can think of that breaks it is
`using (hash-key k)` or with HASH-VALUE. Universally accepted macros break
this rule all the time, though. By shoving everything into lists, they totally
abandon trying to keep with the (op ...args) form. If you see that regularity
as a great advantage of Lisp's, then it seems like you should be much more
bothered by the more "mundane" macros than you should be by LOOP.
(loop :for i :below 10 :do (print i))
Is less "syntax-breaking" than:
(dotimes (i 10) (print i))
- kazinator 8y agoCommonly used loop syntax is replete with syntax that breaks "op args ...": when <condition> do for <var> in <list> for <var0> = <init0> then <step0> and for <var1> = <init1> then <step1> collecting <expr> into <var> The normal macros that don't have a flat argument structure, but shove everything into lists are keeping with the idea of leveraging the nesting so that the construct is "parsed on arrival" (POA?) into the macro. All that remains is to access its structure.
- kbp 8y agoSyntactically, those are things that could have been implemented as operators, but aren't, they're just LOOP keywords; lots of functions take keyword arguments (edit: even if LOOP's are a little different from &key parameters). LOOP avoids using unquoted lists for things other than calling operators. edit: Oh, right, destructuring, too! I guess that also counts. Out of curiosity, how would you feel about a macro like this (ignoring that it doesn't enforce any keyword order)? (defmacro for (var &key = (then =) while do) `(do ((,var ,= ,then)) ((not ,while)) ,do))