[racket] Use of map and eval to evaluate symbol in namespace
Oh sorry I meant this for parse-meds:
(define (parse-meds lst)
(match lst
[(list) ""]
[(list-rest MED QUANT FORM POS (? inst? INST) rest)
(~a MED " " line " " QUANT " " FORM "\n" POS "\n" INST "\n" (parse-meds rest))]
[(list-rest MED QUANT FORM POS rest)
(~a MED " " line " " QUANT " " FORM "\n" POS "\n" (parse-meds rest))]))
On Aug 4, 2014, at 2:09 PM, Alexander D. Knauth <alexander at knauth.org> wrote:
> Then would something like this work?
> #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 (displayln (parse-meds (list med-thing ...)))))
>
> (define (parse-meds lst)
> (match lst
> [(list) ""]
> [(list-rest MED QUANT FORM POS (? inst? INST) rest)
> (~a MED " " line " " QUANT " " FORM "\n" POS "\n" INST "\n" (parse rest))]
> [(list-rest MED QUANT FORM POS rest)
> (~a MED " " line " " QUANT " " FORM "\n" POS "\n" (parse rest))]))
>
> (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 "-----------")
>
> (define (inst? x)
> (equal? x INSTOMZ))
>
>
> On Aug 4, 2014, at 1:22 AM, Henry Lenzi <henry.lenzi at gmail.com> wrote:
>
>> 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".
>>>
>>>
>>>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140804/ac4b1212/attachment.html>