From: Stefan Sonesson
Subject: FOR unbound, What's up?
Date: 
Message-ID: <37445963.EEDD9585@swipnet.se>
Hello,

I use GCL 2.2.2
When I try to do this:

(loop for book in *books*
  when(and (>= (read-from-string (book-year book)
    (search "Steele" (book-author book))
      collect book)

/*  *books* is a list of several book that are structures */

I get the error "The variable FOR is unbound",  I suspect I should not
use
the syntax <for> and <in> but I don't know how it should be done.

I also have another problem:
(setq *books*
  (list (make-book :subject "a" :title "b" :author '("a1" "a2" "a3")
:publisher "c" :year "1")
  .......

Question is, how do I search for an author e.g. "a2"?
I know how to do it for the other attributes, but it can't be done the
same way.

That's all for now.

/Stefan Sonesson

From: Gareth McCaughan
Subject: Re: FOR unbound, What's up?
Date: 
Message-ID: <86pv3vzif2.fsf@g.pet.cam.ac.uk>
Stefan Sonesson wrote:

> I use GCL 2.2.2
> When I try to do this:
> 
> (loop for book in *books*
> when(and (>= (read-from-string (book-year book)
> (search "Steele" (book-author book))
> collect book)
> 
> /*  *books* is a list of several book that are structures */

You mean

;; *books* is a list of several books that are structures

:-) You've also missed a closing parenthesis.

> I get the error "The variable FOR is unbound",  I suspect I should not
> use
> the syntax <for> and <in> but I don't know how it should be done.

Sounds like GCL doesn't understand extended LOOP. For this problem,
DOLIST should do well enough. Cons up a list in reverse order (start
with NIL and cons each book onto it as it's found) and then (if the
order matters) NREVERSE the list.

> I also have another problem:
> (setq *books*
> (list (make-book :subject "a" :title "b" :author '("a1" "a2" "a3")
>: publisher "c" :year "1")
> .......
> 
> Question is, how do I search for an author e.g. "a2"?
> I know how to do it for the other attributes, but it can't be done the
> same way.

Loop through the books looking for ones for which "a1" is a member
of the list of authors. The MEMBER predicate might be your friend here.
Or, if you think you might want to use vectors or something instead
of lists some day, FIND.

If this list is going to be searched much more often than it's
updated, you might find it profitable to build some other data
structures -- e.g., a hash table mapping each author to a list
of all the books with that author.

-- 
Gareth McCaughan       Dept. of Pure Mathematics & Mathematical Statistics,
·····@dpmms.cam.ac.uk  Cambridge University, England.
From: Raymond Toy
Subject: Re: FOR unbound, What's up?
Date: 
Message-ID: <4n1zgbjw9j.fsf@rtp.ericsson.se>
>>>>> "Gareth" == Gareth McCaughan <·····@dpmms.cam.ac.uk> writes:

    Gareth> Sounds like GCL doesn't understand extended LOOP. For this problem,

I'm pretty sure GCL doesn't even have an ANSI loop.  There is a
version of loop in GCL but I think it's called sloop (W. Schelter's
loop).  It's not quite ANSI either.

However, the ansi loop in the CMU AI archives should work.  Or you can
get a version for gcl from http://www.mindspring.com/~rtoy somewhere.
I haven't kept it up-to-date, though (too much other work, too little
time).

Ray
From: Marco Antoniotti
Subject: Re: FOR unbound, What's up?
Date: 
Message-ID: <lwpv3u3lz3.fsf@copernico.parades.rm.cnr.it>
Stefan Sonesson <···············@swipnet.se> writes:

> Hello,
> 
> I use GCL 2.2.2
> When I try to do this:
> 
> (loop for book in *books*
>   when(and (>= (read-from-string (book-year book)
>     (search "Steele" (book-author book))
>       collect book)
> 
> /*  *books* is a list of several book that are structures */
> 
> I get the error "The variable FOR is unbound",  I suspect I should not
> use
> the syntax <for> and <in> but I don't know how it should be done.
> 
> I also have another problem:
> (setq *books*
>   (list (make-book :subject "a" :title "b" :author '("a1" "a2" "a3")
> :publisher "c" :year "1")
>   .......
> 
> Question is, how do I search for an author e.g. "a2"?
> I know how to do it for the other attributes, but it can't be done the
> same way.
> 
> That's all for now.
> 


GCL is up.  Dump it and get CMUCL or CLISP at www.cons.org.

I haven't checked it lately, but you can try to load a just installed
copy of GCL and then do

	(DEFPACKAGE "I-DO-NOT-WORK-IN-GCL" (:use "CL"))

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