[CM] query on references within Loop
Tue, 15 Aug 2006 11:14:45 +0200
On Tue, 2006-08-15 at 16:31 +1200, Adam wrote:
> This has me a little puzzled, in Common Music,
> The intention is that Loop cycles through a list, and for each entry then
> collects a list carried in that item.
> However an error reports that .. a-ref is not of type list. While it
> appears to be a list, perhaps its outside of the Loop scope somehow ?
> Can anyone suggest where I am going wrong here ?
I'm far away from my CM-repl, but i think you should be careful with
your quoting ...
> (define a-ref '('a1 (1 2 3) 'a2))
> (define b-ref '('b1 (4 5 6) 'b2))
> (define c-ref '('c1 (7 8 9) 'c2))
As a rule of thumb: you'll most likely never want to quote within a
quoted list. The #\' character is reader magic that expands to
(quote ...) and is done _before_ the evaluator "sees" a form. So the
above is fed to the evaluator as:
(quote ((quote c1) (7 8 9) (quote c2)))
which evaluates to
((quote c1) (7 8 9) (quote c2))
Is this really what you want? This is a list of three lists and
most likely you wanted a list of a symbol, a list and a symbol ...
> (define ref-list '(a-ref b-ref c-ref))
Remeber: quoting stops evaluation, so ref-list is a list of three
symbols. This is why LOOP complains.
(define ref-list (list a-ref b-ref c-ref))
Some Lispers will still go for the quoting syntax, but then you need
(define ref-list `(,a-ref ,b-ref ,c-ref))
HTH, Ralf Mattes
> (loop for refx in ref-list
> (loop for data in (second refx)
> collect data))
> Cmdist mailing list