I found section 6.1 "The LOOP Facility" of the HyperSpec quite
helpful.
http://www.xanalys.com/software_tools/reference/HyperSpec/index.html
The hyperspec is pretty definitive, and is a bunch of web pages.
And it's actually a good way to learn it. I read some LOOP tutorial
somewhere that got me through for, in, across, collecting, min, max,
and maybe summing and a couple others; then, I just read the spec on
LOOP, which, once you get the basics of LOOP, is an easy, exciting
read. And I've been fairly loopy ever since ;-)
--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'
>Tim Bradshaw <t...@tfeb.org> writes:
>
>> * Thaddeus L Olczyk wrote:
>> > Is there somewhere where a person can find a reference to
>> > the loop macro that convers it inside and out?
>> > Preferably a web site ( so that I can copy it to my internal
>> > server so I don't have to constantly go digging for it ).
>>
>> The hyperspec is pretty definitive, and is a bunch of web pages.
>
>And it's actually a good way to learn it. I read some LOOP tutorial
>somewhere that got me through for, in, across, collecting, min, max,
>and maybe summing and a couple others; then, I just read the spec on
>LOOP, which, once you get the basics of LOOP, is an easy, exciting
>read. And I've been fairly loopy ever since ;-)
Have you read what you wrote:
I learned from a tutorial, then I read CLHS.
So you should read CLHS.
From what you wrote, it sounds more like I should read the tutorial.
PS I find CLHS on the subject very abbreviated. OTOH I've got the
one that came with LispWorks. Maybe I need to find a more upto date
one? Or perhaps a dated one.
> Tim Bradshaw <t...@tfeb.org> writes:
>
> And it's actually a good way to learn it. I read some LOOP tutorial
> somewhere that got me through for, in, across, collecting, min, max,
> and maybe summing and a couple others;
Probably this one: <http://www.ai.sri.com/~pkarp/loop.html>.
Edi.
--
Dr. Edmund Weitz
Hamburg
Germany
The Common Lisp Cookbook
<http://agharta.de/cookbook/>
*I* think you should learn by playing and by the CLHS, that worked for
me. Macroexpanding things to see what happens is useful too.
--tim
I used the book _Common Lisp The Language_ that is available on
the web at: http://tcw2.ppsw.rug.nl/cltl/clm/node1.html
or: http://www-2.cs.cmu.edu/Groups/AI/html/cltl/cltl2.html
I found it useful to remember that the loop macro uses pairs of
keywords and values and used colon on the keywords as shown below.
Not everyone agrees with this practice but it helped me quickly
learn the keywords and recognize when the keywords and values
were not paired up. The other benefit is that emacs recognizes
the keywords and keeps the indentation pretty.
(cut from emacs):
LISP(5): (loop
:for i :from 1 :to 10
:collect i :into num-list
:count i :into num-count
:sum i :into num-sum
:finally (return
(format nil "Sum of ~s numbers in ~s is ~s"
num-count num-list num-sum)))
"Sum of 10 numbers in (1 2 3 4 5 6 7 8 9 10) is 55"
I remember reading or hearing this disapproval
somewhere too but don't remember the rationale behind
it. Could someone recount why this colonization tactic
is not approved practice?
--d
Tim
> Jeff Sandys <san...@juno.com> wrote:
>
> >I found it useful to remember that the loop macro uses pairs of
> >keywords and values and used colon on the keywords as shown below.
> >
> >Not everyone agrees with this practice but it helped me quickly
>
> I remember reading or hearing this disapproval somewhere too but
> don't remember the rationale behind it. Could someone recount why
> this colonization tactic is not approved practice?
Because it looks ugly.
;)
> On 12 Feb 2002 22:06:04 -0800, t...@whirlwind.OCF.Berkeley.EDU (Thomas
> F. Burdick) wrote:
>
> >Tim Bradshaw <t...@tfeb.org> writes:
> >
> >> * Thaddeus L Olczyk wrote:
> >> > Is there somewhere where a person can find a reference to
> >> > the loop macro that convers it inside and out?
> >> > Preferably a web site ( so that I can copy it to my internal
> >> > server so I don't have to constantly go digging for it ).
> >>
> >> The hyperspec is pretty definitive, and is a bunch of web pages.
> >
> >And it's actually a good way to learn it. I read some LOOP tutorial
> >somewhere that got me through for, in, across, collecting, min, max,
> >and maybe summing and a couple others; then, I just read the spec on
> >LOOP, which, once you get the basics of LOOP, is an easy, exciting
> >read. And I've been fairly loopy ever since ;-)
>
> Have you read what you wrote:
> I learned from a tutorial, then I read CLHS.
> So you should read CLHS.
You somehow got my 57 word statement wrong in your 22 word summary.
That's actually kind of impressive. I told you how I learned LOOP,
and that's it. I didn't say what you should do at all, I left that
implied; the implication being (since you seem to have had a hard time
with it the first time) that you should find a simple tutorial that
will get you the basic idea of how LOOP works, then read the spec. I
mostly learned from the spec. Of course, I have very good reading
comprehension, so YMMV.
> From what you wrote, it sounds more like I should read the tutorial.
> PS I find CLHS on the subject very abbreviated. OTOH I've got the
> one that came with LispWorks. Maybe I need to find a more upto date
> one? Or perhaps a dated one.
? The content is the same. Once you get the basic idea of how LOOP
functions, the spec is crystal clear.
> t...@whirlwind.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
>
> > Tim Bradshaw <t...@tfeb.org> writes:
> >
> > And it's actually a good way to learn it. I read some LOOP tutorial
> > somewhere that got me through for, in, across, collecting, min, max,
> > and maybe summing and a couple others;
>
> Probably this one: <http://www.ai.sri.com/~pkarp/loop.html>.
It wasn't, although it just as well could have been :)
To expand on that, LOOP was designed to look English-like. Throwing in all
those colons is contrary to this idea. It no longer looks like English,
and because it doesn't have much in the way of parens it also doesn't look
like Lisp, it's just an ugly mutt of a language.
If you want a Lispy iteration language, use Series.
--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
> In article <sfwadud...@shell01.TheWorld.com>,
> Kent M Pitman <pit...@world.std.com> wrote:
> >ds...@goldshoe.gte.com (Dorai Sitaram) writes:
> >
> >> Jeff Sandys <san...@juno.com> wrote:
> >>
> >> >I found it useful to remember that the loop macro uses pairs of
> >> >keywords and values and used colon on the keywords as shown below.
> >> >
> >> >Not everyone agrees with this practice but it helped me quickly
> >>
> >> I remember reading or hearing this disapproval somewhere too but
> >> don't remember the rationale behind it. Could someone recount why
> >> this colonization tactic is not approved practice?
> >
> >Because it looks ugly.
>
> To expand on that, LOOP was designed to look English-like. Throwing in all
> those colons is contrary to this idea. It no longer looks like English,
> and because it doesn't have much in the way of parens it also doesn't look
> like Lisp, it's just an ugly mutt of a language.
>
> If you want a Lispy iteration language, use Series.
I agree with Barry's analysis, but would add further the following:
The aim is not only to look English-like, though it does that too, but
also to offer "infix special operators". Putting :'s on them looks visually
to me the same as if you wrote :'s at the start of your special operator
and/or macro names.
(:defun f (x)
(:cond ((zerop x) 1)
(:t (* x (f (1- x))))))
That's not to say that others don't see it more like keyword-called
functions, which is presumably why they don't mind the colons. I'm
just trying to explain the alternate view for those who defaultly see
it the other way...
I often use the cl.el documentation; the cl library contains a
(mostly-complete) LOOP implementation. The docs are in Info format,
which means that I can very easily read them from within Emacs.
(C-h i m cl)
hth,
--
BPT <b...@tunes.org> /"\ ASCII Ribbon Campaign
backronym for Linux: \ / No HTML or RTF in mail
Linux Is Not Unix X No MS-Word in mail
Meme plague ;) ---------> / \ Respect Open Standards
> I found it useful to remember that the loop macro uses pairs of
> keywords and values and used colon on the keywords as shown below.
(loop :for key
:being :each
:hash-key :of
<hash-table> :using
(:hash-value value)
:collect (list key value))
Maybe I'm doing something wrong here ;-)
--
Lieven Marchand <m...@wyrd.be>
She says, "Honey, you're a Bastard of great proportion."
He says, "Darling, I plead guilty to that sin."
Cowboy Junkies -- A few simple words
JS|||| found it useful to remember that the loop macro uses pairs
JS|||| of keywords and values and used colon on the keywords.
KP||| Because it looks ugly.
BM|| To expand on that, LOOP was designed to look English-like.
BM|| Throwing in all those colons is contrary to this idea.
BM|| It no longer looks like English,
KP| The aim is not only to look English-like, though it does that too,
KP| but also to offer "infix special operators". Putting :'s on them
KP| looks visually to me the same as if you wrote :'s at the start of
KP| your special operator and/or macro names.
My question to Kent:
By "infix" you mean that in the expression (loop :for i :from 5 ...)
that the :from has to follow the :for ?
Why do you call them "operators", they do not return a value?
Comments:
* Yes, it is ugly to those familar to the loop macro.
* Keywords should not look out of place in Lisp.
* Keywords are part of many functions:
(remove 3 '(1 2 3 1 3 4 5) :count 1)
* We can define our own keywords in our defuns.
* CLTL calls them loop keywords even though CLTL doesn't use the colon.
* It still reads English-like. (the colon is silent :)
* Thinking that a programming language is English-like is dangerous.
* It is a suggestion for *learning* the loop keywords.
* Advantages:
* Clarity, keyword value pairs
* emacs formatting, indents cleanly
My current Lisp programming is with ICAD that extensively
uses keywords, so I am probably tainted by that experience.
But consider this (bad) lisp dialog in the context
of teaching and learning the loop macro:
LISP(2): (setq from 1)
1
LISP(3): (setq to 5)
5
LISP(4): (loop for i from from to to
collect i)
(1 2 3 4 5)
LISP(5): (loop :for i :from from :to to
:collect i)
(1 2 3 4 5)
Thanks,
Jeff Sandys
> KP|Kent M Pitman wrote:
> BM||Barry Margolin <bar...@genuity.net> writes:
> JS||||Jeff Sandys <san...@juno.com> wrote:
>
> JS|||| found it useful to remember that the loop macro uses pairs
> JS|||| of keywords and values and used colon on the keywords.
>
> KP||| Because it looks ugly.
>
> BM|| To expand on that, LOOP was designed to look English-like.
> BM|| Throwing in all those colons is contrary to this idea.
> BM|| It no longer looks like English,
>
> KP| The aim is not only to look English-like, though it does that too,
> KP| but also to offer "infix special operators". Putting :'s on them
> KP| looks visually to me the same as if you wrote :'s at the start of
> KP| your special operator and/or macro names.
>
> My question to Kent:
> By "infix" you mean that in the expression (loop :for i :from 5 ...)
> that the :from has to follow the :for ?
I think he means "infix" as in "Pascal-like". That camp of languages
probably wouldn't call themselves "infix" (because that's hardly their
most interesting characteristic, from their users' point of view), but
from here, that's what they look like. You could also say
"conventional", but unfortunately, that might imply lots of line-noise
characters.
> Why do you call them "operators", they do not return a value?
>
> Comments:
> * Yes, it is ugly to those familar to the loop macro.
It looks ugly without syntax highlighting. With it, you don't see the
colon, because of the bright color of the "for" in :for
> * Keywords should not look out of place in Lisp.
> * Keywords are part of many functions:
> (remove 3 '(1 2 3 1 3 4 5) :count 1)
> * We can define our own keywords in our defuns.
But the keywords are only being used as symbols here, not as keywords.
As someone else pointed out:
(loop :for k
:being :the
:hash-keys :of
my-hash-table :collecting
(gethash k my-hash-table))
> * CLTL calls them loop keywords even though CLTL doesn't use the colon.
This is an overloading of the term "keyword".
> * It still reads English-like. (the colon is silent :)
> * Thinking that a programming language is English-like is dangerous.
Thinking that the LOOP language *is* English is dangerous. Thinking
that it's as english-like as Algol or Pascal, is okay. Provided the
person thinking this knows Algol or Pascal :)
> * It is a suggestion for *learning* the loop keywords.
> * Advantages:
> * Clarity, keyword value pairs
> * emacs formatting, indents cleanly
I used to only code Lisp under X11. I also used to use keywords as
loop keywords/operators, when I was less comfortable with LOOP. The
font-locking of it was kind of nice, being more what one would want
for a language of its style. After a while, I didn't really find much
use for the coloring crutch, and was horrified at how it looked on a
terminal. So, no more keywords for me :) The LOOP language is simple
enough that I don't think it really needs coloring. Unlike, say,
Perl.
> My current Lisp programming is with ICAD that extensively
> uses keywords, so I am probably tainted by that experience.
>
> But consider this (bad) lisp dialog in the context
> of teaching and learning the loop macro:
>
> LISP(2): (setq from 1)
> 1
> LISP(3): (setq to 5)
> 5
> LISP(4): (loop for i from from to to
> collect i)
> (1 2 3 4 5)
> LISP(5): (loop :for i :from from :to to
> :collect i)
> (1 2 3 4 5)
Huh. I've never gotten indentation like in (4).
I think Jeff's calling attention to the same identifier
being used to mean different things in the selfsame
expression. It's confusing to me without a couple of
rescans, but I have a Lisp1 background, so I
doubt it's a universal reaction. Lisp2+ folks would
probably eat it up and ask for more, "because it's just
like English".
--d
>olc...@interaccess.com (Thaddeus L Olczyk) writes:
>
>> Is there somewhere where a person can find a reference to
>> the loop macro that convers it inside and out?
>> Preferably a web site ( so that I can copy it to my internal
>> server so I don't have to constantly go digging for it ).
>>
>I often use the cl.el documentation; the cl library contains a
>(mostly-complete) LOOP implementation. The docs are in Info format,
>which means that I can very easily read them from within Emacs.
>
>(C-h i m cl)
>
>hth,
You're right. Who would have figured it!
I think that the implementation of hash facilities in loop is an
example of trying to make loop too English-like by adding noise
words. All eight combinations of each|the, hash-key|hash-keys and
in|of is valid and do the same thing, where one is needed:
being each hash-key in being each hash-key of
being the hash-keys in being the hash-keys of
being each hash-keys in being each hash-keys of
being the hash-key in being the hash-key of
Also :hash-value|:hash-values creates eight similar combinations.
The words "each" and "the" are just noise words that I think
should have been left out. This below is not a legal lisp
expressions but is easily read and keeps the keyword value pairs:
(loop
:for key :being hash-key :of <hash-table>
:using (hash-value value)
:collect (list key value))
I'm sure if the Lisp standards committee could have found a
preposition that clearly meant being-the-hash-keys-in they
would have used it instead.
Finally, my comment is meant for learning the loop facility.
Most beginners don't start out looping hash tables. I resisted
learning loop because it was un-lisp-like, using do instead.
Once I gronked the keyword value pairs of loop, I understood
that it was lisp and quickly learned how to use loop.
Loop is a powerful facility that every lisper should learn
and love to use. (it's St. Valentine's Day today)
Thanks,
Jeff Sandys
You know, this is not true: "then", "and", and "end" break the keyword
pair pattern that isn't there. There are probably more exceptions to
this non-existing "rule".
when foo collect x and collect y.
if foo then if bar then do (mumble) end else do (frotz).
///
--
In a fight against something, the fight has value, victory has none.
In a fight for something, the fight is a loss, victory merely relief.
I disagree. The spirit of this is very similar to that which allows both
COLLECT and COLLECTING:
(loop for x in list
collecting x)
(loop for x in list
when (oddp x) collect x)
If what you want is Info format CL docs, GCL has one of the drafts for
ANSI CL in Info format. (Or, at least, it used to have.)
TTFN,
'mr
--
rydis (Martin Rydstr|m) @CD.Chalmers.SE ; With a spirit soaring ten miles high,
<URL:http://www.cd.chalmers.se/~rydis/> ; I sing loud words that make me cry...
[Emacs] is written in Lisp, which is the only computer language that is
beautiful. -- Neal Stephenson, _In the Beginning was the Command Line_