* define-syntax
@ 2008-12-09 16:51 Pach Roman (DGS-EC/ESG3)
2008-12-09 20:20 ` define-syntax Neil Jerram
0 siblings, 1 reply; 5+ messages in thread
From: Pach Roman (DGS-EC/ESG3) @ 2008-12-09 16:51 UTC (permalink / raw)
To: guile-devel
[-- Attachment #1: Type: text/plain, Size: 779 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 3011 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: define-syntax
2008-12-09 16:51 define-syntax Pach Roman (DGS-EC/ESG3)
@ 2008-12-09 20:20 ` Neil Jerram
2008-12-09 20:52 ` AW: define-syntax Pach Roman (DGS-EC/ESG3)
0 siblings, 1 reply; 5+ messages in thread
From: Neil Jerram @ 2008-12-09 20:20 UTC (permalink / raw)
To: Pach Roman (DGS-EC/ESG3); +Cc: guile-devel
2008/12/9 Pach Roman (DGS-EC/ESG3) <Roman.Pach@de.bosch.com>:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* AW: define-syntax
2008-12-09 20:20 ` define-syntax Neil Jerram
@ 2008-12-09 20:52 ` Pach Roman (DGS-EC/ESG3)
2008-12-09 21:17 ` define-syntax Neil Jerram
2008-12-09 22:28 ` AW: define-syntax Clinton Ebadi
0 siblings, 2 replies; 5+ messages in thread
From: Pach Roman (DGS-EC/ESG3) @ 2008-12-09 20:52 UTC (permalink / raw)
To: guile-devel
>> 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: define-syntax
2008-12-09 20:52 ` AW: define-syntax Pach Roman (DGS-EC/ESG3)
@ 2008-12-09 21:17 ` Neil Jerram
2008-12-09 22:28 ` AW: define-syntax Clinton Ebadi
1 sibling, 0 replies; 5+ messages in thread
From: Neil Jerram @ 2008-12-09 21:17 UTC (permalink / raw)
To: Pach Roman (DGS-EC/ESG3); +Cc: guile-devel
2008/12/9 Pach Roman (DGS-EC/ESG3) <Roman.Pach@de.bosch.com>:
>
> 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.
Agreed.
> I've expected both of the be computed during the reading of scheme
> source.
That's not what define-syntax is supposed to do, as I understand it.
If you think we've got this wrong, can you point to something specific
in R5RS?
Regards,
Neil
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: AW: define-syntax
2008-12-09 20:52 ` AW: define-syntax Pach Roman (DGS-EC/ESG3)
2008-12-09 21:17 ` define-syntax Neil Jerram
@ 2008-12-09 22:28 ` Clinton Ebadi
1 sibling, 0 replies; 5+ messages in thread
From: Clinton Ebadi @ 2008-12-09 22:28 UTC (permalink / raw)
To: Pach Roman (DGS-EC/ESG3); +Cc: guile-devel
"Pach Roman (DGS-EC/ESG3)" <Roman.Pach@de.bosch.com> writes:
>>> test 2:
>>> -------
>>> (define-macro (my-macro-2 par1 par2 par3)
>>> (string-concatenate (list par1 par2 par3)))
A macro defined with define-macro is merely a function that is run at
macroexpansion time and is expected to return a new form for the
compiler. The body of the macro can perform arbitrary computation, and
your macro is actually calling string-concatenate at macroexpansion time
rather than returning the form as you expected.
(define-macro (my-macro-2 par1 par2 par3)
`(string-concatenate (list ,par1 ,par2, par3)))
Will do what you expect.
--
How can you accept social supression
This weak state of mind in our time
I demand release from hypocrisy
I'd rather die than be held down, forced down
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-12-09 22:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-09 16:51 define-syntax Pach Roman (DGS-EC/ESG3)
2008-12-09 20:20 ` define-syntax Neil Jerram
2008-12-09 20:52 ` AW: define-syntax Pach Roman (DGS-EC/ESG3)
2008-12-09 21:17 ` define-syntax Neil Jerram
2008-12-09 22:28 ` AW: define-syntax Clinton Ebadi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).