[plt-scheme] Re: lambda-apply-values

From: kbohdan at mail.ru (kbohdan at mail.ru)
Date: Fri Nov 21 07:32:09 EST 2008

What about
(map (lambda (p) (apply blah-fn p))
      people)
?

--
Bohdan

Stephen De Gabrielle wrote:
> Hi,
> 
> something I seem to often do is use list as structures, (and have lists 
> of these)
> 
> eg
> 
> #lang scheme
> (define  people '(("Guy" 40 man) ("Maddona" 50 woman)))
> 
> I am often doing something like;
> 
> (map (λ (person)
> (let ((name (car person))
>         (age (car person))
>         (gender (car person))) 
>    (blah-fn name age gender)
>  ) people)
> 
> I could, but don't often, do (map (λ (name age gender) (blah-fn name age 
> gender) ) (map car people) (map cadr people) (map caddr people))
> 
> I realise this is a bit rubbish and have thought of a better way;
> 
> (map (λ (person)
>        (let-values ([(name age gender)  (apply values person)])
>          (blah-fn name age gender)
>          )) people)
> 
> I sort of suspect that a macro might be the ticket - like;
> 
> 
> (define-syntax-rule (lambda-apply-values-person1 values-list blah-fn x y z)
>   (λ (values-list)
>     (let-values ([(x y z)  (apply values values-list)])
>       (blah-fn x y z)
>       )))
> 
> (map (lambda-apply-values-person1 person (lambda args (display args)) x 
> y z)  people)
> 
> which works but doesn't handle multiple identifiers;
> 
> (define-syntax lambda-apply-values-person2
>   (syntax-rules ()
>     (lambda-apply-values-person2 values-list ...)
>     (λ (values-list) 
>       (let-values ([(...)  (apply values values-list)])
>         (list ...)
>         ))))
> of course this doesn't work. I suspect I can't do this with syntax-rules 
> and need to look at syntax-case and the syntax form.
> 
> Because I do this all the time I'm sure that others have a better way. 
> What do you do?
> 
> Cheers,
> 
> Stephen
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.