guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: define-syntax


From: Pach Roman (DGS-EC/ESG3)
Subject: AW: define-syntax
Date: Tue, 9 Dec 2008 21:52:34 +0100

>> I've performed following two short tests.
>>
>> test 1:
>> -------
>>
>> (use-syntax (ice-9 syncase))
>>
>> (define-syntax my-macro-1
>>   (syntax-rules ()
>>     ((_ par1 par2 par3)
>>      (begin
>>            (string-concatenate (list par1 par2 par3))
>>            ))))
>>
>> (define (dummy)
>>   (my-macro-1 "a" "b" "c"))
>>
>> (format #t "dummy => ~s\n" (procedure-source dummy))
>>
>> result:
>> dummy => (lambda () (string-concatenate (list "a" "b" "c")))
>>
>> test 2:
>> -------
>> (define-macro (my-macro-2 par1 par2 par3)
>>   (string-concatenate (list par1 par2 par3)))
>>
>> (define (dummy)
>>   (my-macro-2 "a" "b" "c")
>>   )
>> (dummy)
>> (format #t "dummy => ~s\n" (procedure-source dummy))
>>
>> result:
>> dummy => (lambda () "abc")
>>
>> It seems to me the define-syntax is broken in version "1.8.2"
>> or I've done something wrong.
>
> These examples both look good to me.  Which one do you think is wrong?
>
> It may help if I point out that define-macro usage usually involves
> backquoting.  The define-macro version of your define-syntax example
> would normally be:
>
>  (define-macro (my-macro-2 par1 par2 par3)
>    `(string-concatenate (list ,par1 ,par2 ,par3)))
>
> Regards,
>       Neil

take look at the results

(1) dummy => (lambda () (string-concatenate (list "a" "b" "c")))
(2) dummy => (lambda () "abc")

in the case of define-syntax (1) the string "abc" will be computed at
the run time,
the macro version (2) hat produced the "abc" already by reading the
macro definition.
I've expected both of the be computed during the reading of scheme
source.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]