<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Oh sorry I meant this for parse-meds:</div><div><div><font face="Courier New">(define (parse-meds lst)</font></div><div><font face="Courier New"> (match lst</font></div><div><font face="Courier New"> [(list) ""]</font></div><div><font face="Courier New"> [(list-rest MED QUANT FORM POS (? inst? INST) rest)</font></div><div><font face="Courier New"> (~a MED " " line " " QUANT " " FORM "\n" POS "\n" INST "\n" (parse-meds rest))]</font></div><div><font face="Courier New"> [(list-rest MED QUANT FORM POS rest)</font></div><div><font face="Courier New"> (~a MED " " line " " QUANT " " FORM "\n" POS "\n" (parse-meds rest))]))</font></div></div><div><br></div><div><div>On Aug 4, 2014, at 2:09 PM, Alexander D. Knauth <<a href="mailto:alexander@knauth.org">alexander@knauth.org</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Then would something like this work?</div><div><div><font face="Courier New">#lang racket</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(provide (all-defined-out)</font></div><div><font face="Courier New"> #%datum #%top</font></div><div><font face="Courier New"> (rename-out [new-module-begin #%module-begin]))</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define-syntax-rule</font></div><div><font face="Courier New"> (new-module-begin med-thing ...)</font></div><div><font face="Courier New"> (#%module-begin (displayln (parse-meds (list med-thing ...)))))</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define (parse-meds</font><span style="font-family: 'Courier New';"> lst)</span></div><div><font face="Courier New"> (match lst</font></div><div><font face="Courier New"> [(list) ""]</font></div><div><font face="Courier New"> [(list-rest MED QUANT FORM POS (? inst? INST) rest)</font></div><div><font face="Courier New"> (~a MED " " line " " QUANT " " FORM "\n" POS "\n" INST "\n" (parse rest))]</font></div></div></div></blockquote><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><div><font face="Courier New"> [(list-rest MED QUANT FORM POS rest)</font></div><div><font face="Courier New"> (~a MED " " line " " QUANT " " FORM "\n" POS "\n" (parse rest))]))</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define hctz25 "Hydrochlorothiazide 25mg")</font></div><div><font face="Courier New">(define simva20 "Simvastatin 20mg")</font></div><div><font face="Courier New">(define pl "pills")</font></div><div><font face="Courier New">(define 1xd "Take 1 pill P.O. 1x/day")</font></div><div><font face="Courier New">(define 1xn "Take 1 pill P.O. 1x at night")</font></div><div><font face="Courier New">(define INSTOMZ "half an hour before breakfast, with a glass of water")</font></div><div><font face="Courier New">(define line "-----------")</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define (inst? x)</font></div><div><font face="Courier New"> (equal? x INSTOMZ))</font></div></div><div><br></div><br><div><div>On Aug 4, 2014, at 1:22 AM, Henry Lenzi <<a href="mailto:henry.lenzi@gmail.com">henry.lenzi@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hello Alex --<br><br>This is nice, the problem is separating the output into the proper<br>formatting. I feel this has to be done a step before the expansion<br>into the string form.<br>One thing I'm considering is that that the DSL is made of MED QUANT<br>FORM POS or MED QUANT FOR POS INST, so 4 or 5 items.<br>If we have a symbol list (before string expansion), than we can treat<br>INST as the divider marker. Otherwise, there's a linebreak at every<br>fourth item.<br><br>I'm looking into how to to this using a position function:<br> (define (position item list)<br> (- (length list)<br> (length (member item list))))<br><br>Knowing where the INST instructions occur help up decided whether we<br>can break a line into the<br>MED QUANT FORM<br> POS<br>or<br>MED QUANT FORM<br> POS<br> INST<br><br>forms (see the code snippet on <a href="http://pasterack.org/pastes/14535">http://pasterack.org/pastes/14535</a> )<br><br><br>Cheers,<br><br>Henry<br><br>On Mon, Aug 4, 2014 at 1:23 AM, Alexander D. Knauth<br><<a href="mailto:alexander@knauth.org">alexander@knauth.org</a>> wrote:<br><blockquote type="cite">Would this work for what you want?<br><br>If med.rkt contains this:<br>#lang racket<br><br>(provide (all-defined-out)<br> #%datum #%top<br> (rename-out [new-module-begin #%module-begin]))<br><br>(define-syntax-rule<br> (new-module-begin med-thing ...)<br> (#%module-begin (display (~a med-thing ... #:separator " "))))<br><br>(define hctz25 "Hydrochlorothiazide 25mg")<br>(define simva20 "Simvastatin 20mg")<br>(define pl "pills")<br>(define 1xd "Take 1 pill P.O. 1x/day")<br>(define 1xn "Take 1 pill P.O. 1x at night")<br>(define INSTOMZ "half an hour before breakfast, with a glass of water")<br>(define line "-----------")<br><br>And try-it.rkt contains this:<br>#lang s-exp "med.rkt"<br>hctz25 30 pl 1xd<br>simva20 30 pl 1xn<br><br>Then running try-it.rkt will produce the output:<br>Hydrochlorothiazide 25mg 30 pills Take 1 pill P.O. 1x/day Simvastatin 20mg<br>30 pills Take 1 pill P.O. 1x at night<br><br>Or if new-module-begin is defined like this instead:<br>(define-syntax-rule<br> (new-module-begin med-thing ...)<br> (#%module-begin (provide data) (define data (~a med-thing ... #:separator<br>" "))))<br><br>Then doing (require “try-it.rkt”) will import data as the string<br>"Hydrochlorothiazide 25mg 30 pills Take 1 pill P.O. 1x/day Simvastatin 20mg<br>30 pills Take 1 pill P.O. 1x at night".<br><br><br><br></blockquote></blockquote></div><br></div>____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>