Re: a noob question

From: Tayssir John Gabbour (tayss_temp2_at_yahoo.com)
Date: 01/24/05


Date: 23 Jan 2005 15:36:46 -0800

Michael Beattie wrote:
> Why is it that some macros or whatever have double parens around
> them? Like...
>
> (let ((x 2))) ; this has 2 parens around the x=2 assignment
>
> or
>
> (do ((i 0 (+ i 1))) ; there's 2 parens around the i=0 and the
increment
> ((> i 10) 'done) ; 2 parens around the "end" condition
> (print i))
>
> I guess part of the question is "what exactly is the template for
> the do or let macro?"

Good questiron. LET's syntax is:

let ({var | (var [init-form])}*) declaration* form* => result*

If we did away with having a single "var" without an initform, which is
probably sucky practice anyway, we could do without the multiple
parens:

. (let (blah 10
. foo 20
. bar 30)
. (+ blah foo bar))

I'm guessing the Ancients didn't think of it, or really liked tacitly
initting stuff to nil. I recall Paul Graham complaining about this once
while talking about Arc. And if you think about it, setf actually is
like this when you're setting multiple things at once.

. (defmacro let- ((&rest inits) &body body)
. `(let ,(loop for i on inits by #'cddr
. collect (list (first i) (second i)))
. ,@body))

At the prompt:

. CL-USER> (macroexpand '(let- (blah 10
. foo 20
. bar 30)
. (list blah foo bar)))
.
. (let ((blah 10)
. (foo 20)
. (bar 30))
. (list blah foo bar))
. t

MfG,
Tayssir



Relevant Pages

  • Re: A speakable (kind of) SUO-KIF ?
    ... m> very few nested parens. ... m> lispy version of Lojban, ... idiomatic syntax is the way to go for a logical language. ... With macros, I hope, one could adapt the syntax to the ...
    (comp.lang.lisp)
  • Re: tail recursion guidelines
    ... since I'm at the recursion part of Touretzky's tutorial book. ... answered my question with iterative solutions. ... >> If macros are the solution, that would be interesting, too, but I'm ... parens in one place where most other languages I'm used to use them. ...
    (comp.lang.lisp)
  • Re: RAD vs. performance
    ... the parens are not good imo. ... What I like most about Lisp is having full-fledged macros, ... is whether there's another language that has enough features and syntax ...
    (comp.lang.misc)
  • Re: RAD vs. performance
    ... It just happens that the only languages I'm ... aware of that have powerful macros that are actually used have parens. ... shell syntax, but corresponds 1-to-1 to Lisp syntax). ...
    (comp.lang.misc)