Subject: Re: Can you help me get rid of the setf?
From: (Rob Warnock)
Date: Thu, 16 Aug 2007 22:05:23 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Ken Tilton  <> wrote:
| wrote:
| > I'm looping over two variables to maximize a function, returning x and
| > y that maximize f.  Any way to do it without the setf in the body?
| meanwhile, I /do/ think loop needs:
|      maximize x into outer-best-x and y into outer-best-y and...
| I need it about once a month, that should be good enough for the ANSI 
| committee.

I do agree that LOOP's lack of nestable lexical scopes is a pain,
but waiting for ANSI is like... What was that guy's name...? Godot?

While you're waiting, CMUCL has COLLECT, the ITERATE package has,
well, ITERATE, and even plain ol' ANSI CL LOOP can be coerced
(screaming & kicking) into doing *something* along these lines,
albeit plug-ugly:

    > (loop for i below 10
	    for (tmp-x . tmp-y) =
		(loop for j below 10
		      for x = (+ (* i i) (* j j))
		      and y = (- (* i i) (* j j))
		   maximize x into inner-best-x       
		   maximize y into inner-best-y
		   finally (return (cons inner-best-x inner-best-y)))
	maximize tmp-x into outer-best-x
	maximize tmp-y into outer-best-y        
	finally (return (cons outer-best-x outer-best-y)))        

    (162 . 81)


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607