[racket] Use of map and eval to evaluate symbol in namespace

From: Alexander D. Knauth (alexander at knauth.org)
Date: Mon Aug 4 00:23:47 EDT 2014

Would this work for what you want?

If med.rkt contains this:
#lang racket

(provide (all-defined-out)
         #%datum #%top
         (rename-out [new-module-begin #%module-begin]))

(define-syntax-rule
  (new-module-begin med-thing ...)
  (#%module-begin (display (~a med-thing ... #:separator " "))))

(define hctz25 "Hydrochlorothiazide 25mg")
(define simva20 "Simvastatin 20mg")
(define pl "pills")
(define 1xd "Take 1 pill P.O. 1x/day")
(define 1xn "Take 1 pill P.O. 1x at night")
(define INSTOMZ "half an hour before breakfast, with a glass of water")
(define line "-----------")

And try-it.rkt contains this:
#lang s-exp "med.rkt"
hctz25 30 pl 1xd
simva20 30 pl 1xn

Then running try-it.rkt will produce the output:
Hydrochlorothiazide 25mg 30 pills Take 1 pill P.O. 1x/day Simvastatin 20mg 30 pills Take 1 pill P.O. 1x at night

Or if new-module-begin is defined like this instead:
(define-syntax-rule
  (new-module-begin med-thing ...)
  (#%module-begin (provide data) (define data (~a med-thing ... #:separator " "))))

Then doing (require “try-it.rkt”) will import data as the string "Hydrochlorothiazide 25mg 30 pills Take 1 pill P.O. 1x/day Simvastatin 20mg 30 pills Take 1 pill P.O. 1x at night".



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140804/d2f3ff4d/attachment.html>

Posted on the users mailing list.