<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>The REPL automatically uses the current namespace, which is why you can casually use eval there without specifying a namespace. [1]</div><div><br></div><div>But if you're using eval in the definitions window, you need to give it a namespace, otherwise you'll get "unbound identifier" errors.</div><div><br></div><div>In this case, the namespace you want is the one you're already in. So rather than using (make-base-namespace), which will give you an new namespace [2], you need a namespace anchor. To make an anchor, put this in your definitions:</div><div><br></div><div></div><blockquote type="cite"><div>(define-namespace-anchor a)</div></blockquote><div><br></div><div>And then to use the anchor, change your `map` to this:</div><div><br></div><div></div><blockquote type="cite"><div>(map (λ(str) (eval str (namespace-anchor->namespace a))) </div><div>    '((eval *med-name*) line *quant-str* pl) )</div></blockquote><div><br></div><div>And it works.</div><div><br></div><div>PS I assume you have a reason for preferring eval to, say, a hash.</div><div><br></div><div><br></div><div>[1] <a href="http://docs.racket-lang.org/guide/eval.html?q=namespaces#(part._namespaces)">http://docs.racket-lang.org/guide/eval.html?q=namespaces#%28part._namespaces%29</a></div><div><br></div><div>[2] <a href="http://docs.racket-lang.org/reference/Namespaces.html?q=make-base-namespace&q=namespaces#(def._((lib._racket/private/base..rkt)._make-base-namespace))">http://docs.racket-lang.org/reference/Namespaces.html?q=make-base-namespace&q=namespaces#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._make-base-namespace%29%29</a></div><div><br></div><div><br></div><br><div><div>On Jul 26, 2014, at 8:10 PM, Henry Lenzi <<a href="mailto:henry.lenzi@gmail.com">henry.lenzi@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">#lang racket<br><br>#|<br><br>Dear Racketeers -<br><br>I would like to create a little function<br>that would write a line of a medical recipe.<br><br>I would pass to "read" a shorthand form,<br>and the program would expand the text. Like so:<br><br>When I answer "hctz25" and "30", it would print:<br>"Hydrochlorothiazide 25mg ----------- 30 pills".<br><br>But I'm facing problems related to:<br> - use of "map" with "eval" in the definition area (namespace issues...)<br>See below.<br>|#<br><br><br>(require scheme/base) ; Is this necessary?<br>(define this-namespace (make-base-namespace))<br><br>(define hctz25 "Hydroclorothiazide 25mg")<br>(define  line "-----------")<br>(define pl "pills")<br><br>(define *med-name* 'NIL) ; *med-name* has global scope - this is on purpose<br>(define *med-name-str* "") ; *med-name-str* has global scope<br><br>(define (ask-med-name)<br>  (print "Medication") (newline)<br>  (set! *med-name* (read))<br>  (set! *med-name-str* (symbol->string *med-name*)))<br><br>(define *quant* 0) (define *quant-str* " ")<br><br>(define (ask-quant)<br>  (print "Quantity") (newline)<br>  (and<br>   (set! *quant* (read)) (unless (number? *quant*) (error "It's not a<br>number!")))<br>  (set! *quant-str* (number->string *quant*)))<br><br>(define (ask)<br>  (ask-med-name)<br>  (ask-quant))<br>(ask)<br><br>#|<br>Where's the problem?<br>In the REPL, I can do this:<br><br><blockquote type="cite">(map eval '((eval *med-name*) line *quant-str* pl))<br></blockquote>'("Hydrochlorothiazide 25mg" "-----------" "30" "pills")<br><br>or this:<br><br><blockquote type="cite">(string-join (map eval '((eval *med-name*) line *quant-str* pl)))<br></blockquote><br>"Hydrochlorothiazide 25mg ----------- 30 pills"<br><br><br>But, because of the namespace issues associated with "eval", I'm not<br>able to do it in the definition area.<br><br>I have no clue as to what the syntax should be.<br><br>Thanks for any help.<br><br>Henry Lenzi<br><br>|#<br>____________________<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>