From: Nicolas Neuss on
rpw3(a)rpw3.org (Rob Warnock) writes:

> Even worse, when hurriedly transliterating C to CL,
> I often find myself doing this bit of ghastliness:
>
> (let* ((tmp ...)
> (tmp ...expression_using_tmp...)
> (tmp ...another_expression_using_tmp...)
> (tmp ...you_get_the_picture...)
> ...)
> ...)
>
> (*blush*)

Looks as if might be time for a macro. I use the following:

(defmacro chain (arg &body expressions)
"Anaphoric macro on the symbol _ which allows to express a chain of
operations."
`(let ((_ ,arg))
,@(loop for expr in expressions collect `(setq _ ,expr))
_))

(chain (+ 2 3) (* _ 2) (expt _ _))

Nicolas
From: Rob Warnock on
Nicolas Neuss <lastname(a)kit.edu> wrote:
+---------------
| rpw3(a)rpw3.org (Rob Warnock) writes:
| > Even worse, when hurriedly transliterating C to CL,
| > I often find myself doing this bit of ghastliness:
| > (let* ((tmp ...)
| > (tmp ...expression_using_tmp...)
| > (tmp ...another_expression_using_tmp...)
| > (tmp ...you_get_the_picture...)
| > ...)
| > ...)
|
| Looks as if might be time for a macro. I use the following:
|
| (defmacro chain (arg &body expressions)
| "Anaphoric macro on the symbol _ which allows to express a chain of
| operations."
| `(let ((_ ,arg))
| ,@(loop for expr in expressions collect `(setq _ ,expr))
| _))
|
| (chain (+ 2 3) (* _ 2) (expt _ _))
+---------------

To each his own. I prefer bare LET*, since you can have multiple
distinct intertwined names without added contortions [other than
the obvious contortions of the quantity you're trying to compute]:

(let* ((a (init-a))
(b (init-b))
(c (init-c))
(a (foo a b c))
(b (bar b c a))
(c (baz c a b))
(a (gorp a b c))
(b (quux b c a))
(c (frob c a b)))
...)

How would you do that with CHAIN? Introduce more magic characters?
[Maybe use *, **, and *** ?!? ;-} ]


-Rob

-----
Rob Warnock <rpw3(a)rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

From: Pascal Costanza on
On 31/03/2010 03:08, Kazimir Majorinc wrote:
> Is anyone aware of "natural" occurences of the s-expressions similar to
>
> (let((x ...))
> ...
> (let((x ...))
> ...
> ...))
>
> in any Lisp dialect?

Coincidentally, in Java this is not allowed. ;)


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Nicolas Neuss on
rpw3(a)rpw3.org (Rob Warnock) writes:

> To each his own. I prefer bare LET*, since you can have multiple
> distinct intertwined names without added contortions [other than
> the obvious contortions of the quantity you're trying to compute]:
>
> (let* ((a (init-a))
> (b (init-b))
> (c (init-c))
> (a (foo a b c))
> (b (bar b c a))
> (c (baz c a b))
> (a (gorp a b c))
> (b (quux b c a))
> (c (frob c a b)))
> ...)
>
> How would you do that with CHAIN? Introduce more magic characters?
> [Maybe use *, **, and *** ?!? ;-} ]

No, I use it only in the case when I have a more complicated compose
situation (i.e. not very often). In this second example, I would use
LET* as you do. [However, your first example was of a structure fitting
to CHAIN.]

Nicolas
From: Kazimir Majorinc on
On 31.3.2010 10:40, Pascal Costanza wrote:

>
> Coincidentally, in Java this is not allowed. ;)

It is the step further in hygiene. Maybe it was Steele's influence.

Similar situation happens in combination of dynamic scope and recursive
functions or fexprs and in combination of lexical scope and recursive
macros (and "inlined" recursive functions, if such entity exist) as
well.

(define (f ...)
(let((y ...))
...
(f ...)))