<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:arial,sans-serif;font-size:13px">Thanks, Vincent. But a recipe is more than those simple definitions.<br>
</span><span style="font-family:arial,sans-serif;font-size:13px">Actually, it would be something like:</span></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">MEDICATION DOSE UNITS ----------------- QUANTITY FORM</span><br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px"> INSTRUCTIONS FOR TAKING MEDICATION</span> </blockquote><div><br></div>The module idea would still work. You can define your definitions in one file, provide them, and then require them in another file. The definitions can be as complex as you like.<div>
<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:arial,sans-serif;font-size:13px">In my previous Forth version, this was extremely easy to achieve, as<br>
</span><span style="font-family:arial,sans-serif;font-size:13px">Forth is syntax-less, and "code is data, and data is code". So the<br></span><span style="font-family:arial,sans-serif;font-size:13px">recipe turned out to be a mini language written in Forth itself.</span></blockquote>
<div><br></div><div>There doesn't seem to be any need for "code as data, data as code" here. Instead of mapping abbreviations to full names with identifiers and values, why not use keys and values with a hash-table? It removes the need for 'eval'.</div>
<div><br></div><div><div> (define meds (hash 'hctz "Hydrochlorothiazide"</div><div> 'cough-drops "Cough Drops"))</div></div><div><br></div><div><div> (define (abbreviation->full-name abbreviation)</div>
<div> (dict-ref meds abbreviation))</div></div><div><br></div><div>If the mapping is constant, you can store it in another module, provide, and require it, like Vincent explains. If your mapping is updated over time, you can save it to a file as Roman explains. Saving it to a file doesn't require text parsing. With print, read, and serialize, all the hard work is already taken care of.</div>
<div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 29, 2014 at 10:54 PM, Henry Lenzi <span dir="ltr"><<a href="mailto:henry.lenzi@gmail.com" target="_blank">henry.lenzi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks, Vincent. But a recipe is more than those simple definitions.<br>
Actually, it would be something like:<br>
<br>
<br>
MEDICATION DOSE UNITS ----------------- QUANTITY FORM<br>
<br>
INSTRUCTIONS FOR TAKING MEDICATION<br>
<br>
In my previous Forth version, this was extremely easy to achieve, as<br>
Forth is syntax-less, and "code is data, and data is code". So the<br>
recipe turned out to be a mini language written in Forth itself.<br>
<br>
These seems to be harder in Scheme... Some here seem to shun code/data<br>
("don't use eval") in favor of what would amount ultimately to<br>
string-based methods, as far as I understand it.<br>
<span class="HOEnZb"><font color="#888888"><br>
- Henry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
<br>
On Mon, Jul 28, 2014 at 6:03 PM, Vincent St-Amour <<a href="mailto:stamourv@ccs.neu.edu">stamourv@ccs.neu.edu</a>> wrote:<br>
> Henry,<br>
><br>
> It looks like modules may be what you're looking for.<br>
><br>
> You could have a file that defines a substance and exports it<br>
><br>
> ;; a.rkt<br>
> #lang racket<br>
> (provide hctz25)<br>
> (define hctz25 "Hydrochlorothiazide 25mg")<br>
><br>
> and then a recipe file that imports the previous file<br>
><br>
> #lang racket<br>
> (require "a.rkt")<br>
> hctz25<br>
><br>
> The module system is the preferred way to share definitions across<br>
> multiple files in Racket.<br>
><br>
> Would that solve your problem?<br>
><br>
> Vincent<br>
><br>
><br>
> At Mon, 28 Jul 2014 17:21:40 -0300,<br>
> Henry Lenzi wrote:<br>
>><br>
>> Hi Neil --<br>
>><br>
>> So how do you export hash keys as symbols to a file that can be read<br>
>> in again, not as string?<br>
>><br>
>> Now, I haven't gotten around to reading the whole of Racket Scheme's<br>
>> documentation... Things are looking kind of hard.<br>
>><br>
>> What I'm attempting to do is then read back the symbols defined, such<br>
>> as the one below:<br>
>><br>
>> (define hctz25 "Hydrochlorothiazide 25mg")<br>
>><br>
>> > (close-input-port in)<br>
>> > (define in (open-input-file "Recipe.txt"))<br>
>> > (string->symbol (read-line in))<br>
>> '|'hctz25|<br>
>><br>
>> But what I really want is the "hctz25" symbol that evaluates to a<br>
>> string. If I don't use string->symbol, I get the string "hctz25". And<br>
>> why the bars ("|")? I've read<br>
>><br>
>> <a href="http://docs.racket-lang.org/reference/reader.html#%28part._parse-hashtable%29" target="_blank">http://docs.racket-lang.org/reference/reader.html#%28part._parse-hashtable%29</a><br>
>><br>
>> but it didn't help me much.<br>
>><br>
>> Of course, the ultimate purpose would be to re-evaluate the imported<br>
>> symbol and reconstruct a medical recipe. The purpose of these<br>
>> baby-steps exercises is porting a medical recipe program I've written<br>
>> originally in Forth that allowed me to service 5.000 patients creating<br>
>> a little database of shorthand recipes that then expand into real<br>
>> medical recipes. I got hundreds of patients on renewable recipes for,<br>
>> say, hypertension. Hand writing is no fun. Typing them in Word is no<br>
>> fun. The hospital has is its own software, but it's is a load of<br>
>> baloney, extremely buggy, if you ask me, so I'm rolling my own again,<br>
>> except I want to print directly on the model paper our service uses,<br>
>> so I want graphics like Racket Scheme has (very good capabilities, as<br>
>> far as my needs are concerned).<br>
>><br>
>> With Forth, it's very easy to design DSLs, because there's no syntax<br>
>> and you get a lot of advanced features for free. For instance, there's<br>
>> no need to write a parser for my little language. However, since Forth<br>
>> implementations fall short of dealing with images, graphics (unless<br>
>> you take the royal road to pain and learn to program for the Win32 API<br>
>> and how it works for a particular Forth vendor), I'm looking at Racket<br>
>> Scheme.<br>
>><br>
>> TIA,<br>
>><br>
>> Henry Lenzi<br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>> On Mon, Jul 28, 2014 at 4:46 PM, Neil Van Dyke <<a href="mailto:neil@neilvandyke.org">neil@neilvandyke.org</a>> wrote:<br>
>> > I don't know the current state of the "eval" docs in the manual, but I think<br>
>> > they should have a big warning at the very front, intended to scare away<br>
>> > newbies.<br>
>> ><br>
>> > Remember that Racket is often used in conjunction with many different<br>
>> > Scheme-based and other Lisp-based textbooks and courses. It seems that many<br>
>> > CS instructors and textbook authors like to talk about ``EVAL'' (as an<br>
>> > abstract operation) when talking about some models of evaluation, and "eval"<br>
>> > (as an accessible language binding) to say, gosh, aren't dynamic languages<br>
>> > interesting and powerful. So, we can't blame every fourth newbie for trying<br>
>> > to use "eval" unnecessarily, in ways that make for bad software engineering.<br>
>> ><br>
>> > Given this reality of confusing instruction, I'm thinking that, as a<br>
>> > reactive measure, "#lang paddle" will disable "eval" by default. Attempting<br>
>> > to use "eval" will give you an error message, unless you have an assertion<br>
>> > form like<br>
>> > "(i-have-read-the-foo-document-and-understand-that-eval-is-usually-the-wrong-thing-but-honest-i-know-what-i-am-doing)".<br>
>> ><br>
>> > Cheers,<br>
>> > Neil V.<br>
>> ><br>
>> > Vincent St-Amour wrote at 07/28/2014 02:21 PM:<br>
>> ><br>
>> >> Maybe this should be linked to from the `eval' docs?<br>
>> >><br>
>> >><br>
>> >> <a href="http://blog.racket-lang.org/2011/10/on-eval-in-dynamic-languages-generally.html" target="_blank">http://blog.racket-lang.org/2011/10/on-eval-in-dynamic-languages-generally.html</a><br>
>> >><br>
>> >> Vincent<br>
>> >><br>
>> >><br>
>> >> At Sun, 27 Jul 2014 16:16:52 -0400,<br>
>> >> Neil Van Dyke wrote:<br>
>> >>><br>
>> >>> Maybe there should be a periodic public service announcement about not<br>
>> >>> using "eval". This time I will communicate in FAQ format:<br>
>> >>><br>
>> >>> Q: How do I use eval?<br>
>> >>> A: Don't use eval.<br>
>> >>><br>
>> >>> Q: But don't so many academic books feature eval prominently, so doesn't<br>
>> >>> that mean I should use try to eval?<br>
>> >>> A: Those books use eval for pedagogic reasons, or because the author is<br>
>> >>> enamored of some theoretical appeal of eval, or because the author wants<br>
>> >>> to watch the world burn. Don't use eval.<br>
>> >>><br>
>> >>> Q: But, but, but, I am just starting to learn, and eval seems to do what<br>
>> >>> I need.<br>
>> >>> A: Eval is almost certainly not what you want. Learn how to use the<br>
>> >>> other basics effectively. Don't use eval.<br>
>> >>><br>
>> >>> Q: I now am very comfortable with the language, I am aware that I should<br>
>> >>> avoid eval in almost all cases, and I can tell you why eval is actually<br>
>> >>> the right thing in this highly unusual case.<br>
>> >>> A: Cool, that's why eval is there.<br>
>> >>><br>
>> >>> Neil V.<br>
>> >>><br>
>> ><br>
>> > ____________________<br>
>> > Racket Users list:<br>
>> > <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>> ____________________<br>
>> Racket Users list:<br>
>> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>