Re: lisp newbie here
From: Pascal Costanza (costanza_at_web.de)
Date: 04/10/04
- Next message: André Thieme: "Re: Use of dynamic variables"
- Previous message: Brian Mastenbrook: "Re: Sentience"
- In reply to: Kenny Tilton: "Re: lisp newbie here"
- Next in thread: Eric Smith: "Re: lisp newbie here"
- Reply: Eric Smith: "Re: lisp newbie here"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 10 Apr 2004 23:18:32 +0200
Kenny Tilton wrote:
> (loop for (a b) on '(a b c d e) by 'cddr
> collecting (if b
> (list a b)
> (list a)))
>
> ...or if you don't mind padding the last pair:
>
> (loop for (a b) on '(a b c d e) by 'cddr
> collecting (list a b))
Hmm, this looks like a good way to iterate over property lists. I have
implemented a relatively complex doplist some time ago, and I was
surprised that CL doesn't offer anything predefined for that purpose.
Now this is already considerably simpler.
However, you probably want to make sure that the length of a property
list is even, so that all properties get one value, and that the last
property doesn't accidentally get a nil value. So I came up with this:
(loop for (a b) on '(:a b :c d :e nil) by (lambda (list)
(assert (cdr list))
(cddr list))
collect (list a b))
Is there a simpler way to do this?
Pascal
-- 1st European Lisp and Scheme Workshop June 13 - Oslo, Norway - co-located with ECOOP 2004 http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
- Next message: André Thieme: "Re: Use of dynamic variables"
- Previous message: Brian Mastenbrook: "Re: Sentience"
- In reply to: Kenny Tilton: "Re: lisp newbie here"
- Next in thread: Eric Smith: "Re: lisp newbie here"
- Reply: Eric Smith: "Re: lisp newbie here"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|