[racket] Internal definition context

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Jan 13 19:21:46 EST 2013

Hi All,

I'd like to change the program below s.t. the
local-expand uses an internal definition context.
Simply changing 'top-level to 'module does not work.

I have tried to use various combinations of
  - (generate-expand-context #t)
  - syntax-local-make-definition-context
  - syntax-local-bind-syntaxes	
without hitting the right incantation.

Any hints are welcome.

/Jens Axel


#lang racket
(require racket/stxparam
         racket/splicing
         (for-syntax syntax/parse
                     syntax/context))

(begin-for-syntax
  (define *types* '()))

(define-syntax (program stx)
  (syntax-parse stx
    [(_ (def ...) (expr ...))
     (let ()
       (define defs
         (local-expand #'(begin def ...)
                       'top-level
                       '()))
       (with-syntax ([defs defs])
         (displayln (list 'program *types*))
         #'(begin defs expr ...)))]))

(define-syntax (def stx)
  (syntax-parse stx
    [(_ name type expr)
     (begin
       (set! *types* (cons (cons #'name #'type) *types*))
       #'(define name expr))]))

(program
 ((def x int 42)
  (def y str "foo"))
 ((list x y)))

Posted on the users mailing list.