From: David Bakhash
Subject: advice...
Date: 
Message-ID: <cxjvhrbz2x4.fsf@hawk.bu.edu>
hey,

I just wanted to know...

I use `loop' for (basically) all my iterations.  I like it a lot, and
so I never really use dotimes and stuff like that.  Is it poor choice
to use loop when another function/macro is more "appropriate"?  Note
I'm using ACL, so I'm not sure if this question depends strongly on
the particular implementation I'm using.  Some might have really
efficient loop implementations, better than others.  Anyway, I find
loop very easy to read/write, and I find that extending an iteration
to do more stuff is easier w/ loop than with dotimes, etc.

dave

From: Mike McDonald
Subject: Re: advice...
Date: 
Message-ID: <yy361.6339$326.4003241@news.teleport.com>
In article <···············@hawk.bu.edu>,
	David Bakhash <·····@bu.edu> writes:
> hey,
> 
> I just wanted to know...
> 
> I use `loop' for (basically) all my iterations.  I like it a lot, and
> so I never really use dotimes and stuff like that.  Is it poor choice
> to use loop when another function/macro is more "appropriate"?  Note
> I'm using ACL, so I'm not sure if this question depends strongly on
> the particular implementation I'm using.  Some might have really
> efficient loop implementations, better than others.  Anyway, I find
> loop very easy to read/write, and I find that extending an iteration
> to do more stuff is easier w/ loop than with dotimes, etc.
> 
> dave

  I almost never use dotimes, do, dolist, map, ... anymore. I prefer loop to
these. I used to use the other forms back before loop became widely available.
But now, I find the one form makes my code simpler and more consistant.

  Mike McDonald
  ·······@mikemac.com
From: Marco Antoniotti
Subject: Re: advice...
Date: 
Message-ID: <lwbtt21u4h.fsf@galvani.parades.rm.cnr.it>
·······@mikemac.com (Mike McDonald) writes:

>   I almost never use dotimes, do, dolist, map, ... anymore. I prefer loop to
> these. I used to use the other forms back before loop became widely available.
> But now, I find the one form makes my code simpler and more consistant.
> 

I use DOTIMES and DOLIST whenever the iteration is obviously
exressable with these "simple" forms.  I find LOOP to be verbose in
these cases (and on top of that, none of the Emacs CL indenting
facilities works "right" on LOOP).

I use LOOP whenever I need a DO or a DO*.

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - (0)6 - 68 80 79 23, fax. +39 - (0)6 - 68 80 79 26
http://www.parades.rm.cnr.it
From: William Paul Vrotney
Subject: Re: advice...
Date: 
Message-ID: <vrotneyEsxGF8.II0@netcom.com>
In article <··············@galvani.parades.rm.cnr.it> Marco Antoniotti <·······@galvani.parades.rm.cnr.it> writes:

> 
> ·······@mikemac.com (Mike McDonald) writes:
> 
> >   I almost never use dotimes, do, dolist, map, ... anymore. I prefer loop to
> > these. I used to use the other forms back before loop became widely available.
> > But now, I find the one form makes my code simpler and more consistant.
> > 
> 
> I use DOTIMES and DOLIST whenever the iteration is obviously
> exressable with these "simple" forms.  I find LOOP to be verbose in
> these cases (and on top of that, none of the Emacs CL indenting
> facilities works "right" on LOOP).
> 
> I use LOOP whenever I need a DO or a DO*.
> 

The idea of DO is actually a decent iteration construct that is consistent
with the rest of Lisp.  I think of it as an "iterative LET".  It puts all of
the looping variable schema up front rather than distributing it though less
structured code.

The idea that extended LOOP is a single simple iteration construct compared
to others does not have any merit to me.  It seems that preferring extended
LOOP as simple and consistent is similar to preferring to just use PROGs
with GOs, the devil is in the details.

Finally, extended LOOP has this amazing property that it attracts
programmers who have a strong desire to create complex extended LOOP
constructs with the claim that there is no decent way to do the same without
it .... just joking! :-)


-- 

William P. Vrotney - ·······@netcom.com
From: Mike McDonald
Subject: Re: advice...
Date: 
Message-ID: <ZEG61.8319$326.5182305@news.teleport.com>
In article <·················@netcom.com>,
	·······@netcom.com (William Paul Vrotney) writes:
> 
> In article <··············@galvani.parades.rm.cnr.it> Marco Antoniotti <·······@galvani.parades.rm.cnr.it> writes:
> 
>> 
>> ·······@mikemac.com (Mike McDonald) writes:
>> 
>> >   I almost never use dotimes, do, dolist, map, ... anymore. I prefer loop to
>> > these.

>> 
>> I use DOTIMES and DOLIST whenever the iteration is obviously
>> exressable with these "simple" forms.  I find LOOP to be verbose in
>> these cases (and on top of that, none of the Emacs CL indenting
>> facilities works "right" on LOOP).
>> 
>> 

> The idea of DO is actually a decent iteration construct that is consistent
> with the rest of Lisp.  I think of it as an "iterative LET".  It puts all of
> the looping variable schema up front rather than distributing it though less
> structured code.

  I always think of it as a big prog.

> The idea that extended LOOP is a single simple iteration construct compared
> to others does not have any merit to me.  It seems that preferring extended
> LOOP as simple and consistent is similar to preferring to just use PROGs
> with GOs, the devil is in the details.

  Loop can be a simple iteration construct or an amazingly complex one. The
difference is in the skill and good taste of the programmer. But that applies
to all of programming.

> Finally, extended LOOP has this amazing property that it attracts
> programmers who have a strong desire to create complex extended LOOP
> constructs with the claim that there is no decent way to do the same without
> it .... just joking! :-)

  I've seen some pretty bazarre and complex do's in my day too. Anything can
be abused. I personally try not to do loops inside loops. But for simple "loop
over something and collect these things", I find it very clear. Much more so
than all of the map variations for instance.

  As for the editors not being able to indent it correctly, I agree that's an
annoyance. Zemacs used to get it right, too bad none of the "modern" emacs's
can.

  Mike McDonald
  ·······@mikemac.com
From: Kelly Murray
Subject: Re: advice...
Date: 
Message-ID: <nmn2cktysu.fsf@charlotte.i-have-a-misconfigured-system-so-shoot-me>
I don't have any problem with emacs indenting LOOP.
This is how emacs indents LOOP (and SilkScript IF)
(This code snippet was the first piece of code I saw
when I selected my editor -- it loads in timecard job codes
into Charlotte's timecard application)

How about this: LOOP-haters feel free to recode it
using something other than LOOP and post it,
and let the readers decide which is simpler and clearer
to understand.


-Kelly Murray ···@franz.com

(loop for name = (read stream nil nil)
      for code = (read stream nil nil)
      for active-p = (read stream nil nil)
      for job1 = (and code (job-from-code code))
      for job2 = (and name (job-from-name name))
      while name
    do
    (if (and job1 job2 (eq job1 job2))
      then
       (text :break "Job " name " exists with code " code ".")
     elseif (or job1 job2)
      then
       (text :break :bold "Job with name " name " or code " code
             " already exists and is not the same."
             :break " You must delete one or both manually.")
      else
       (text :break :italic "Creating Job " (:bold name) " with code "
             (:bold code) ".")
       (make-instance 'job :code code :name name
                      :active-p active-p
                      :created-by manager)
       ))
From: Mike McDonald
Subject: Re: advice...
Date: 
Message-ID: <akJ61.8560$326.5273950@news.teleport.com>
In article <··············@charlotte.i-have-a-misconfigured-system-so-shoot-me>,
	Kelly Murray <···@franz.com> writes:
> 

> How about this: LOOP-haters feel free to recode it
> using something other than LOOP and post it,
> and let the readers decide which is simpler and clearer
> to understand.
> 
> 
> -Kelly Murray ···@franz.com
> 
> (loop for name = (read stream nil nil)
>       for code = (read stream nil nil)
>       for active-p = (read stream nil nil)
>       for job1 = (and code (job-from-code code))
>       for job2 = (and name (job-from-name name))
>       while name
>     do
>     (if (and job1 job2 (eq job1 job2))
>       then
>        (text :break "Job " name " exists with code " code ".")
>      elseif (or job1 job2)
>       then
>        (text :break :bold "Job with name " name " or code " code
>              " already exists and is not the same."
>             :break " You must delete one or both manually.")
>       else
>        (text :break :italic "Creating Job " (:bold name) " with code "
>              (:bold code) ".")
>        (make-instance 'job :code code :name name
>                      :active-p active-p
>                      :created-by manager)
>        ))

  then, else, elseif? Yikes! 

  Personally, I'd write it as:

(loop for name = (read stream nil nil)
      for code = (read stream nil nil)
      for active-p = (read stream nil nil)
      for job1 = (and code (job-from-code code))
      for job2 = (and name (job-from-name name))
      while name
      do (cond
           ((and job1 job2 (eq job1 job2))
             (text :break "Job " name " exists with code " code "."))
           ((or job1 job2)
             (text :break 
                   :bold "Job with name " name " or code " code
                   " already exists and is not the same."
                   :break 
                   " You must delete one or both manually."))
           (t
             (text :break 
                   :italic "Creating Job " (:bold name) " with code "
                   (:bold code) ".")
             (make-instance 'job 
                            :code code 
                            :name name
                            :active-p active-p
                            :created-by manager))
           ))

  Where these )) go is open, depending on context. (I hope I got this write. 
My newsreader doesn't indent lisp too well!) Unfortunately, some unnamed lisp
company's xemacs indenter giver this:

(loop for name = (read stream nil nil)
    for code = (read stream nil nil)
    for active-p = (read stream nil nil)
    for job1 = (and code (job-from-code code))
    for job2 = (and name (job-from-name name))
    while name
    do (cond
	((and job1 job2 (eq job1 job2))
	 (text :break "Job " name " exists with code " code "."))
	((or job1 job2)
	 (text :break 
	       :bold "Job with name " name " or code " code
	       " already exists and is not the same."
	       :break 
	       " You must delete one or both manually."))
	(t
	 (text :break 
	       :italic "Creating Job " (:bold name) " with code "
	       (:bold code) ".")
	 (make-instance 'job 
	   :code code 
	   :name name
	   :active-p active-p
	   :created-by manager))
	))

  Which I don't care for. I guess someday I'll have to learn how to customize
it. 

  Mike McDonald
  ·······@mikemac.com
From: Scott L. Burson
Subject: Re: advice...
Date: 
Message-ID: <355C11A9.446B9B3D@zeta-sqoft.com>
Kelly Murray wrote:
> How about this: LOOP-haters feel free to recode it
> using something other than LOOP and post it,
> and let the readers decide which is simpler and clearer
> to understand.

Okay, I certainly qualify as a LOOP-hater.  Here's your example with DO
(body elided since it's not really relevant -- like Mike, though, I
would prefer COND):

(do () (nil)
  (let* ((name stream nil nil)
	 (code (read stream nil nil))
	 (active-p (read stream nil nil))
	 (job1 (and code (job-from-code code)))
	 (job2 (and name (job-from-name name))))
    (when (null name) (return))
    ... body ...)))

Here's a macro that would clean this example up further:

(defmacro repeat (&body body)
  `(macrolet ((while (pred)
		`(unless ,pred (return)))
	      (until (pred)                  ; included for completeness
		`(when ,pred (return))))
       (do () (nil)
	 . ,body)))

With that, one could write your example this way:

(repeat
  (let* ((name stream nil nil)
	 (code (read stream nil nil))
	 (active-p (read stream nil nil))
	 (job1 (and code (job-from-code code)))
	 (job2 (and name (job-from-name name))))
    (while name)
    ... body ...)))

This cleans up the useless subforms in the DO version and clarifies the
termination condition slightly.

I think that for simplicity and clarity it's pretty much a toss-up
between the LOOP and REPEAT versions.  It comes down to a matter of
taste.

-- Scott

				  * * * * *

To use the email address, remove all occurrences of the letter "q".
From: Scott L. Burson
Subject: Re: advice...
Date: 
Message-ID: <35647F7A.398A68D@zeta-sqoft.com>
Scott L. Burson wrote:
> 
> Okay, I certainly qualify as a LOOP-hater.

No response?  Nobody wants to argue about LOOP?  Sigh :-)

-- Scott

				  * * * * *

To use the email address, remove all occurrences of the letter "q".
From: Barry Margolin
Subject: Re: advice...
Date: 
Message-ID: <fCj91.10$hF2.3580@cam-news-reader1.bbnplanet.com>
In article <················@zeta-sqoft.com>,
Scott L. Burson <·····@zeta-sqoft.com> wrote:
>Scott L. Burson wrote:
>> 
>> Okay, I certainly qualify as a LOOP-hater.
>
>No response?  Nobody wants to argue about LOOP?  Sigh :-)

I thought this group was for arguing about Y2K....

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
From: Martin Rodgers
Subject: Re: advice...
Date: 
Message-ID: <MPG.fd1318db4f717d9989a5c@news.demon.co.uk>
In article <·················@cam-news-reader1.bbnplanet.com>, 
······@bbnplanet.com says...
> I thought this group was for arguing about Y2K....

Admit it, you stole that joke from another newsgroup. ;)

FWIW, I've been resisting LOOP for years but I do now sometimes make 
conservative use of it. Now, if DOLIST could do destructuring...
Yes, I know. I should write my own DOLIST. Someday I will, I promise.

This is what I dislike about LOOP - it's so seductive. Why write some new 
and non-standard looping macro, however small it may be, when a standard 
construct is already available? Well, if I wanted a looping macro that 
was a little more ambitious than a destructuring DOLIST, I wouldn't 
hesitate to write it and use it.
-- 
Please note: my email address is munged; You can never browse enough
         "There are no limits." -- ad copy for Hellraiser
From: Jeffrey Mark Siskind
Subject: Re: advice...
Date: 
Message-ID: <yq7g1ic1ybs.fsf@qobi.nj.nec.com>
   (and on top of that, none of the Emacs CL indenting
   facilities works "right" on LOOP).
   As for the editors not being able to indent it correctly, I agree that's an
   annoyance. Zemacs used to get it right, too bad none of the "modern"
   emacs's can.

I prefer to use Jon Amsterdam's ITERATE macro precisely for this reason. (Note
that I am refering to Amsterdam's ITERATE macro, not one of the other macros
that share the same name.) It is similar to LOOP, provides a superset of the
power of LOOP, allows one to define new iteration clauses, and has a standard
parenthesized syntax that any editor that can indent Lisp can indent. IMHO it
is a shame that ANSI CL standardized LOOP. It should have standardized
Amsterdam's ITERATE instead.

I distribute Amsterdam's ITERATE macro as part of my Screamer package which is
available free from my home page. It runs under every Common Lisp known to
mankind.

    Jeff (http://www.neci.nj.nec.com/homepages/qobi)
From: David Bakhash
Subject: Re: advice...
Date: 
Message-ID: <cxjn2ckm75g.fsf@hawk.bu.edu>
hey,

just downloaded this.  I am having trouble finding examples of ND
programming and constraint programming examples out there, but I'm
still looking.  Sounds like it may be applicable to optimization
problems, which would be cool.

dave
From: Graham Hughes
Subject: Re: advice...
Date: 
Message-ID: <8767jb42p7.fsf@oak.treepeople.dyn.ml.org>
-----BEGIN PGP SIGNED MESSAGE-----

>>>>> "David" == David Bakhash <·····@bu.edu> writes:

    David> I use `loop' for (basically) all my iterations.  I like it
    David> a lot, and so I never really use dotimes and stuff like
    David> that.  Is it poor choice to use loop when another
    David> function/macro is more "appropriate"?  Note I'm using ACL,
    David> so I'm not sure if this question depends strongly on the
    David> particular implementation I'm using.  Some might have
    David> really efficient loop implementations, better than others.
    David> Anyway, I find loop very easy to read/write, and I find
    David> that extending an iteration to do more stuff is easier w/
    David> loop than with dotimes, etc.

The long and short of it is, ``yes'', but not because of efficiency or
whatnot.  It is because LOOP is underdefined in the standard; to quote
Paul Graham in _ANSI Common Lisp_, ``[Re: understanding LOOP] The bad
news is that you probably never will, because the ANSI standard does
not really give a formal specification of its behaviour.''

Basically, while the clauses themselves are simple, their interaction
is quite complex, and highly dependent on the implementation.

Now, I agree with you that LOOP macros are nice; it's a constant
battle to wean myself away from them.  If you use them for simple
stuff, you should probably be fine.  But complex things are something
else entirely.

Incidentally, just about anything the LOOP macro does can be done
inside a DO loop, so you might look to those for a possible
replacement.  And DO loops *are* formally specified :-)
- -- 
Graham Hughes <·····@treepeople.dyn.ml.org> 
http://treepeople.dyn.ml.org/thrag/
PGP Fingerprint: 36 15 AD 83 6D 2F D8 DE  EC 87 86 8A A2 79 E7 E6


-----BEGIN PGP SIGNATURE-----
Version: 2.6.3a
Charset: noconv
Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface

iQCVAwUBNVi6NFN2pHdjE11BAQGeZgP/beK5aIlw1n599KE7vpMQSlrPLxksthxE
5+CGXYHDHhEzPgN90EKjQuIo1m0Qf/nvGqjUsBm3ZrmnM/REtFTl5xxuMdq9GGyq
9tayC9BMRiwYnRgwwyqoQlADHQBjpJ5vHWqeQt6yXm80zODDqEzVaIULw05E2xSE
2s6DokqmkRo=
=/dWY
-----END PGP SIGNATURE-----
From: David Bakhash
Subject: Re: advice...
Date: 
Message-ID: <cxju36uzql2.fsf@hawk.bu.edu>
I think I'll stick to loop based on what you're saying.  because I'm
not using it for anything really complicated.  Just as a nice way to
quickly and easily take pseudocode and convert it into real Lisp
code.  I can do stuff really fast with loop.  At the command line,
it's insdispensible to me.  But in code too.  I was more concerned
with efficiency.  I've found good-old loop to work in enough
implementations that I'm not concerned.  Shoot.  it works in elisp,
CLISP, ACL...and it probably works in CMUCL, though I can't say for
sure.  So that's good enough for me, in terms of it being there.

dave
From: Barry Margolin
Subject: LOOP vs DO/DOTIMES/DOLIST (was Re: advice...)
Date: 
Message-ID: <i1j61.26$EA.937990@cam-news-reader1.bbnplanet.com>
[Subject changed to be more meaningful, so I don't have to quote so much.
When I first saw the subject "advice", I assumed the message was going to
be about something like the "advise" function in Zetalisp or GNU Emacs
Lisp.]

In article <··············@oak.treepeople.dyn.ml.org>,
Graham Hughes  <·····@treepeople.dyn.ml.org> wrote:
>The long and short of it is, ``yes'', but not because of efficiency or
>whatnot.  It is because LOOP is underdefined in the standard; to quote
>Paul Graham in _ANSI Common Lisp_, ``[Re: understanding LOOP] The bad
>news is that you probably never will, because the ANSI standard does
>not really give a formal specification of its behaviour.''

While this is true, it's not really relevant to this question.  The
problems with the LOOP specification only apply to complicated combinations
of elements.  Any LOOP that can be replaced by a DOTIMES or DOLIST should
be simple enough that the LOOP specification is adequate.

That said, I generally prefer to use the most specific operator for what
I'm doing.  When I see a DOTIMES, that one word tells me that it's a
simple, numeric iteration; when I see a LOOP, I prepare my mind for the
worst, and then have to read on to understand what type of iteration it's
doing.  While it's possible to go overboard in the direction of terse
syntax (see APL for an extreme), conciseness and precision is a virtue
IMHO.  For the same reason (or perhaps just out of years of habit) I also
prefer SETQ rather than SETF when assigning to a variable.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.