From: Tron3k
Subject: Most impressive examples of the LOOP macro
Date: 
Message-ID: <1121814243.743320.30730@g43g2000cwa.googlegroups.com>
Greetings fellow Common Lispers.

As some of you may know I am developing a new variant of Lisp. I am
currently figuring out iteration constructs. In particular, I am
experimenting with a method of iteration that iterates in parallel over
several lazy sequences, stopping when any of them terminates. I have
found this useful to replace several uses of the LOOP macro in my code.
However, I know the LOOP macro is too powerful for any one man to
comprehend. Hence, I request that you post the most impressive,
succinct, and elegant examples of the LOOP macro in action, so that I
can use them as goalposts for my language's iteration constructs.

Here's one of mine (I invented this one myself):

; Prints the first 16 rows of Pascal's triangle
; not tested, I'm writing it from memory right here!
(loop repeat 16
      for list = '(1) then (mapcar #'+ (cons 0 list) (append list
'(0)))
      do (format t "~{~6D~^,~}~%" list))

That's definitely one of the most beautiful pieces of code I've ever
written. I wrote it for a programming language comparison contest, and
blew every other language out of the water, except Mathematica, of
course. ;-)

Tron3k

From: Pascal Costanza
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <3k5i0nFsqejpU1@individual.net>
Tron3k wrote:
> Greetings fellow Common Lispers.
> 
> As some of you may know I am developing a new variant of Lisp. I am
> currently figuring out iteration constructs. In particular, I am
> experimenting with a method of iteration that iterates in parallel over
> several lazy sequences, stopping when any of them terminates. I have
> found this useful to replace several uses of the LOOP macro in my code.
> However, I know the LOOP macro is too powerful for any one man to
> comprehend. Hence, I request that you post the most impressive,
> succinct, and elegant examples of the LOOP macro in action, so that I
> can use them as goalposts for my language's iteration constructs.

These requests have been made in the past for some other projects. 
Googling in the archives of comp.lang.lisp should give you some ideas.


Pascal

-- 
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
From: Tron3k
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <1121834252.743063.114330@g49g2000cwa.googlegroups.com>
Pascal Costanza wrote:
> Tron3k wrote:
> > Greetings fellow Common Lispers.
> >
> > As some of you may know I am developing a new variant of Lisp. I am
> > currently figuring out iteration constructs. In particular, I am
> > experimenting with a method of iteration that iterates in parallel over
> > several lazy sequences, stopping when any of them terminates. I have
> > found this useful to replace several uses of the LOOP macro in my code.
> > However, I know the LOOP macro is too powerful for any one man to
> > comprehend. Hence, I request that you post the most impressive,
> > succinct, and elegant examples of the LOOP macro in action, so that I
> > can use them as goalposts for my language's iteration constructs.
>
> These requests have been made in the past for some other projects.
> Googling in the archives of comp.lang.lisp should give you some ideas.

Thanks. I did, in fact, google for cool Lisp snippets before posting
this and found some interesting ones such as the one that prints the
Mandelbrot set using ASCII characters. I just thought that it would be
fun to have a thread for everyone to share the cool snippets they have
tucked away ... I've done this on other forums and people usually enjoy
it.
From: Pascal Costanza
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <3k754nFstrmqU1@individual.net>
Tron3k wrote:
> Pascal Costanza wrote:
> 
>>Tron3k wrote:
>>
>>>Greetings fellow Common Lispers.
>>>
>>>As some of you may know I am developing a new variant of Lisp. I am
>>>currently figuring out iteration constructs. In particular, I am
>>>experimenting with a method of iteration that iterates in parallel over
>>>several lazy sequences, stopping when any of them terminates. I have
>>>found this useful to replace several uses of the LOOP macro in my code.
>>>However, I know the LOOP macro is too powerful for any one man to
>>>comprehend. Hence, I request that you post the most impressive,
>>>succinct, and elegant examples of the LOOP macro in action, so that I
>>>can use them as goalposts for my language's iteration constructs.
>>
>>These requests have been made in the past for some other projects.
>>Googling in the archives of comp.lang.lisp should give you some ideas. 
> 
> Thanks. I did, in fact, google for cool Lisp snippets before posting
> this and found some interesting ones such as the one that prints the
> Mandelbrot set using ASCII characters. I just thought that it would be
> fun to have a thread for everyone to share the cool snippets they have
> tucked away ... I've done this on other forums and people usually enjoy
> it.

I had your more specific request in mind, wrt examples using LOOP. There 
were a number of examples posted in conjunction with LinJ.


Pascal

-- 
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
From: Tron3k
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <1121870220.722367.248880@g43g2000cwa.googlegroups.com>
Pascal Costanza wrote:
> Tron3k wrote:
> > Pascal Costanza wrote:
> >
> >>Tron3k wrote:
> >>
> >>>Greetings fellow Common Lispers.
> >>>
> >>>As some of you may know I am developing a new variant of Lisp. I am
> >>>currently figuring out iteration constructs. In particular, I am
> >>>experimenting with a method of iteration that iterates in parallel over
> >>>several lazy sequences, stopping when any of them terminates. I have
> >>>found this useful to replace several uses of the LOOP macro in my code.
> >>>However, I know the LOOP macro is too powerful for any one man to
> >>>comprehend. Hence, I request that you post the most impressive,
> >>>succinct, and elegant examples of the LOOP macro in action, so that I
> >>>can use them as goalposts for my language's iteration constructs.
> >>
> >>These requests have been made in the past for some other projects.
> >>Googling in the archives of comp.lang.lisp should give you some ideas.
> >
> > Thanks. I did, in fact, google for cool Lisp snippets before posting
> > this and found some interesting ones such as the one that prints the
> > Mandelbrot set using ASCII characters. I just thought that it would be
> > fun to have a thread for everyone to share the cool snippets they have
> > tucked away ... I've done this on other forums and people usually enjoy
> > it.
>
> I had your more specific request in mind, wrt examples using LOOP. There
> were a number of examples posted in conjunction with LinJ.
>

Fantastic! I actually found it:

http://groups-beta.google.com/group/comp.lang.lisp/browse_thread/thread/5cd7b6634e692987?tvc=2&q=linj+loop&hl=en

This is like a gold mine! Thanks!

Tron3k
From: Matthias Buelow
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <86pstefhsy.fsf@drjekyll.mkbuelow.net>
"Tron3k" <······@gmail.com> writes:

>That's definitely one of the most beautiful pieces of code I've ever
>written.

Warning: slippery slope.

mkb.
From: Tron3k
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <1121834315.692879.251840@g49g2000cwa.googlegroups.com>
Matthias Buelow wrote:
> "Tron3k" <······@gmail.com> writes:
>
> >That's definitely one of the most beautiful pieces of code I've ever
> >written.
> 
> Warning: slippery slope.
> 
> mkb.

???
From: Timofei Shatrov
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <42de0d83.5226891@news.readfreenews.net>
On 19 Jul 2005 16:04:03 -0700, "Tron3k" <······@gmail.com> tried to
confuse everyone with this message:

>Greetings fellow Common Lispers.
>
>As some of you may know I am developing a new variant of Lisp. I am
>currently figuring out iteration constructs. In particular, I am
>experimenting with a method of iteration that iterates in parallel over
>several lazy sequences, stopping when any of them terminates. I have
>found this useful to replace several uses of the LOOP macro in my code.
>However, I know the LOOP macro is too powerful for any one man to
>comprehend. Hence, I request that you post the most impressive,
>succinct, and elegant examples of the LOOP macro in action, so that I
>can use them as goalposts for my language's iteration constructs.

Here is one neat loop I wrote. Not very efficient, though...

;Continous fractions: 47/350 -> (0 (1 3) (4 2 8 5 7 1))
(defun contdivstuff (a b &key (base 10))
  (multiple-value-bind (whole r) (floor (/ a b))
  (loop for tr = (* base r) then (* base (- tr (floor tr)))
	for tail = (member tr past)
	until tail
	collecting tr into past
	finally (return (list whole (mapcar #'floor (ldiff past tail)) 
			      (mapcar #'floor tail))))))

-- 
|a\o/r|,-------------.,---------- Timofei Shatrov aka Grue ------------.
| m"a ||FC AMKAR PERM|| mail: grue at mail.ru  http://grue3.tripod.com |
|  k  ||  PWNZ J00   || Kingdom of Loathing: Grue3 lvl 18 Seal Clubber |
`-----'`-------------'`-------------------------------------------[4*72]
From: Paolo Amoroso
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <87pste3p16.fsf@plato.moon.paoloamoroso.it>
"Tron3k" <······@gmail.com> writes:

> currently figuring out iteration constructs. In particular, I am
> experimenting with a method of iteration that iterates in parallel over
> several lazy sequences, stopping when any of them terminates. I have
> found this useful to replace several uses of the LOOP macro in my code.

I also have a way of replacing uses of LOOP: MACROEXPAND.


Paolo
-- 
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film
Recommended Common Lisp libraries/tools:
- ASDF/ASDF-INSTALL: system building/installation
- CL-PPCRE: regular expressions
- UFFI: Foreign Function Interface
From: Tron3k
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <1121868830.699343.269620@g43g2000cwa.googlegroups.com>
Paolo Amoroso wrote:
> "Tron3k" <······@gmail.com> writes:
>
> > currently figuring out iteration constructs. In particular, I am
> > experimenting with a method of iteration that iterates in parallel over
> > several lazy sequences, stopping when any of them terminates. I have
> > found this useful to replace several uses of the LOOP macro in my code.
>
> I also have a way of replacing uses of LOOP: MACROEXPAND.

Its expansion is hideous, but I don't think that's what you meant.

You're saying that it's stupid to hate a tool if it works. You're
fitting me into your pre-existing archetype of the mindless anti-LOOP
bigot. Well, there are reasons I'm not going to translate all the code
for LOOP into my new Lisp. First of all, it would be hard to get right.
Second of all, I'm trying to make this language simple to implement,
since as PG says, source code is often the best spec. So I'm trying to
find a good combination of simple but powerful constructs that are
equivalent in expressivity to LOOP.
From: Don Geddis
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <87hdept5dx.fsf@sidious.geddis.org>
"Tron3k" <······@gmail.com> wrote on 20 Jul 2005 07:1:
> Well, there are reasons I'm not going to translate all the code for LOOP
> into my new Lisp. First of all, it would be hard to get right.

True.  Yet many CL programmers find it valuable that CL implementors spend
this effort.  I wonder if the programming community for your new language
will be as forgiving of you not bothering to put forth the effort.

> Second of all, I'm trying to make this language simple to implement

More and more, it sure sounds like you would be happier in the Scheme
community.  They share much of your aesthetic sense.  For example: Lisp-1,
small language spec, simple to implement, etc.

You sure don't sound like someone trying to improve Common Lisp.  You sound
like a Scheme guy who is trying to convert the "enemy".

> since as PG says, source code is often the best spec.

Leaving aside whether Paul Graham is the Prophet of Lisp, such that his
every word must become our law ... how is this even related?  "Source code
being the best spec" means that a sufficiently powerful language would allow
you to express most of what is usually in documentation, directly in the
language itself.

How does that have anything to do with whether the language is easy to
implement or not?

        -- Don
_______________________________________________________________________________
Don Geddis                  http://don.geddis.org/               ···@geddis.org
Writing about music is like dancing about architecture.
From: Paolo Amoroso
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <87mzohtu7d.fsf@plato.moon.paoloamoroso.it>
"Tron3k" <······@gmail.com> writes:

> Paolo Amoroso wrote:
[...]
>> I also have a way of replacing uses of LOOP: MACROEXPAND.
>
> Its expansion is hideous, but I don't think that's what you meant.
>
> You're saying that it's stupid to hate a tool if it works. You're
> fitting me into your pre-existing archetype of the mindless anti-LOOP
> bigot. Well, there are reasons I'm not going to translate all the code

No.


Paolo
-- 
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film
Recommended Common Lisp libraries/tools:
- ASDF/ASDF-INSTALL: system building/installation
- CL-PPCRE: regular expressions
- UFFI: Foreign Function Interface
From: Tron3k
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <1121910833.909516.118420@g43g2000cwa.googlegroups.com>
Paolo Amoroso wrote:
> "Tron3k" <······@gmail.com> writes:
>
> > Paolo Amoroso wrote:
> [...]
> >> I also have a way of replacing uses of LOOP: MACROEXPAND.
> >
> > Its expansion is hideous, but I don't think that's what you meant.
> >
> > You're saying that it's stupid to hate a tool if it works. You're
> > fitting me into your pre-existing archetype of the mindless anti-LOOP
> > bigot. Well, there are reasons I'm not going to translate all the code
>
> No.

Oh, so you were just wasting everyone's time with a thoroughly useless
comment. Ok then.
From: Paolo Amoroso
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <87oe8wtumi.fsf@plato.moon.paoloamoroso.it>
"Tron3k" <······@gmail.com> writes:

>> > Paolo Amoroso wrote:
>> [...]
>> >> I also have a way of replacing uses of LOOP: MACROEXPAND.
[...]
> Oh, so you were just wasting everyone's time with a thoroughly useless
> comment. Ok then.

It was a joke.  As for wasting everyone's time, everyone can decide
for himself/herself.


Paolo
-- 
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film
Recommended Common Lisp libraries/tools:
- ASDF/ASDF-INSTALL: system building/installation
- CL-PPCRE: regular expressions
- UFFI: Foreign Function Interface
From: Peter Seibel
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <m2r7dtza9w.fsf@gigamonkeys.com>
"Tron3k" <······@gmail.com> writes:

> Here's one of mine (I invented this one myself):
>
> ; Prints the first 16 rows of Pascal's triangle
> ; not tested, I'm writing it from memory right here!
> (loop repeat 16
>       for list = '(1) then (mapcar #'+ (cons 0 list) (append list
> '(0)))
>       do (format t "~{~6D~^,~}~%" list))
>
> That's definitely one of the most beautiful pieces of code I've ever
> written. I wrote it for a programming language comparison contest,
> and blew every other language out of the water, except Mathematica,
> of course. ;-)

Hmmm. I'm not sure any code that repeatedly APPENDs to the end of a
growing list can be all that elegant. If you're into this sort of
thin, both the versions below, while slightly longer in terms of
number of characters than yours, are, I'd argue, algorithmically more
elegant:

  (loop repeat 16 for list = '(1)
     then (maplist #'(lambda (cons) (+ (car cons) (or (cadr cons) 0))) (cons 0 list))
     do (format t "~{~6D~^,~}~%" list))

  (loop repeat 16 for list = '(1)
     then (maplist #'(lambda (cons) (apply #'+ (ldiff cons (cddr cons)))) (cons 0 list))
     do (format t "~{~6D~^,~}~%" list))

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Peter Lewerin
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <b72f3640.0507201426.220e936e@posting.google.com>
Peter Seibel <·····@gigamonkeys.com> wrote:

> Hmmm. I'm not sure any code that repeatedly APPENDs to the end of a
> growing list can be all that elegant. If you're into this sort of
> thin, both the versions below, while slightly longer in terms of
> number of characters than yours, are, I'd argue, algorithmically more
> elegant:
> 
>   (loop repeat 16 for list = '(1)
>      then (maplist #'(lambda (cons) (+ (car cons) (or (cadr cons) 0))) (cons 0 list))
>      do (format t "~{~6D~^,~}~%" list))
> 
>   (loop repeat 16 for list = '(1)
>      then (maplist #'(lambda (cons) (apply #'+ (ldiff cons (cddr cons)))) (cons 0 list))
>      do (format t "~{~6D~^,~}~%" list))

Maybe even

    (loop repeat 16
        for list = '(1)
        then (cons 1 (loop for (a b) on list
                         collecting (+ a (or b 0))))
        do (format t "~&~{~6D~^,~}~%" list))
From: Tron3k
Subject: Re: Most impressive examples of the LOOP macro
Date: 
Message-ID: <1121910601.867696.219440@g44g2000cwa.googlegroups.com>
Peter Seibel wrote:
> "Tron3k" <······@gmail.com> writes:
>
> > Here's one of mine (I invented this one myself):
> >
> > ; Prints the first 16 rows of Pascal's triangle
> > ; not tested, I'm writing it from memory right here!
> > (loop repeat 16
> >       for list = '(1) then (mapcar #'+ (cons 0 list) (append list
> > '(0)))
> >       do (format t "~{~6D~^,~}~%" list))
> >
> > That's definitely one of the most beautiful pieces of code I've ever
> > written. I wrote it for a programming language comparison contest,
> > and blew every other language out of the water, except Mathematica,
> > of course. ;-)
>
> Hmmm. I'm not sure any code that repeatedly APPENDs to the end of a
> growing list can be all that elegant. If you're into this sort of
> thin, both the versions below, while slightly longer in terms of
> number of characters than yours, are, I'd argue, algorithmically more
> elegant:
>
>   (loop repeat 16 for list = '(1)
>      then (maplist #'(lambda (cons) (+ (car cons) (or (cadr cons) 0))) (cons 0 list))
>      do (format t "~{~6D~^,~}~%" list))
>
>   (loop repeat 16 for list = '(1)
>      then (maplist #'(lambda (cons) (apply #'+ (ldiff cons (cddr cons)))) (cons 0 list))
>      do (format t "~{~6D~^,~}~%" list))

Yeah, I know. The contest was to create the shortest code though. :-)