[plt-scheme] getting argument identifiers

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Fri Oct 17 06:18:42 EDT 2008

Stephen De Gabrielle wrote:
> What I was trying to do was define a macro that would dump whatever I
> stuffed into it. (instead of using printf functions all through my
> code)
> It can get unwieldy so I wanted to print the identifiers too.
>
>  (define-syntax dump-all
>   (syntax-rules ()
>     [(_ x ...)
>      (begin
>        (printf "Dump:~N")
>        (for-each
>          (lambda (i) (printf "item:~n~v~n" i))
>          (list x ...))
>        (printf "Dump End~n")
>        )]))
>
> (define x "dfd")
> (dump-all 2 4 x)
>   

Do you mean something like this?

#lang scheme
(define-syntax dump-all
  (syntax-rules ()
    [(_ x ...)
     (begin
       (for-each (lambda (e v) (printf "expression: ~v  value: ~v ~n" e v))
                 '(x ...)
                 (list x ...)))]))

(define x "dfd")
(dump-all 2 4 x)

which prints

expression: 2  value: 2
expression: 4  value: 4
expression: x  value: "dfd"

?

-- 
Jens Axel Søgaard



Posted on the users mailing list.