From: Jonathan LF King
Subject: Q: `loop' and local variables
Date: 
Message-ID: <xndu2hqzy7g.fsf@infinity.math.ufl.edu>
[Caveat: I currently do not have access to CL and am, instead, running Emacs
Lisp (EL) with the CL compatibility package.]

Dear Cognoscenti, I have an elementary `loop' question.  I would like the
functionality of 

    (let ((A 5) b c d)
      (function-setting-bcd-depending-on-A  A )
      (loop
	<loopy-code using A b c d>   ))

For purely esthetic reasons, I wonder if I can do this with just `loop' and no
`let'; something like

    (loop with A = 5	with b    with c    with d
      initially (function-setting-bcd-depending-on-A A)
      <loopy-code using A b c d>  )

However, the `initially' isn't executed until `for from' statements are
executed once (although `for = ' are not).  Here is test code run in EL-CL:

    (loop   with m = 5
	    initially (incf m 100)
	    for k = (* 10 m)
	    for j from m upto 7
	    do (echo-vars j k m)
	    )
    j: 5  k: 1050  m: 105  
    j: 6  k: 1050  m: 105  
    j: 7  k: 1050  m: 105  
    nil

================
Alternatively, is there a way to have `loop' expand a macro, e.g, I replace 
`function-setting-bcd-depending-on-a' with a macro `frob-bcd-depending-on-a',
then type something like: [Incorrect syntax]

    (loop 
      (frob-bcd-depending-on-A 5)
      <loopy-code using A b c d>   )

which somehow expands to

    (loop with A = 5		with b = <fnc1-of A>
	  with c = <fnc2-of A>	with d = <fnc3-of A>
	  <Code using A b c d> 
	  )

What a correct/reasonable way to do this?  Should I just use  let + loop ?
Sincerely, -Jonathan King
-- 
Prof. Jonathan King,	Mathematics dept, Univ. of Florida
······@math.ufl.edu	<http://www.math.ufl.edu/~squash/>
From: Tom Breton
Subject: Re: Q: `loop' and local variables
Date: 
Message-ID: <m3ln32n0w6.fsf@world.std.com>
Jonathan LF King <······@math.ufl.edu> writes:

> [Caveat: I currently do not have access to CL and am, instead, running Emacs
> Lisp (EL) with the CL compatibility package.]
> 
> Dear Cognoscenti, I have an elementary `loop' question.  I would like the
> functionality of 
> 
>     (let ((A 5) b c d)
>       (function-setting-bcd-depending-on-A  A )
>       (loop
> 	<loopy-code using A b c d>   ))
> 
> For purely esthetic reasons, I wonder if I can do this with just `loop' and no
> `let'; something like

Sure, `with' is essentially `let' out of place.


> However, the `initially' isn't executed until `for from' statements are
> executed once (although `for = ' are not).  

Not exactly correct, the `for' variables are bound to their initial
values before initially.  Since you're in emacs, it's in the cl manual
(C-h i m cl m loop m control m other).

 
> ================
> Alternatively, is there a way to have `loop' expand a macro, e.g, I replace 
> `function-setting-bcd-depending-on-a' with a macro `frob-bcd-depending-on-a',
> then type something like: [Incorrect syntax]
> 
>     (loop 
>       (frob-bcd-depending-on-A 5)
>       <loopy-code using A b c d>   )
> 
> which somehow expands to
> 
>     (loop with A = 5		with b = <fnc1-of A>
> 	  with c = <fnc2-of A>	with d = <fnc3-of A>
> 	  <Code using A b c d> 
> 	  )

No, because a macro will only expand to one object, while loop
requires multiple objects to express things like "with A = 5".  This
is one more reason why loop should have used real Lisp syntax.

-- 
Tom Breton, http://world.std.com/~tob
Not using "gh" since 1997. http://world.std.com/~tob/ugh-free.html
Rethink some Lisp features, http://world.std.com/~tob/rethink-lisp/index.html