Hi Jens Axel
 
Thanks very much. That works perfectly.
I already guessed that I was confusing contexts, but did not realize how
simply with-syntax and datum->syntax can solve this problem.
Stupid me, for I have used with-syntax and datum->syntax before.
Syntax-case and its helpers (like with-syntax, datum->syntax, quasi-syntax
and so on) are great!
 
Thanks again, Jos Koot

  _____  

From: jensaxelsoega...@gmail.com [mailto:jensaxelsoega...@gmail.com] On
Behalf Of Jens Axel Søgaard
Sent: jueves, 16 de abril de 2015 17:13
To: Jos Koot
Cc: racket-users@googlegroups.com
Subject: Re: [racket-users] literals within syntax-transfromer within
syntax-transformer


The literals in the syntax-case expression needs to have the same context 
as the identifiers used in the expressions where try is used.

#lang racket

(require (for-syntax racket))

(define-syntax (try stx)
  (define-syntax (stx-case stx)
    (syntax-case stx ()
      ((_ stx-expr clause ...) 
       (with-syntax ([+ (datum->syntax stx '+)]
                     [- (datum->syntax stx '-)])
       #'(syntax-case stx-expr (+ -) clause ...)))))
  (stx-case stx
            ((_ +) #''plus)
            ((_ -) #''minus)
            ((_ x) #''x)))

(try +) 
(try -) 
(try a) 
 

2015-04-16 16:35 GMT+02:00 Jos Koot <jos.k...@gmail.com>:



Probably I am mixing literal identifiers from distinct expansion phases.
Nevertheless, I don't understand the behaviour of the program below.
Explanation would be very welcome.
I have looked into the expanded code with the macro stepper,
but I could not find any code looking for the literals.
 
#lang racket
 
(require (for-syntax racket))
 
(define-syntax (try stx)
 (define-syntax (stx-case stx)
  (syntax-case stx ()
   ((_ stx-expr clause ...) #'(syntax-case stx-expr (+ -) clause ...))))
 (stx-case stx
  ((_ +) #''plus)
  ((_ -) #''minus)
  ((_ x) #''x)))
 
(try +) ; -> plus; as expected
(try -) ; -> plus; expected -
(try a) ; -> plus; expected a
 
I did this in the definitions window of DrRacket, version 6.1.1 [3m].
Language: racket [custom]; memory limit: 2000 MB.
 
Thanks, Jos Koot


-- 
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.





-- 

-- 
Jens Axel Søgaard


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to