From: Jon Boone
Subject: writing my own version of loop
Date: 
Message-ID: <m3abtxll3a.fsf@janus.delamancha.org>
Folks,

  I am reading through Patrick Harrison's
  _Common_Lisp_&_Artificial_Intelligence_ and have just finished the
  chapter on macros.  One of the problems presented at the end of the
  chapter involves writing a loop macro that has the following
  syntax: 

  LOOP {form}* UNTIL test

  I have come up with the following solution, but I'm not happy with
  it.  Does anyone else have suggestions on how to improve it?  

  (defmacro my-loop (&body body)
    (let* ((start (gensym))
           (end (gensym))
           (smorf (reverse body))
           (test (car smorf))
           (forms (reverse (cddr smorf))))
    `(tagbody
      ,start
        ,@forms
        (if ,test (go ,end))
        (go ,start)
      ,end nil)))

--jon

From: D Herring
Subject: Re: writing my own version of loop
Date: 
Message-ID: <muOdnSTewfa72wfbnZ2dnUVZ_u2mnZ2d@comcast.com>
Jon Boone wrote:
>   I am reading through Patrick Harrison's
>   _Common_Lisp_&_Artificial_Intelligence_ and have just finished the
>   chapter on macros.  One of the problems presented at the end of the
>   chapter involves writing a loop macro that has the following
>   syntax: 
> 
>   LOOP {form}* UNTIL test
> 
>   I have come up with the following solution, but I'm not happy with
>   it.  Does anyone else have suggestions on how to improve it?  
> 
>   (defmacro my-loop (&body body)
>     (let* ((start (gensym))
>            (end (gensym))
>            (smorf (reverse body))
>            (test (car smorf))
>            (forms (reverse (cddr smorf))))
>     `(tagbody
>       ,start
>         ,@forms
>         (if ,test (go ,end))
>         (go ,start)
>       ,end nil)))

Ideas:
- Use last/butlast to separate the body.
- replace the 'if and 'end with a single 'unless

HTH,
Daniel
From: Ari Johnson
Subject: Re: writing my own version of loop
Date: 
Message-ID: <m2644l4m39.fsf@hermes.theari.com>
Jon Boone <········@delamancha.org> writes:

> Folks,
>
>   I am reading through Patrick Harrison's
>   _Common_Lisp_&_Artificial_Intelligence_ and have just finished the
>   chapter on macros.  One of the problems presented at the end of the
>   chapter involves writing a loop macro that has the following
>   syntax: 
>
>   LOOP {form}* UNTIL test
>
>   I have come up with the following solution, but I'm not happy with
>   it.  Does anyone else have suggestions on how to improve it?  
>
>   (defmacro my-loop (&body body)
>     (let* ((start (gensym))
>            (end (gensym))
>            (smorf (reverse body))
>            (test (car smorf))
>            (forms (reverse (cddr smorf))))
>     `(tagbody
>       ,start
>         ,@forms
>         (if ,test (go ,end))
>         (go ,start)
>       ,end nil)))
>
> --jon

Try:

(defmacro my-loop (&body body)
  (let* ((start-label (gensym "START"))
         (name (gensym "LOOP")) ; Later, you could add a NAME clause
         (return-form nil) ; ...or a RETURN/FINALLY clause
         (until-clause (do ((x body (cdr x)))
                           ((and (symbolp (cadr x))
                                 (string= (symbol-name (cadr x)) "UNTIL"))
                            (let ((rest (cdr x))) (rplacd x nil) rest))))
         (until-test (cadr until-clause)))
    `(block ,name
       (tagbody
         ,start-label
         (when ,until-test
           (return-from ,name ,return-form))
         ,@body
         (go ,start-label)))))
From: Jon Boone
Subject: Re: writing my own version of loop
Date: 
Message-ID: <m3zm1winrg.fsf@janus.delamancha.org>
    Thanks Ari!  Something like this was knocking around the back of
  my brain, but I couldn't get it to come out. 

--jon
From: Madhu
Subject: Re: writing my own version of loop
Date: 
Message-ID: <m3lkdgvats.fsf@robolove.meer.net>
* Jon Boone <··············@janus.delamancha.org> :
|   LOOP {form}* UNTIL test
|
|   I have come up with the following solution, but I'm not happy with
|   it.  Does anyone else have suggestions on how to improve it?  
|

Use LOOP :)

;; implements LOOP {FORM}+ UNTIL TEST
;;
(defmacro my-loop (&body body)
  (loop for (a b c . rest) on body
        when (endp rest) return `(loop ,b ,c do ,@forms ,a)
        else collect a into forms))



|   (defmacro my-loop (&body body)
|     (let* ((start (gensym))
|            (end (gensym))
|            (smorf (reverse body))
|            (test (car smorf))
|            (forms (reverse (cddr smorf))))
|     `(tagbody
|       ,start
|         ,@forms
|         (if ,test (go ,end))
|         (go ,start)
|       ,end nil)))

-- 
Madhu
From: Ken Tilton
Subject: Something Happened
Date: 
Message-ID: <iaMmi.4$ip4.1@newsfe12.lga>
We have never had traffic like this on c.l.l during the Northern 
Hemisphere summer.

kt
From: Rob Warnock
Subject: Re: Something Happened
Date: 
Message-ID: <mumdnYOkvJmqggHbnZ2dnUVZ_sjinZ2d@speakeasy.net>
Ken Tilton  <·········@gmail.com> wrote:
+---------------
| We have never had traffic like this on c.l.l
| during the Northern Hemisphere summer.
+---------------

Global warming?  ;-}

Or just more programmers warming to Lisp...?


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Ken Tilton
Subject: Re: Something Happened
Date: 
Message-ID: <m3Ymi.9867$iN.843@newsfe12.lga>
Rob Warnock wrote:
> Ken Tilton  <·········@gmail.com> wrote:
> +---------------
> | We have never had traffic like this on c.l.l
> | during the Northern Hemisphere summer.
> +---------------
> 
> Global warming?  ;-}
> 
> Or just more programmers warming to Lisp...?

No, it is something specific, the upturn is too sharp. Aftershock of 
Ruby on Rails? The moth got too close to the flame?

kt
From: Jeff Shrager
Subject: Re: Something Happened
Date: 
Message-ID: <1184686329.467433.214650@x35g2000prf.googlegroups.com>
On Jul 16, 10:04 pm, Ken Tilton <···········@optonline.net> wrote:
> Rob Warnock wrote:
> > Ken Tilton  <·········@gmail.com> wrote:
> > +---------------
> > | We have never had traffic like this on c.l.l
> > | during the Northern Hemisphere summer.
> > +---------------
>
> > Global warming?  ;-}
>
> > Or just more programmers warming to Lisp...?
>
> No, it is something specific, the upturn is too sharp. Aftershock of
> Ruby on Rails? The moth got too close to the flame?
>
> kt

Maybe this:

  http://it.slashdot.org/article.pl?sid=07/01/14/0336213

???
From: Ken Tilton
Subject: Re: Something Happened
Date: 
Message-ID: <xF5ni.99$ip4.53@newsfe12.lga>
Jeff Shrager wrote:
> On Jul 16, 10:04 pm, Ken Tilton <···········@optonline.net> wrote:
> 
>>Rob Warnock wrote:
>>
>>>Ken Tilton  <·········@gmail.com> wrote:
>>>+---------------
>>>| We have never had traffic like this on c.l.l
>>>| during the Northern Hemisphere summer.
>>>+---------------
>>
>>>Global warming?  ;-}
>>
>>>Or just more programmers warming to Lisp...?
>>
>>No, it is something specific, the upturn is too sharp. Aftershock of
>>Ruby on Rails? The moth got too close to the flame?
>>
>>kt
> 
> 
> Maybe this:
> 
>   http://it.slashdot.org/article.pl?sid=07/01/14/0336213
> 

Strong candidate for most proximate incarnation of RoR aftershock. What 
is inescapable in that discussion is that Lisp really no longer is the 
crazy aunt in the attic.

kt
From: Pillsy
Subject: Re: Something Happened
Date: 
Message-ID: <1184785220.543332.84520@i13g2000prf.googlegroups.com>
On Jul 17, 11:59 am, Ken Tilton <···········@optonline.net> wrote:
[...]
> What is inescapable in that discussion is that Lisp really no longer
> is the crazy aunt in the attic.

Dynamic languages are hip again, and Common Lisp is the '70s muscle
car of dynamic languages. It's big and and old and resource hungry and
lacks some modern amenities, but when you get right down to it, it's
fast and powerful and as cool as anything on the road.

Cheers,
Pillsy
From: Ken Tilton
Subject: Re: Something Happened
Date: 
Message-ID: <90Dni.15066$xe1.7548@newsfe12.lga>
Pillsy wrote:
> On Jul 17, 11:59 am, Ken Tilton <···········@optonline.net> wrote:
> [...]
> 
>>What is inescapable in that discussion is that Lisp really no longer
>>is the crazy aunt in the attic.
> 
> 
> Dynamic languages are hip again,...

That happened long ago with Python's ascendance to langue du jour. 
Something /just/ happened.

Time for another survey, or to rehype..

    http://wiki.alu.org/The_RtLS_by_Switch_Year

oh, look, unsolicited life on the RtL, usually I have to hawk it.

This long entry might be representative (and, yes, it looks like RoR 
should get the credit for the quantum leap):

    http://bendiken.net/2007/01/01/the-road-to-lisp

Wow, Google fight now has Ruby winning 102m to 82m, just a few months 
ago it was even. And if you read the most recent RtLs you can see folks 
see Ruby as much more powerful than Python. ie, it ain't the dynamism, 
it is the FP thing, and proper closures which Guido almost took out.

But anyone who escapes to Python and then escapes to Ruby (where Lisp 
gets a lot of cred) will barely get their suitcase unpacked before they 
are reading Lisp brochures, too damn close.

Game over?

kt
From: David Young
Subject: Re: Something Happened
Date: 
Message-ID: <1184852892.584469.299520@e16g2000pri.googlegroups.com>
That's one of the best descriptions of Common Lisp I've read.

-- david
From: Ken Tilton
Subject: Re: Something Happened
Date: 
Message-ID: <haMni.36$vW7.35@newsfe12.lga>
David Young wrote:
> That's one of the best descriptions of Common Lisp I've read.

You mean of course:

  http://bendiken.net/2007/01/01/the-road-to-lisp

Yep, great stuff, and it confirms the Path Ineluctable: static -> Python 
-> Ruby -> Lisp, aided and abetted by Graham's cheerleading.

That would have made it to #1 on my Top Ten list if (a) I was still 
maintaining it and (b) the wheels did not come off at the end of his Road:

> The Scheme community is a much more chaotic, fragmented space, but at least the lights are still on. 

Hunh, and I thought he liked macros. Anyway, I just hope he does not 
show his face here on c.l.l -- I put that quotation on the lockerroom 
door and the hounds are out of control. They see great in the dark, too.

> Lisp is literally the perfect language for reinventing itself, and I think it�s about time it did so.

Ron (and Ilias) has a new friend!

kenny
From: Ken Tilton
Subject: Call for Roads [was Re: Something Happened]
Date: 
Message-ID: <2NMni.32$Zi.8@newsfe12.lga>
One last thought:

>  http://bendiken.net/2007/01/01/the-road-to-lisp
> 
>> Lisp is literally the perfect language for reinventing itself, and I 
>> think it�s about time it did so.

It is said one should do the tai chi form for thirty years before 
thinking of changing it. Something like that. Anyway...

I think I see what is going on, but it would still be interesting to 
hear from the rugrats, either here or on RtL itself:

    http://wiki.alu.org/The_Road_to_Lisp_Survey

The question remains, in brief, why are you all bothering with a dead 
language like Lisp?

tia,kenny
From: Andrew Reilly
Subject: Re: Call for Roads [was Re: Something Happened]
Date: 
Message-ID: <pan.2007.07.20.01.17.28.355799@areilly.bpc-users.org>
On Thu, 19 Jul 2007 13:02:47 -0400, Ken Tilton wrote:

> The question remains, in brief, why are you all bothering with a dead 
> language like Lisp?

It's dynamically typed, so I don't have to fuss with spurious declarations
or casts.

It's compiled, so my own algorithms go just as fast as the canned
native library functions.

It's a fully fractal algorithm expression mechanism, without any of the
restrictions on naming, nesting or scope so prevalent in other languages.

It encourages an incremental, "improve from a working foundation" coding
style.

Well balanced and thoroughly sorted.

I'm yet green in the ways of lisp, though, and there are a few other
schools of thought out there that look promising, but which I have not yet
tried (chiefly smalltalk and the ml family), so I may yet falter and fall
off the road.  It's a pleasant journey at the moment, though.

-- 
Andrew
From: Jeff Shrager
Subject: Re: Something Happened
Date: 
Message-ID: <1185006041.354305.287150@e16g2000pri.googlegroups.com>
> Yep, great stuff, and it confirms the Path Ineluctable: static -> Python
> -> Ruby -> Lisp, aided and abetted by Graham's cheerleading.

You might recall that in Dec. of 2006 a famous flamer, who shall here
remain nameless, famously said:

"But consider: Tcl replaced Csh, Perl replaced Tcl, Python is rapidly
replacing Perl, and Ruby is simultaneously and even more rapidly
replacing Python. Each is closer to Lisp than the last; the world is
returning to Lisp ..."

In the latest results, http://www.tiobe.com/tpci.htm reports:

   Python 3.024% flat (up +0.01%)
   Ruby   2.099% Seven Up Arrows! (up +1.59%)
   Lisp   0.680% flat (up +0.16%)
       (And Lisp is at the top of the "B" list! -- under 1%, I guess)

** No other langauge beat out Ruby for increased mind share! **
From: Ken Tilton
Subject: Re: Something Happened
Date: 
Message-ID: <f%moi.1$3D1.0@newsfe12.lga>
Jeff Shrager wrote:
>>Yep, great stuff, and it confirms the Path Ineluctable: static -> Python
>>-> Ruby -> Lisp, aided and abetted by Graham's cheerleading.
> 
> 
> You might recall that in Dec. of 2006 a famous flamer, who shall here
> remain nameless, famously said:
> 
> "But consider: Tcl replaced Csh, Perl replaced Tcl, Python is rapidly
> replacing Perl, and Ruby is simultaneously and even more rapidly
> replacing Python. Each is closer to Lisp than the last; the world is
> returning to Lisp ..."


2006? Try 2003-05-16:

> Sudsy wrote:
> 
>  >... the latest bandwagon ...
> 
> woo-hoo! Lisp made it!! (to "latest" bandwagon status.)
> 
> ok, game over, i want credit for being the first to predict this. it's
> time for lispniks to add "Lisp" to their resumes.
> 
> woo-hoo! we're the langue du jour!! 

Frickin Google does not show the author, tho. Brilliant chap, clearly. 
Laser rocket arm.

kenny
From: Slobodan Blazeski
Subject: Re: Something Happened
Date: 
Message-ID: <1185044954.466731.206840@q75g2000hsh.googlegroups.com>
On Jul 21, 10:20 am, Jeff Shrager <········@gmail.com> wrote:
> > Yep, great stuff, and it confirms the Path Ineluctable: static -> Python
> > -> Ruby -> Lisp, aided and abetted by Graham's cheerleading.
>
> You might recall that in Dec. of 2006 a famous flamer, who shall here
> remain nameless, famously said:
>
> "But consider: Tcl replaced Csh, Perl replaced Tcl, Python is rapidly
> replacing Perl, and Ruby is simultaneously and even more rapidly
> replacing Python. Each is closer to Lisp than the last; the world is
> returning to Lisp ..."
>
> In the latest results,http://www.tiobe.com/tpci.htmreports:
>
>    Python 3.024% flat (up +0.01%)
>    Ruby   2.099% Seven Up Arrows! (up +1.59%)
>    Lisp   0.680% flat (up +0.16%)
>        (And Lisp is at the top of the "B" list! -- under 1%, I guess)
>
> ** No other langauge beat out Ruby for increased mind share! **

I would prefer honest graph with scheme & common lisp treated as
separate languages.
From: Slobodan Blazeski
Subject: Re: Something Happened
Date: 
Message-ID: <1185045713.359814.137260@k79g2000hse.googlegroups.com>
On Jul 21, 9:09 pm, Slobodan Blazeski <·················@gmail.com>
wrote:
> On Jul 21, 10:20 am, Jeff Shrager <········@gmail.com> wrote:
>
>
>
> > > Yep, great stuff, and it confirms the Path Ineluctable: static -> Python
> > > -> Ruby -> Lisp, aided and abetted by Graham's cheerleading.
>
> > You might recall that in Dec. of 2006 a famous flamer, who shall here
> > remain nameless, famously said:
>
> > "But consider: Tcl replaced Csh, Perl replaced Tcl, Python is rapidly
> > replacing Perl, and Ruby is simultaneously and even more rapidly
> > replacing Python. Each is closer to Lisp than the last; the world is
> > returning to Lisp ..."
>
> > In the latest results,http://www.tiobe.com/tpci.htmreports:
>
> >    Python 3.024% flat (up +0.01%)
> >    Ruby   2.099% Seven Up Arrows! (up +1.59%)
> >    Lisp   0.680% flat (up +0.16%)
> >        (And Lisp is at the top of the "B" list! -- under 1%, I guess)
>
> > ** No other langauge beat out Ruby for increased mind share! **
>
> I would prefer honest graph with scheme & common lisp treated as
> separate languages.

But I believe that world started moving to lisp. Slowly but direction
is right.
From: Terry Sullivan
Subject: Re: Something Happened
Date: 
Message-ID: <e6edd$469ffa37$186091bf$13855@KNOLOGY.NET>
Ken Tilton wrote:
> 
> 
> Rob Warnock wrote:
>> Ken Tilton  <·········@gmail.com> wrote:
>> +---------------
>> | We have never had traffic like this on c.l.l
>> | during the Northern Hemisphere summer.
>> +---------------
>>
>> Global warming?  ;-}
>>
>> Or just more programmers warming to Lisp...?
> 
> No, it is something specific, the upturn is too sharp. Aftershock of 
> Ruby on Rails? The moth got too close to the flame?
> 
> kt

As for myself, it was a couple of close encounters with the disaster 
known as C++ Templates and the resulting unreadable code.

Ts
From: Matthias Buelow
Subject: Re: Something Happened
Date: 
Message-ID: <5g2vnbF3fi90aU1@mid.dfncis.de>
Rob Warnock wrote:
> Ken Tilton  <·········@gmail.com> wrote:
> +---------------
> | We have never had traffic like this on c.l.l
> | during the Northern Hemisphere summer.
> +---------------
> 
> Global warming?  ;-}
> 
> Or just more programmers warming to Lisp...?

The first few snowballs of a thundering avalanche coming down the hill. :)
From: Slobodan Blazeski
Subject: Re: Something Happened
Date: 
Message-ID: <1184851048.480733.310200@o61g2000hsh.googlegroups.com>
On Jul 17, 6:43 am, Matthias Buelow <····@incubus.de> wrote:
> Rob Warnock wrote:
> > Ken Tilton  <·········@gmail.com> wrote:
> > +---------------
> > | We have never had traffic like this on c.l.l
> > | during the Northern Hemisphere summer.
> > +---------------
>
> > Global warming?  ;-}
>
> > Or just more programmers warming to Lisp...?
>
> The first few snowballs of a thundering avalanche coming down the hill. :)

This is all just a conspiracy by a secret society called lisperati.
From: Chris Riesbeck
Subject: Re: writing my own version of loop
Date: 
Message-ID: <5gk8clF3cd98uU1@mid.individual.net>
Madhu wrote:
> * Jon Boone <··············@janus.delamancha.org> :
> |   LOOP {form}* UNTIL test
> |
> |   I have come up with the following solution, but I'm not happy with
> |   it.  Does anyone else have suggestions on how to improve it?  
> |
> 
> Use LOOP :)

Assuming NIL is always returned and no UNTIL means an endless loop:

(defmacro my-loop (&rest l)
   (let ((until (member 'until l)))
     `(do () (,(cadr until) nil)
      ,@(ldiff l until))))

Fixing the MEMBER to be package-independent is left for the reader.

> 
> ;; implements LOOP {FORM}+ UNTIL TEST
> ;;
> (defmacro my-loop (&body body)
>   (loop for (a b c . rest) on body
>         when (endp rest) return `(loop ,b ,c do ,@forms ,a)
>         else collect a into forms))
> 
> 
> 
> |   (defmacro my-loop (&body body)
> |     (let* ((start (gensym))
> |            (end (gensym))
> |            (smorf (reverse body))
> |            (test (car smorf))
> |            (forms (reverse (cddr smorf))))
> |     `(tagbody
> |       ,start
> |         ,@forms
> |         (if ,test (go ,end))
> |         (go ,start)
> |       ,end nil)))
> 
From: Thomas A. Russ
Subject: Re: writing my own version of loop
Date: 
Message-ID: <ymik5szn95n.fsf@sevak.isi.edu>
Jon Boone <········@delamancha.org> writes:

> Folks,
> 
>   I am reading through Patrick Harrison's
>   _Common_Lisp_&_Artificial_Intelligence_ and have just finished the
>   chapter on macros.  One of the problems presented at the end of the
>   chapter involves writing a loop macro that has the following
>   syntax: 
> 
>   LOOP {form}* UNTIL test
> 
>   I have come up with the following solution, but I'm not happy with
>   it.  Does anyone else have suggestions on how to improve it?  

There are a couple of approaches.

The simplest is to use BUTLAST and LAST, which gives a very compact
solution as long as you assume that the input is well-formed (i.e., it
does no error checking:

(defmacro my-loop-trusting (&body body)
  (let ((start (gensym)))
    `(tagbody
       ,start
         ,@(butlast body 2)
       (unless ,(first (last body))
          (go ,start)))))

To actually test for the presence of the symbol UNTIL and verify that
there is only one form after it would require some additional work,
although you could fold that in pretty easily by using

  (position 'UNTIL body :form-end t)

or just testing the n-1st element of the body.  These do require running
down the list more than once, but it still remains a linear operation:

  (let ((len (length body)))
    (if (and (> len 2)  ; allows empty body.  Otherwise use > 3
             (eq (nth body (- len 2)) 'until))
        ...insert code from above...
        (error "Malformed my-loop form: ~A" body)))



-- 
Thomas A. Russ,  USC/Information Sciences Institute