<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.6000.16735" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=spdegabrielle@gmail.com href="mailto:spdegabrielle@gmail.com">Stephen
De Gabrielle</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=plt-scheme@list.cs.brown.edu
href="mailto:plt-scheme@list.cs.brown.edu">PLT List</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, November 21, 2008 1:07
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [plt-scheme]
lambda-apply-values</DIV>
<DIV><BR></DIV>
<DIV>Hi, <BR><BR>something I seem to often do is use list as structures, (and
have lists of these)<BR><BR>eg<BR><BR>#lang scheme<BR>(define people
'(("Guy" 40 man) ("Maddona" 50 woman)))<BR><BR>I am often doing something
like;<BR><BR>(map (λ (person) <BR>(let ((name (car person))<BR>
(age (car person))<BR>
(gender (car person))) <BR> (blah-fn name age
gender)<BR> ) people)<BR><BR>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))<BR><BR>I realise this is a bit rubbish and have thought of
a better way; <BR><BR>(map (λ (person)
<BR> (let-values ([(name age gender)
(apply values person)])<BR>
(blah-fn name age gender)<BR>
)) people)<BR><BR>I sort of suspect that a macro might be the ticket - like;
<BR><BR><BR>(define-syntax-rule (lambda-apply-values-person1 values-list
blah-fn x y z)<BR> (λ (values-list)<BR> (let-values
([(x y z) (apply values values-list)])<BR>
(blah-fn x y z)<BR> )))<BR><BR>(map
(lambda-apply-values-person1 person (lambda args (display args)) x y z)
people)<BR><BR>which works but doesn't handle multiple identifiers;
<BR><BR>(define-syntax lambda-apply-values-person2<BR> (syntax-rules
()<BR> (lambda-apply-values-person2 values-list (x y
z))<BR> (λ (values-list)
<BR> (let-values ([(...) (apply values
values-list)]) <===<BR> (list
...)<BR> ))))<BR>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.</DIV></BLOCKQUOTE>
<DIV><FONT face="Courier New"><FONT size=2><FONT face="Courier New" size=2>May
be </FONT></FONT></FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>(define-syntax
lambda-apply-values-person2<BR> (syntax-rules ()<BR> ((_
((values-list (e ...)) ...) . body)<BR> (λ (values-list
...) <BR> (let-values ([(e ...) (apply
values values-list)] ...)<BR> .
body)))))</FONT></DIV>
<DIV><FONT face="Courier New" size=2><BR>(map (lambda-apply-values-person2
((lsta (a b c)) (lstx (x y))) (list a b c x y))<BR> '((a0 b0 c0) (a1 b1
b2)) '((x0 y0) (x1 y1))) ;--> ((a0 b0 c0 x0 y0) (b0 b1 b2 x1
y1))</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Jos</FONT></DIV>
<DIV><FONT face="Courier New"><FONT size=2><FONT face="Courier New"
size=2></FONT></FONT></FONT> </DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>Because I do this all the time I'm sure that others have a better way.
What do you do?<BR><BR>Cheers,<BR><BR>Stephen<BR><BR><BR></DIV>
<P>
<HR>
<P></P>_________________________________________________<BR> For
list-related administrative tasks:<BR>
http://list.cs.brown.edu/mailman/listinfo/plt-scheme<BR></BLOCKQUOTE></BODY></HTML>