[racket] have built a symbol, now need the value of the id represented by the symbol
Thanks, Laurent. That sounds like a much better idea! --Geoffrey
On Feb 18, 2014, at 17:09 , Laurent <laurent.orseau at gmail.com> wrote:
> Could you use a dictionary (e.g., hash table) instead of `define`s by any chance? Then you would not need `eval` but only `dict-ref`, which is way less problematic.
>
> Laurent
>
>
> On Tue, Feb 18, 2014 at 9:54 PM, Geoffrey S. Knauth <geoff at knauth.org> wrote:
> Our local community has a funky tax form not handled by the big tax prep vendors. So I rolled my own with Racket. It outputs LaTeX so I have something to submit all ready.
>
> Well it would, except I have goofed something up. I'm eval'ing a symbol (probably incorrect). The symbol comes not from the top-level, but from a module. I'm forming a symbol 'line1-gsk. I want the value of the identifier represented by that symbol. How do I do that? (If my son were back from school, I'd ask him...)
>
> Geoff
>
> line1-gsk: undefined;
> cannot reference undefined identifier
> context...:
> /Users/gknauth/me/2014/taxes/TY2013/ipt-latex.rkt:50:2: for-loop
> /Users/gknauth/me/2014/taxes/TY2013/ipt-latex.rkt:49:0: pr-table-rows
> /Users/gknauth/me/2014/taxes/TY2013/ipt-latex.rkt:35:0: pr-table
> /Users/gknauth/me/2014/taxes/TY2013/ipt-hdr-gsk.rkt: [running body]
>
> ipt-data.rkt:
> (provide (all-defined-out))
> (define line1-gsk (round (+ 111 222 333)))
> ; I want this value, line1-gsk, to be picked up in pr-table-row below
>
> ipt-latex.rkt:
> (require (lib "48.ss" "srfi"))
> (require "ipt-data.rkt")
> (provide (all-defined-out))
> ...
> (define (pr-table-row lineno whoisa whoisb) ; whoisa is "gsk" (me), whoisb is my spouse
> (let* ((base-str (string-append "line" (number->string lineno) "-"))
> ;;;;;; ERROR FIRST HAPPENS HERE ;;;;;;
> (amt-a (eval (string->symbol (string-append base-str whoisa))))
> ;;;;;; (eval 'line1-gsk) ;;;;;;
> (amt-b (eval (string->symbol (string-append base-str whoisb))))
> (what (eval (string->symbol (string-append base-str "what"))))
> (desc (eval (string->symbol (string-append base-str "desc")))))
> (printf
> (string-append
> (number->string lineno) "&"
> what "&"
>
> (number->string lineno) "&"
> "\\texttt{" (format "~9,2F" amt-a) "}&"
> "\\texttt{" (format "~9,2F" amt-b) "}"
> (if desc
> (string-append "\\\\&{\\small " desc "}&&&")
> "")
> "\\\\\\hline\n"))))
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
>