Re: lisp newbie here

From: Pascal Costanza (costanza_at_web.de)
Date: 04/10/04


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/


Relevant Pages

  • Re: lisp newbie here
    ... > collecting ) ... it possible to use more complex lists? ... commands in clisp? ...
    (comp.lang.lisp)
  • [Full-Disclosure] Re: mailman email harvester
    ... > scripts can subscribe to gain access to restricted lists. ... collecting such addresses. ... The harvesters don't bother because there are so many un-obfuscated email ... > subscribers, processes more lists and works more parallelized is ...
    (Full-Disclosure)
  • Re: lisp newbie here
    ... |> collecting ) ... | So loop will set to corresponding elements in '? ... | Is it possible to use more complex lists? ... It may have been bad syntax, or a CLISP bug. ...
    (comp.lang.lisp)
  • Re: Administrivia: Discussion - Making this list subscriber-only
    ... >>> Hmm. ... lists like -security-questions should be created. ... to freebsd-security, sans the excitement about Spam and off-topic posts. ... >>> are committed, and b) if enough of them come, ensuring that you can commit ...
    (FreeBSD-Security)
  • Re: ..how do I tell apt-get | dpkg about bad files off a bad disk? Clue Whack, Please!
    ... > Reading Package Lists... ... > Building Dependency Tree... ... hmm, not sure why that would be, I suppose it could be related to the ...
    (Debian-User)