[plt-scheme] Macro question
I'm not quite sure, but I think Matt's problem is converting syntax to
symbols or something like that.
You could try using define-macro like in the file bind.scm (it won't let
me copy and paste for some reason).
The file bind.scm.test contains test cases.
David Van Horn wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>mcj4 at ukc.ac.uk wrote:
>
>
>>Hello,
>>
>>I'm working on my macro-fu. In my imagination, the form
>>
>>(bind ([v c1 c2 c3] [v2 c4 c5] [v3 c6]) 'thisisatest)
>>
>>expands to =>
>>
>> (let ((v.c1 (vector-ref v 0))
>> (v.c2 (vector-ref v 1))
>> (v.c3 (vector-ref v 2))
>> (v2.c4 (vector-ref v2 0))
>> (v2.c5 (vector-ref v2 1))
>> (v3.c6 (vector-ref v3 0)))
>> (quote thisisatest))
>>
>>
>
>This gets you pretty close. There's no v.c style binding, but it's compact
>and clear.
>
>BTW, I couldn't reproduce your #%app not bound error...
>
>(define-syntax bind
> (syntax-rules ()
> ((_ ([v c1 c2 ...] ...) e ...)
> (let-values ([(c1 c2 ...) (vector->values v)]
> ...)
> e ...))))
>
>(define (vector->values v)
> (apply values (vector->list v)))
>
>(define v1 #(1 2 3))
>(define v2 #(4 5))
>
>(bind ([v1 c1 c2 c3]
> [v2 c4 c5])
> (+ c1 c2 c3 c4 c5)) ;; -> 15
>
>-d
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20030524/47092582/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: bind.scm.test
URL: <http://lists.racket-lang.org/users/archive/attachments/20030524/47092582/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: bind.scm
URL: <http://lists.racket-lang.org/users/archive/attachments/20030524/47092582/attachment-0001.ksh>