unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* define-syntax
@ 2010-06-15 20:48 Ludovic Courtès
  2010-06-15 22:06 ` define-syntax Andy Wingo
  2010-06-16  7:35 ` define-syntax Marco Maggi
  0 siblings, 2 replies; 9+ messages in thread
From: Ludovic Courtès @ 2010-06-15 20:48 UTC (permalink / raw)
  To: guile-devel

Hello,

From R6RS Section 10:

  define-syntax form  The expander expands and evaluates the
    right-hand-side expression and binds the keyword to the resulting
    transformer.

Thus I think the following should work:

  (define-syntax +
    (let ((plus +))  ;; `+' should resolve to whatever `+' is bound to
                     ;; before this definition
      (lambda (stx)
        (syntax-case stx ()
          ((_ args ...)
           (apply plus (map syntax->datum #'(args ...))))))))

But it fails when expanding the macro:

  scheme@(guile-user)> (+ 2 3)
  Throw to key `wrong-type-arg':
  ERROR: In procedure vm-debug-engine:
  ERROR: Wrong type to apply: #<syntax-transformer +>

Thoughts?

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 9+ messages in thread
* 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; 9+ 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] 9+ messages in thread

end of thread, other threads:[~2010-06-18 14:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-15 20:48 define-syntax Ludovic Courtès
2010-06-15 22:06 ` define-syntax Andy Wingo
2010-06-15 22:38   ` define-syntax Ludovic Courtès
2010-06-16  7:35 ` define-syntax Marco Maggi
2010-06-18  8:39   ` define-syntax Andy Wingo
2010-06-18 14:41     ` define-syntax Marco Maggi
  -- strict thread matches above, loose matches on Subject: below --
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

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).