From: Shin
Subject: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <380ccaad.2659587@news.iddeo.es>
What is the usual way of programming a `while' in Common Lisp?
Perhaps something like this?

(loop
  (when (all-done-test) 
        (return something))
  form1
  form2
  ...
  formn)

And a `do-while'? Perhaps the following?

(loop
  form1
  form2
  ...
  formn
  (when (all-done-test) 
        (return something)))

Also, I wonder if `loop' could be better than `do' when we have,
say, one or two variables involved, or is just a matter of style
or readibility to use one or the other?

Thanks,

-- Shin

From: David J. Cooper
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <380CC71D.BC5DA63E@genworks.com>
Shin wrote:
> 
> What is the usual way of programming a `while' in Common Lisp?
> Perhaps something like this?
> 
> (loop
>   (when (all-done-test)
>         (return something))
>   form1
>   form2
>   ...
>   formn)
> 

Check pg. 164 of Graham's ANSI Common Lisp for a ``while'' macro
using DO. Note that Graham does not recommend the use of LOOP
(pg. 244).


-- 
David J. Cooper Jr, Chief Engineer	Genworks International
·······@genworks.com			5777 West Maple, Suite 130
(248) 932-2512 (Genworks HQ/voicemail)	West Bloomfield, MI 48322-2268
(248) 407-0633 (pager)			http://www.genworks.com
From: R. Matthew Emerson
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <87hfjnkrnz.fsf@nightfly.apk.net>
"David J. Cooper" <·······@genworks.com> writes:

> Check pg. 164 of Graham's ANSI Common Lisp for a ``while'' macro
> using DO. Note that Graham does not recommend the use of LOOP
> (pg. 244).

Graham was talking about the fancy extended LOOP macro, though.
Plain vanilla LOOP is presumably OK, even for those who find
the extended LOOP macro distasteful.

-matt
From: Chris Riesbeck
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <riesbeck-2110990929010001@riesbeck.ils.nwu.edu>
In article <·················@genworks.com>, "David J. Cooper"
<·······@genworks.com> wrote:

>Check pg. 164 of Graham's ANSI Common Lisp for a ``while'' macro
>using DO. Note that Graham does not recommend the use of LOOP
>(pg. 244).

Graham, while very expert about Common Lisp, is clearly fond of 
Scheme style, including a dislike for LOOP, a fondness for 
IF + PROGN instead of COND, and a preference for recursive 
solutions.
From: Christopher R. Barry
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <87u2njtcdj.fsf@2xtreme.net>
········@ils.nwu.edu (Chris Riesbeck) writes:

> In article <·················@genworks.com>, "David J. Cooper"
> <·······@genworks.com> wrote:
> 
> >Check pg. 164 of Graham's ANSI Common Lisp for a ``while'' macro
> >using DO. Note that Graham does not recommend the use of LOOP
> >(pg. 244).
> 
> Graham, while very expert about Common Lisp, is clearly fond of 
> Scheme style, including a dislike for LOOP, a fondness for 
> IF + PROGN instead of COND, and a preference for recursive 
> solutions.

Not to mention variable names like LST, L, OBJ, etc. when Common Lisp
allows you to use real variable names--unlike Scheme.

Christopher
From: Johan Kullstam
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <m2zoxbm66v.fsf@sophia.axel.nom>
······@2xtreme.net (Christopher R. Barry) writes:

> ········@ils.nwu.edu (Chris Riesbeck) writes:
> 
> > In article <·················@genworks.com>, "David J. Cooper"
> > <·······@genworks.com> wrote:
> > 
> > >Check pg. 164 of Graham's ANSI Common Lisp for a ``while'' macro
> > >using DO. Note that Graham does not recommend the use of LOOP
> > >(pg. 244).

don't let graham decide this issue for you.  learn to use LOOP and
*then* make up your mind if you like it or not.  you may agree with
graham opinion, but then again, you might not.

> > Graham, while very expert about Common Lisp, is clearly fond of 
> > Scheme style, including a dislike for LOOP, a fondness for 
> > IF + PROGN instead of COND, and a preference for recursive 
> > solutions.
> 
> Not to mention variable names like LST, L, OBJ, etc. when Common Lisp
> allows you to use real variable names--unlike Scheme.

imho this is the *least* of graham's flaws.  i know common-lisp has
several namespaces which allow using LIST as a variable without
shadowing/clobbering LIST as a function.  however, even though the
compiler has no trouble, i am not always as smart.  overloading the
names will only serve to confuse the neophyte.  just because you
*can* do it doesn't mean it's a good idea.

-- 
J o h a n  K u l l s t a m
[········@ne.mediaone.net]
Don't Fear the Penguin!
From: Christopher Browne
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <xT8Q3.16469$y45.429323@news4.giganews.com>
On 22 Oct 1999 17:33:28 -0400, Johan Kullstam
<········@ne.mediaone.net> wrote: 
>······@2xtreme.net (Christopher R. Barry) writes:
>> ········@ils.nwu.edu (Chris Riesbeck) writes:
>> 
>> > In article <·················@genworks.com>, "David J. Cooper"
>> > <·······@genworks.com> wrote:
>> > 
>> > >Check pg. 164 of Graham's ANSI Common Lisp for a ``while'' macro
>> > >using DO. Note that Graham does not recommend the use of LOOP
>> > >(pg. 244).
>
>don't let graham decide this issue for you.  learn to use LOOP and
>*then* make up your mind if you like it or not.  you may agree with
>graham opinion, but then again, you might not.

It's a tough call.

a) LOOP has a definition complex enough as to be ambiguous.
b) LOOP is arguably "unLisp-like" in providing a syntax that is rather
   like "traditional looping structures" in other languages.

On the other hand...

c) If LOOP simplifies *some* cases, it can be worth using even if it
   is not the ultimate "grand unified control structure scheme."
d) The purpose in life should not be to be "Lisp-like for the sake of
   being Lisp-like;" if other languages provide control structures
   that (emphasis "have merit") then there is merit to using them,
   Lisp-like or not.

Graham points out a) and b); he doesn't spend enough space on LOOP to
be able to express the parallel issues of c) and d).

>> > Graham, while very expert about Common Lisp, is clearly fond of 
>> > Scheme style, including a dislike for LOOP, a fondness for 
>> > IF + PROGN instead of COND, and a preference for recursive 
>> > solutions.
>> 
>> Not to mention variable names like LST, L, OBJ, etc. when Common Lisp
>> allows you to use real variable names--unlike Scheme.
>
>imho this is the *least* of graham's flaws.  i know common-lisp has
>several namespaces which allow using LIST as a variable without
>shadowing/clobbering LIST as a function.  however, even though the
>compiler has no trouble, i am not always as smart.  overloading the
>names will only serve to confuse the neophyte.  just because you
>*can* do it doesn't mean it's a good idea.

With M-/, long object names become vastly less painful than they are
without that.

On the other hand, long object names result in code being wider and
more likely not to fit nicely on the screen.

Further, the place where long names have most merit is when they are
used in global namespaces, where there is the greatest likelihood of
collision were names to stay short.  Having a global name "OBJ" or
"LST" would be quite silly when it is neither descriptive nor unique.

Having a local variable name "LST" inside a function is, on the other
hand, not particularly awful.

I certainly agree that overloading names serves to supply confusion;
just because I can write:

(DEFUN DO-SOMETHING-SILLY (LIST)
       (LIST (CDR LIST) 'SHORTENED-BY-ONE))

thereby using LIST for several things, does not mean that this is
actually a wise idea.

(DEFUN DO-SOMETHING-SILLY (LST)
       (LIST (CDR LST) 'SHORTENED-BY-ONE))
is probably slightly easier to grok.
-- 
The Three Laws of Thermodynamics: 
   1) You can't win.
   2) You can't break even.
   3) You can't even get out of the game.
········@ntlug.org- <http://www.ntlug.org/~cbbrowne/langlisp.html>
From: Rob Warnock
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <7ur8te$6vo2e@fido.engr.sgi.com>
Christopher Browne <········@hex.net> wrote:
+---------------
| just because I can write:
| 
| (DEFUN DO-SOMETHING-SILLY (LIST)
|        (LIST (CDR LIST) 'SHORTENED-BY-ONE))
| 
| thereby using LIST for several things, does not mean that this is
| actually a wise idea.
| 
| (DEFUN DO-SOMETHING-SILLY (LST)
|        (LIST (CDR LST) 'SHORTENED-BY-ONE))
| is probably slightly easier to grok.
+---------------

Even better, to my taste, is something like this:

  (DEFUN DO-SOMETHING-SILLY (SILLIES)
    (LIST (CDR SILLIES) 'SHORTENED-BY-ONE))

I also tend to avoid names like "NUMBER", "CHAR", "VECTOR", etc.


-Rob

-----
Rob Warnock, 8L-846		····@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA
From: Marco Antoniotti
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <lwk8oegsct.fsf@copernico.parades.rm.cnr.it>
········@news.hex.net (Christopher Browne) writes:

> It's a tough call.
> 
> a) LOOP has a definition complex enough as to be ambiguous.
> b) LOOP is arguably "unLisp-like" in providing a syntax that is rather
>    like "traditional looping structures" in other languages.

Any WHILE (or FOR) macro usually requires a SETQ/F.  This is the most
un-lipsy thing you can think of. :)

Let's flame on! :)

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Fred Gilham
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <u7iu3x3nva.fsf@snapdragon.csl.sri.com>
Christopher Browne writes:

>d) The purpose in life should not be to be "Lisp-like for the sake of
>   being Lisp-like;" if other languages provide control structures
>   that (emphasis "have merit") then there is merit to using them,
>   Lisp-like or not.


On pg 8 of the paper ``Don't Loop, Iterate'' by Jonathan Amsterdam,
the author points out why being `Lisp-like' is important:

     ...Third, the absence of parens makes it hard to parse, both by
     machine and, more importantly, by human....Fifth, there is no
     good interface with the rest of Lisp, so loop clauses cannot
     appear inside Lisp forms and macros cannot expand to pieces of
     loop....

I've recently become more aware of the fact that Lisp's `program as
data' paradigm really sets it apart from the rest of the crowd; loop
detracts from this.  It would not be so bad if doing so were necessary
to gain the functionality loop provides; the fact that alternatives
exist that are more Lisp-like makes loop something of a wart.

-- 
Fred Gilham                                 ······@csl.sri.com
[My tutors] got bored sooner than I, and laid down a general rule
that all statements about languages had to be in a higher level
language.  I thereupon asked in what level of language that rule was
formulated.  I got a very bad report.    -- J. R. Lucas
From: Erik Naggum
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <3149697116657478@naggum.no>
* Fred Gilham
| I've recently become more aware of the fact that Lisp's `program as
| data' paradigm really sets it apart from the rest of the crowd; loop
| detracts from this.

  I disagree.  LOOP is an excellent example of "program as data", both in
  the way it is implemented (symbols like WHILE are not in COMMON-LISP, but
  are STRING= with stuff the LOOP macro knows about).  moreover, LOOP is an
  excellent example of "not all data or programs can be alike", which I
  think is an even more important issue -- Lisp captures the diversity of
  real-life complexity.  finally, LOOP is an example of a very messy use of
  both of these high quality features in Common Lisp.

| It would not be so bad if doing so were necessary to gain the
| functionality loop provides; the fact that alternatives exist that are
| more Lisp-like makes loop something of a wart.

  there's something to be said about the beauty of youth and the immature,
  but as sll things mature, warts and wrinkles show up and make some people
  want to leave in disgust for yet another immature youth.  I don't think
  this is a valid way to think of beauty in either languages nor humans,
  despite the intense pressure from the extremely youth-fixated fashion
  industry whose views permeate our entire culture's view on maturity.

#:Erik
From: Christopher R. Barry
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <871zaltr4c.fsf@2xtreme.net>
Fred Gilham <······@snapdragon.csl.sri.com> writes:

> Christopher Browne writes:
> 
> >d) The purpose in life should not be to be "Lisp-like for the sake of
> >   being Lisp-like;" if other languages provide control structures
> >   that (emphasis "have merit") then there is merit to using them,
> >   Lisp-like or not.
> 
> 
> On pg 8 of the paper ``Don't Loop, Iterate'' by Jonathan Amsterdam,
> the author points out why being `Lisp-like' is important:
> 
>      ...Third, the absence of parens makes it hard to parse, both by
>      machine and, more importantly, by human....Fifth, there is no
>      good interface with the rest of Lisp, so loop clauses cannot
>      appear inside Lisp forms and macros cannot expand to pieces of
>      loop....

I don't see the utility of macros that expand to pieces of LOOP. Also,
with the Symbolics LOOP implementation IIRC you can use a LOOP "for
...." clause standalone like:

  (for x in ... do ....)

Also, I write a lot of macros that expand to LOOP forms like

  `(loop for ,<blah> ....
         while ,<blah>
         do ,@body)

> I've recently become more aware of the fact that Lisp's `program as
> data' paradigm really sets it apart from the rest of the crowd; loop
> detracts from this.

No. A LOOP form is still just lists and atoms. Macros are the only
time you need this "program as data" functionality, and LOOP works
quite well with these. It is one of these, after all.

> It would not be so bad if doing so were necessary
> to gain the functionality loop provides; the fact that alternatives
> exist that are more Lisp-like makes loop something of a wart.

The best thing is the best thing, Lisp-like or not. It just happens
that Lisp-like is usually the best thing. LOOP is Lisp-like, but in a
deeper, non-superficial way. I was never too impressed with SERIES,
and I think LOOP is better. I haven't investigated ITERATE too well
yet, but it might be promising....

Christopher
From: Eugene Zaikonnikov
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <940766196.432352@lxms.cit.org.by>
Christopher R. Barry <······@2xtreme.net> wrote in message
···················@2xtreme.net...
>
> No. A LOOP form is still just lists and atoms. Macros are the only
> time you need this "program as data" functionality, and LOOP works
> quite well with these. It is one of these, after all.
>
Actually, treating program as data is neccessary for some kinds of art, like
codewalkers and foo-to-lisp translators. Remember the recent discussion
about regexp implementation, where regexp compiler was proposed? There is
also many data driven AI programs that look elegant because they exploit
"data as program" concept.
OTOH, programmer usually knows when he'd go to treat program as data and may
simply avoid LOOP and such there.

--
  Eugene.
From: Robert Monfera
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <3813287C.F11FC42C@fisec.com>
"Christopher R. Barry" wrote:
...
> No. A LOOP form is still just lists and atoms. Macros are the only
> time you need this "program as data" functionality

No, they aren't - at least not for everybody.

With the SERIES package, you may use closures, curried functions etc. to
do something useful in your iteration.  It's more work and also ugly
when you need to do the same thing with loop.  Loop is quite monolithic,
whereas series is a package of more atomic functions and macros with
clear semantics, with which you can more easily build complex or
customizable iterations.

Also, there are other examples where programs are data, like MOP or
higher order functions.

There are many things you can accuse loop with: being more integrated
with the rest of CL than the alternatives is none of them.

I see the following advantages with loop:

- for frequent, simple iteration patterns it's less typing
- you may avoid having to type #'s and lambdas
- for simple cases, it looks straightforward for newcomers
- it has a bigger mindshare than, say, series - more patterns to learn
from
- it may be a good basis for implementing other iteration functions atop
of it
- it's in the standard :-)

Series wins when it comes to style (especially functional style) or more
complex requirements.  You may avoid extra typing by constructing your
scanning, mapping and collecting functions at higher and higher levels
as you normally do in Lisp.  Of course, macros also work.

I'm not against loop (I use loop if needed without tears).  I just
wanted to highlight that macros are NOT the only thing where programs
are data, and that loop being built out of lists and atoms is not always
enough, let alone 'best'.

Regards
Robert
From: Daniel Barlow
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <874sfihs66.fsf@tninkpad.telent.net>
········@news.hex.net (Christopher Browne) writes:
> Further, the place where long names have most merit is when they are
> used in global namespaces, where there is the greatest likelihood of
> collision were names to stay short.  Having a global name "OBJ" or
> "LST" would be quite silly when it is neither descriptive nor unique.

The situation where using variable names like LIST is worthwhile (at
least, when I find it worthwhile; ymmv) is in function lambda lists.
When I put point on a call to COPY-LIST and press C-c a, the returned
string "(LIST)" is clear and unambiguous.


-dan
From: Christopher Browne
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <Rb7R3.26482$7I4.554691@news5.giganews.com>
On 22 Oct 1999 17:33:28 -0400, Johan Kullstam
<········@ne.mediaone.net> wrote: 
>······@2xtreme.net (Christopher R. Barry) writes:
>> ········@ils.nwu.edu (Chris Riesbeck) writes:
>> 
>> > In article <·················@genworks.com>, "David J. Cooper"
>> > <·······@genworks.com> wrote:
>> > 
>> > >Check pg. 164 of Graham's ANSI Common Lisp for a ``while'' macro
>> > >using DO. Note that Graham does not recommend the use of LOOP
>> > >(pg. 244).
>
>don't let graham decide this issue for you.  learn to use LOOP and
>*then* make up your mind if you like it or not.  you may agree with
>graham opinion, but then again, you might not.

It's a tough call.

a) LOOP has a definition complex enough as to be ambiguous.
b) LOOP is arguably "unLisp-like" in providing a syntax that is rather
   like "traditional looping structures" in other languages.

On the other hand...

c) If LOOP simplifies *some* cases, it can be worth using even if it
   is not the ultimate "grand unified control structure scheme."
d) The purpose in life should not be to be "Lisp-like for the sake of
   being Lisp-like;" if other languages provide control structures
   that (emphasis "have merit") then there is merit to using them,
   Lisp-like or not.

Graham points out a) and b); he doesn't spend enough space on LOOP to
be able to express the parallel issues of c) and d).

>> > Graham, while very expert about Common Lisp, is clearly fond of 
>> > Scheme style, including a dislike for LOOP, a fondness for 
>> > IF + PROGN instead of COND, and a preference for recursive 
>> > solutions.
>> 
>> Not to mention variable names like LST, L, OBJ, etc. when Common Lisp
>> allows you to use real variable names--unlike Scheme.
>
>imho this is the *least* of graham's flaws.  i know common-lisp has
>several namespaces which allow using LIST as a variable without
>shadowing/clobbering LIST as a function.  however, even though the
>compiler has no trouble, i am not always as smart.  overloading the
>names will only serve to confuse the neophyte.  just because you
>*can* do it doesn't mean it's a good idea.

With M-/, long object names become vastly less painful than they are
without that.

On the other hand, long object names result in code being wider and
more likely not to fit nicely on the screen.

Further, the place where long names have most merit is when they are
used in global namespaces, where there is the greatest likelihood of
collision were names to stay short.  Having a global name "OBJ" or
"LST" would be quite silly when it is neither descriptive nor unique.

Having a local variable name "LST" inside a function is, on the other
hand, not particularly awful.

I certainly agree that overloading names serves to supply confusion;
just because I can write:

(DEFUN DO-SOMETHING-SILLY (LIST)
       (LIST (CDR LIST) 'SHORTENED-BY-ONE))

thereby using LIST for several things, does not mean that this is
actually a wise idea.

(DEFUN DO-SOMETHING-SILLY (LST)
       (LIST (CDR LST) 'SHORTENED-BY-ONE))
is probably slightly easier to grok.
-- 
The Three Laws of Thermodynamics: 
   1) You can't win.
   2) You can't break even.
   3) You can't even get out of the game.
········@ntlug.org- <http://www.ntlug.org/~cbbrowne/langlisp.html>
From: Christian Lynbech
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <ofd7ty4mm3.fsf@chl.tbit.dk>
>>>>> "Christopher" == Christopher Browne <········@news.hex.net> writes:

Christopher> just because I can write:

Christopher> (DEFUN DO-SOMETHING-SILLY (LIST)
Christopher>        (LIST (CDR LIST) 'SHORTENED-BY-ONE))

Christopher> thereby using LIST for several things, does not mean that this is
Christopher> actually a wise idea.

Not to mention what it will do to your code if there is no separation
between function and variable name spaces as in scheme :-)


---------------------------+--------------------------------------------------
Christian Lynbech          | Ericsson Telebit A/S                       
Fax:   +45 8628 8186       | Fabrikvej 11, DK-8260 Viby J
Phone: +45 8628 8177 + 28  | email: ···@tbit.dk --- URL: http://www.tbit.dk
---------------------------+--------------------------------------------------
Hit the philistines three times over the head with the Elisp reference manual.
                                        - ·······@hal.com (Michael A. Petonic)
From: Christopher Browne
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <yhsS3.67946$y45.744454@news4.giganews.com>
On 29 Oct 1999 10:06:28 +0200, Christian Lynbech <···@tbit.dk> wrote:
>>>>>> "Christopher" == Christopher Browne <········@news.hex.net> writes:
>Christopher> just because I can write:
>
>Christopher> (DEFUN DO-SOMETHING-SILLY (LIST)
>Christopher>        (LIST (CDR LIST) 'SHORTENED-BY-ONE))
>
>Christopher> thereby using LIST for several things, does not mean that this is
>Christopher> actually a wise idea.
>
>Not to mention what it will do to your code if there is no separation
>between function and variable name spaces as in scheme :-)

The reason why this choice of bindings is unwise is *not* about Lisp
namespace collisions.

It is all about *human brain* namespace collisions.

If the objects not the same thing, then the fact that they hold the
same names will cause some confusion to the human mind.  Possibly not
a *lot* of confusion.  But certainly *some.*

-- 
"The dinosaurs died because they didn't have a space program."
-- Arthur C Clarke
········@hex.net- <http://www.hex.net/~cbbrowne/langlisp.html>
From: Christopher R. Barry
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <871zadv7z3.fsf@2xtreme.net>
········@news.hex.net (Christopher Browne) writes:

> On 29 Oct 1999 10:06:28 +0200, Christian Lynbech <···@tbit.dk> wrote:
> >>>>>> "Christopher" == Christopher Browne <········@news.hex.net> writes:
> >Christopher> just because I can write:
> >
> >Christopher> (DEFUN DO-SOMETHING-SILLY (LIST)
> >Christopher>        (LIST (CDR LIST) 'SHORTENED-BY-ONE))
> >
> >Christopher> thereby using LIST for several things, does not mean that this is
> >Christopher> actually a wise idea.
> >
> >Not to mention what it will do to your code if there is no separation
> >between function and variable name spaces as in scheme :-)
> 
> The reason why this choice of bindings is unwise is *not* about Lisp
> namespace collisions.
> 
> It is all about *human brain* namespace collisions.
> 
> If the objects not the same thing, then the fact that they hold the
> same names will cause some confusion to the human mind.  Possibly not
> a *lot* of confusion.  But certainly *some.*

No. Once you've spent a lot of time with Lisp and have read all the
CLHS stuff on environments and mappings from symbols to objects you
learn to embrace all this stuff and are not confused.

  (defun foo () 4)

  (progv '(foo) '(1)
    (let ((foo 2))
      (flet ((foo () 3))
	(list (symbol-value 'foo)
	      foo
	      (foo)
	      (funcall (symbol-function 'foo))))))
   => (1 2 3 4)


Christopher
From: Johan Kullstam
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <m2puxweu3f.fsf@sophia.axel.nom>
······@2xtreme.net (Christopher R. Barry) writes:

> ········@news.hex.net (Christopher Browne) writes:
> 
> > On 29 Oct 1999 10:06:28 +0200, Christian Lynbech <···@tbit.dk> wrote:
> > >>>>>> "Christopher" == Christopher Browne <········@news.hex.net> writes:
> > >Christopher> just because I can write:
> > >
> > >Christopher> (DEFUN DO-SOMETHING-SILLY (LIST)
> > >Christopher>        (LIST (CDR LIST) 'SHORTENED-BY-ONE))
> > >
> > >Christopher> thereby using LIST for several things, does not mean that this is
> > >Christopher> actually a wise idea.
> > >
> > >Not to mention what it will do to your code if there is no separation
> > >between function and variable name spaces as in scheme :-)
> > 
> > The reason why this choice of bindings is unwise is *not* about Lisp
> > namespace collisions.
> > 
> > It is all about *human brain* namespace collisions.
> > 
> > If the objects not the same thing, then the fact that they hold the
> > same names will cause some confusion to the human mind.  Possibly not
> > a *lot* of confusion.  But certainly *some.*
> 
> No. Once you've spent a lot of time with Lisp and have read all the
> CLHS stuff on environments and mappings from symbols to objects you
> learn to embrace all this stuff and are not confused.

the starting point for this discussion was graham using variable names
like LST as opposed to LIST in his _ansi common lisp_ book.  this is a
beginner's book.  hence, the reader would *not* have spent a lot of
time with lisp.  nor would a beginner have read all the CLHS stuff on
environments and mappings &c.

>   (defun foo () 4)
> 
>   (progv '(foo) '(1)
>     (let ((foo 2))
>       (flet ((foo () 3))
> 	(list (symbol-value 'foo)
> 	      foo
> 	      (foo)
> 	      (funcall (symbol-function 'foo))))))
>    => (1 2 3 4)

you may be more clever than i, but i think you're too clever by half.
i certainly am confused.  i can work it out after some thought, but it
is painful.  it's analagous seeing a badly indented program and having
to count parentheses.  since you are free to choose decent names, the
confusion is completely gratuitous and therefore inexcusable.

-- 
J o h a n  K u l l s t a m
[········@ne.mediaone.net]
Don't Fear the Penguin!
From: Christopher R. Barry
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <87hfj8u1r4.fsf@2xtreme.net>
Johan Kullstam <········@ne.mediaone.net> writes:

> >   (defun foo () 4)
> > 
> >   (progv '(foo) '(1)
> >     (let ((foo 2))
> >       (flet ((foo () 3))
> > 	    (list (symbol-value 'foo)
> > 	          foo
> > 	          (foo)
> > 	          (funcall (symbol-function 'foo))))))
> >   => (1 2 3 4)
> 
> you may be more clever than i, but i think you're too clever by half.

??? I don't think I parse that.

> i certainly am confused.  i can work it out after some thought, but it
> is painful.  it's analagous seeing a badly indented program and having
> to count parentheses.  since you are free to choose decent names, the
> confusion is completely gratuitous and therefore inexcusable.

I think you completely missed the point of what I said.

Christopher
From: Tim Bradshaw
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <ey3g0ys7mnf.fsf@lostwithiel.tfeb.org>
* Christopher R Barry wrote:

> No. Once you've spent a lot of time with Lisp and have read all the
> CLHS stuff on environments and mappings from symbols to objects you
> learn to embrace all this stuff and are not confused.

>   (defun foo () 4)

>   (progv '(foo) '(1)
>     (let ((foo 2))
>       (flet ((foo () 3))
> 	(list (symbol-value 'foo)
> 	      foo
> 	      (foo)
> 	      (funcall (symbol-function 'foo))))))
>    => (1 2 3 4)

Well, I find this *very* confusing code, and I'm a reasonably
experienced Lisp person (and I've certainly spent more time with Lisp
than Christopher just by virtue of age...)

I find it confusing I think (a) because it's manifestly deliberately
obfuscated and (b) because it uses a nonsense word (and one for which
I deliberately have extremely undefined semantics) for several
different purposes.  I find it very different from the kind of
overloading that I often do which is along the 

	(defun foo (list)
	  ... (cons 'bar list) ...
          )

lines.

--tim
From: Tim Bradshaw
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <ey3so37rrwz.fsf@lostwithiel.tfeb.org>
* Shin  wrote:
> What is the usual way of programming a `while' in Common Lisp?
> Perhaps something like this?

> (loop
>   (when (all-done-test) 
>         (return something))
>   form1
>   form2
>   ...
>   formn)

I'd write

(loop while ...
      do ...
      finally (return ...))


> And a `do-while'? Perhaps the following?

and

(loop do ...
      while ...
      finally (return ...))

But lots of people would have a bad reaction to that...

--tim
From: Will Fitzgerald
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <SUiP3.1266$8D.8277@newsfeed.slurp.net>
I've tried hard to overcome my reluctance to use DO. It's not so hard to
use, really, and useful indentation helps a lot. Part of the problem is that
the formal way of describing DO in, say, CLtL2 is not as intuitive as lots
of examples.

I don't mind LOOP--overcoming my reluctance to use DO was largely driven
from writing Scheme code. There is a definite switch in programming
philosophy when using LOOP vs. DO or recursion, though, which is a cognitive
block. Also, some Lisp implementations, (like MCL) only load LOOP on demand.
If there are just a few LOOP calls, it's annoying to watch MCL pause to load
LOOP.

Shin wrote in message <················@news.iddeo.es>...
>What is the usual way of programming a `while' in Common Lisp?
>Perhaps something like this?
>
>(loop
>  (when (all-done-test)
>        (return something))
>  form1
>  form2
>  ...
>  formn)
>
>And a `do-while'? Perhaps the following?
>
>(loop
>  form1
>  form2
>  ...
>  formn
>  (when (all-done-test)
>        (return something)))
>
>Also, I wonder if `loop' could be better than `do' when we have,
>say, one or two variables involved, or is just a matter of style
>or readibility to use one or the other?
>
>Thanks,
>
>-- Shin
From: Tim Bradshaw
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <ey3so35iwen.fsf@lostwithiel.tfeb.org>
* Will Fitzgerald wrote:
> Also, some Lisp implementations, (like MCL) only load LOOP on demand.
> If there are just a few LOOP calls, it's annoying to watch MCL pause to load
> LOOP.

However this will almost certainly only happen at compile time, so
it's not really an issue.

--tim
From: Steve Gonedes
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <m2bt9ub71q.fsf@KludgeUnix.localdomain>
···@retemail.es (Shin) writes:

< 
< What is the usual way of programming a `while' in Common Lisp?
< Perhaps something like this?
< 
< (loop
<   (when (all-done-test) 
<         (return something))
<   form1
<   form2
<   ...
<   formn)

You could use extended loop as well.

(loop while <condition> do <statements>)

(let ((idx 0))
  (loop while (< idx 10)
        do (incf idx)
           (print idx))) 
 
< And a `do-while'? Perhaps the following?
< 
< (loop
<   form1
<   form2
<   ...
<   formn
<   (when (all-done-test) 
<         (return something)))

(let ((x 10))
  (loop do (decf x)
           (print x)
        while (plusp x)))
 
< Also, I wonder if `loop' could be better than `do' when we have,
< say, one or two variables involved, or is just a matter of style
< or readibility to use one or the other?

Probably a style issue, but `do' works well with multiple variables.
 
< Thanks,
< 
< -- Shin
From: Coby
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <7ungnb$a71$1@nnrp1.deja.com>
In article <················@news.iddeo.es>,
  ···@retemail.es (Shin) wrote:
> What is the usual way of programming a `while' in Common Lisp?
> Perhaps something like this?
>
> (loop
>   (when (all-done-test)
>         (return something))
>   form1
>   form2
>   ...
>   formn)
>


I wrote this macro a 'while' back:)

>(defmacro while
       (condition &body body)
      `(loop (if (not ,condition)
                (return)
                (progn
                 ,@body)))))
WHILE
>(setf x 0)
0
>(while (< x 3)
       (incf x)
       (print x))

1
2
3

Seems straight forward...
Happy to learn of any subtleties i may have overlooked.

coby


Sent via Deja.com http://www.deja.com/
Before you buy.
From: Steve Gonedes
Subject: Re: `while' in Lisp? + loop vs do?
Date: 
Message-ID: <m2g0z3fo2u.fsf@KludgeUnix.localdomain>
Coby <····@my-deja.com> writes:

< 
< In article <················@news.iddeo.es>,
<   ···@retemail.es (Shin) wrote:
< > What is the usual way of programming a `while' in Common Lisp?
< > Perhaps something like this?
< >
< > (loop
< >   (when (all-done-test)
< >         (return something))
< >   form1
< >   form2
< >   ...
< >   formn)
< >
< 
< 
< I wrote this macro a 'while' back:)
< 
< >(defmacro while
<        (condition &body body)
<       `(loop (if (not ,condition)
<                 (return)
<                 (progn
<                  ,@body)))))

[...]

< Seems straight forward...
< Happy to learn of any subtleties i may have overlooked.

If you replaced the progn with a `locally' your macro could allow
declarations such as space, and such.


< 
< coby
< 
< 
< Sent via Deja.com http://www.deja.com/
< Before you buy.