Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

The whole world is a tuxedo and you are a pair of brown shoes. -- George Gobel


comp / comp.lang.lisp / Re: getting list of keys

SubjectAuthor
* Re: getting list of keysB. Pym
`- Re: getting list of keysB. Pym

1
Subject: Re: getting list of keys
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Fri, 30 Aug 2024 22:27 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: getting list of keys
Date: Fri, 30 Aug 2024 22:27:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <vath1c$ltbf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 31 Aug 2024 00:27:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c51450164ff44e4b4c9e62a2e4bb2981";
logging-data="718191"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CarP2I2QZSBLKEQpXlTRK"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:yYAbxlZsGbQjUc9OahSKoUPEJE4=
View all headers

> > an `update' function for the mp3 database.
> > I need a function for doing something like this with a list:
> >
> > * (xxxx (list :artist "something" :song "sss"))
> > => (:artist :song)
> >
> > Thanks in advance, and sorry for my bad english.
> > --
> > Pablo.
>
> CL-USER> (loop :for (x y) :on (list :artist "something" :song "sss") :by #'cddr
> :collect x)
> (:ARTIST :SONG)

Gauche Scheme and Racket using unfold from SRFI-1.

(use srfi-1) ;; unfold for Gauche
or
(require srfi/1) ;; unfold for Racket

(unfold null? car cddr '(:artist "something" :song "sss"))
===>
(:artist :song)

Subject: Re: getting list of keys
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Fri, 30 Aug 2024 23:02 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: getting list of keys
Date: Fri, 30 Aug 2024 23:02:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <vatj2b$m815$1@dont-email.me>
References: <vath1c$ltbf$1@dont-email.me>
Injection-Date: Sat, 31 Aug 2024 01:02:37 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c51450164ff44e4b4c9e62a2e4bb2981";
logging-data="729125"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dcVM++E5DgWj0xZZ/RJDp"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:z6rJMTSN070JQ/QS+FCfhVK4LQY=
View all headers

B. Pym wrote:

> > > an `update' function for the mp3 database.
> > > I need a function for doing something like this with a list:
> > >
> > > * (xxxx (list :artist "something" :song "sss"))
> > > => (:artist :song)
> > >
> > > Thanks in advance, and sorry for my bad english.
> > > --
> > > Pablo.
> >
> > CL-USER> (loop :for (x y) :on (list :artist "something" :song "sss") :by #'cddr
> > :collect x)
> > (:ARTIST :SONG)
>
> Gauche Scheme and Racket using unfold from SRFI-1.
>
> (use srfi-1) ;; unfold for Gauche
> or
> (require srfi/1) ;; unfold for Racket
>
> (unfold null? car cddr '(:artist "something" :song "sss"))
> ===>
> (:artist :song)

Rob Warnock wrote:

> The one place I find myself frequently using CDD*R
> is in destructuring lists by "gulps" in LOOP, e.g.:
>
> > (defun group-by-triples (list)
> (loop for (a b c) on list by #'cdddr
> collect (list a b c)))
>
> GROUP-BY-TRIPLES
> > (group-by-triples '(0 1 2 3 4 5 6 7 8 9 10 11 12))
>
> ((0 1 2) (3 4 5) (6 7 8) (9 10 11) (12 NIL NIL))

Gauche Scheme

(use srfi-1) ;; unfold

"take*" and "drop*" are tolerant; they don't raise an
exception when the list is too short.

(define (group-by-triples xs)
(unfold null? (cut take* <> 3 #t) (cut drop* <> 3) xs))

(group-by-triples (iota 13))
===>
((0 1 2) (3 4 5) (6 7 8) (9 10 11) (12 #f #f))

1

rocksolid light 0.9.8
clearnet tor