From: Ingemar Hulthage
Subject: Looping over sequences
Date: 
Message-ID: <1tj35o$7ri@morue.usc.edu>
I would like to bring up one issue on the functionality of the X3J13
loop macro.  (BTW, I love the loop macro, to me it's one of those
things that I don't understand how I got by without 8-)

Why does the construct:
(LOOP FOR ELEMENT IN SEQUENCE ...)
only accept sequences of the type list ?

X3J13, as published in CLtL2, specifies a "FOR ELEMENT ACROSS VECTOR"
construct (which isn't implemented in, for example, Lucid 8-(, but I
don't understand why different types of sequences need to be
distinguished.  The MAP function accepts (and returns) any type of
sequence.

Of less importance is that, it would also be convenient if it was
possible to accumulate values into other sequence types than lists.


Ingemar Hulthage

Associate Professor
Computational Organization Design
SSM room 116C.
University of Southern California
Los Angeles, CA 90089-0021
(213) 740-4044 (voice)
(213) 740-8771 (Administrative assistant & fax)
From: Barry Margolin
Subject: Re: Looping over sequences
Date: 
Message-ID: <1tja43INNi5o@early-bird.think.com>
In article <··········@morue.usc.edu> ········@morue.usc.edu (Ingemar Hulthage) writes:
>Why does the construct:
>(LOOP FOR ELEMENT IN SEQUENCE ...)
>only accept sequences of the type list ?

Because that's how LOOP works in MacLisp, ZetaLisp, etc.

>X3J13, as published in CLtL2, specifies a "FOR ELEMENT ACROSS VECTOR"
>construct (which isn't implemented in, for example, Lucid 8-(, but I
>don't understand why different types of sequences need to be
>distinguished.  The MAP function accepts (and returns) any type of
>sequence.

MAP didn't exist in MacLisp and ZetaLisp, so compatibility wasn't an issue.
Notice that MAPC, MAPCAR, etc. are all restricted to lists.

By adding a new preposition, rather than extending the old IN construct,
you can be told at compile time that you're trying to do something that
won't work in that implementation.  If IN had been extended then you
wouldn't be told that Lucid doesn't implement the extension until run time;
and if you compile with low safety, you might not be told at all but the
program could silently misbehave.

>Of less importance is that, it would also be convenient if it was
>possible to accumulate values into other sequence types than lists.

It's pretty easy to accumulate values in a vector yourself using
VECTOR-PUSH-EXTEND.  Accumulating into lists is provided as a built-in
because doing it efficiently requires some convoluted code (some
implementations make use of implementation-dependent features so they can
optimize even better).
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar