[plt-scheme] Macros and define-package

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Sun Dec 7 18:35:46 EST 2008

I was playing around with the scheme/package from
todays svn-build. Is it possible to modify
define-Zn below, so that open-package can
recognize the identifer later on?

/Jens Axel Søgaard


#lang scheme

(require scheme/package
         (prefix-in mz: scheme))

#;(define-package Z5 (+ *)
  (define (+ a b) (modulo (mz:+ a b) 5))
  (define (* a b) (modulo (mz:* a b) 5)))

(define-syntax (define-Zn stx)
  (syntax-case stx ()
    [(_ pkg-id n-expr)
     #`(let ([n n-expr])
         (define-package pkg-id (+ *)
           (define (+ a b) (modulo (mz:+ a b) n))
           (define (* a b) (modulo (mz:* a b) n)))
         (void))]))

(define-Zn Z5 5)

(+ 5 2)

(let ()
  (open-package Z5) ; open-package: identifier is not bound to a package 
in: Z5
  (+ 5 2))

(+ 5 2)



Posted on the users mailing list.