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

From: Henry Lenzi (henry.lenzi at gmail.com)
Date: Mon Aug 4 01:22:44 EDT 2014

Hello Alex --

This is nice, the problem is separating the output into the proper
formatting. I feel this has to be done a step before the expansion
into the string form.
One thing I'm considering is that that the DSL is made of MED QUANT
FORM POS or MED QUANT FOR POS INST, so 4 or 5 items.
If we have a symbol list (before string expansion), than we can treat
INST as the divider marker. Otherwise, there's a linebreak at every
fourth item.

I'm looking into how to to this using a position function:
 (define (position item list)
    (- (length list)
       (length (member item list))))

Knowing where the INST instructions occur help up decided whether we
can break a line into the
MED QUANT FORM
 POS
or
MED QUANT FORM
 POS
 INST

forms (see the code snippet on http://pasterack.org/pastes/14535 )


Cheers,

Henry

On Mon, Aug 4, 2014 at 1:23 AM, Alexander D. Knauth
<alexander at knauth.org> wrote:
> 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".
>
>
>


Posted on the users mailing list.