Hello,

I am looking for some way to expand syntax (that is, without evaluation, 
just syntax -> syntax transform) during another macro expansion (main-test.rkt 
in the following example) using the foreign module namespace (need to use 
prog and simple-act transformation rules from foreign modules).
I've managed to do the syntax expansion and evaluation with the desired 
namespace, but have a hard time with expansion only.

*Expansion and evaluation sample (working):*

------------main-test.rkt------------
#lang racket
(require (for-syntax racket/base syntax/parse racket/syntax)
         (for-syntax "foreign.rkt"))

(define-syntax (prog stx)
  (syntax-parse stx
    [(_ body ...)
     (let ((x
            (parameterize
                  ([current-namespace (module->namespace "foreign.rkt")])
                (eval stx))))
      #'(begin body ...))
     ]))

(define-syntax (simple-act stx)
  (syntax-parse stx
    [(_ str)
     #'(writeln str)
     ]))

(prog
 (simple-act "foo")
 (simple-act "bar"))
---------------------------------------
------------foreign.rkt----------------
#lang racket
(require (for-syntax racket/base syntax/parse racket/syntax))

(define-syntax (prog stx)
  (syntax-parse stx
    [(_ body ...)
      #'(begin body ...)
     ]))

(define-syntax (simple-act stx)
  (syntax-parse stx
    [(_ str)
     #'(writeln (format "foreign expansion: ~a" str))
     ]))
---------------------------------------

*Separate expansion (not working)*
*I have tried to do something like that:*

------------main-test.rkt--------------
#lang racket
(require (for-syntax racket/base syntax/parse racket/syntax)
         (for-syntax "foreign-0.rkt")
         (for-syntax "foreign-1.rkt"))

(define-syntax (prog stx)
  (syntax-parse stx
    [(_ body ...)
     (let* ((expanded-by-foreign
             (parameterize
                  ([current-namespace (module->namespace "foreign-0.rkt")])
                (expand-syntax stx)))* ;; Expect it to expand macros in 
foreign-0.rkt, resuling syntax object is expanded later*
            (result-of-evaluation
             (parameterize
                 ([current-namespace (module->namespace "foreign-1.rkt")])
               (eval expanded-by-foreign)))) *;; It should expand with 
foreign-1.rkt macros and evaluate expanded code*
      #'(begin body ...))
     ]))

(define-syntax (simple-act stx)
  (syntax-parse stx
    [(_ str)
     #'(writeln str)
     ]))

(prog
 (simple-act "foo")
 (simple-act "bar"))
-----------------------------------------
------------foreign-0.rkt----------------
#lang racket
(require (for-syntax racket/base syntax/parse racket/syntax))

(define-syntax (prog stx)
  (syntax-parse stx
    [(_ body ...)
      #'(prog-0 body ...)
     ]))

(define-syntax (simple-act stx)
  (syntax-parse stx
    [(_ str)
     #'(simple-act-0 str)
     ]))
-----------------------------------------
------------foreign-1.rkt----------------
#lang racket
(require (for-syntax racket/base syntax/parse racket/syntax))

(define-syntax (prog-0 stx)
  (syntax-parse stx
    [(_ body ...)
      #'(begin body ...)
     ]))

(define-syntax (simple-act-0 stx)
  (syntax-parse stx
    [(_ str)
     #'(writeln (format "foreign-0 evaluation: ~v" str))
     ]))
-----------------------------------------

Got an error: ../../../../../Applications/Racket 
v7.1/collects/syntax/wrap-modbeg.rkt:46:4: prog: undefined;
 cannot reference an identifier before its definition

I've tried to use a `local-expand` instead of `expand-syntax`, but 
compilation is running out the memory then (looks like the infinite loop 
while compilation, but I do not understand how to prevent it).

Best regards, 
Ivan

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