I want the following code to work:
(define fn.str "(lambda (x) (displayln x)")
(define fn.callable (string->lambda fn.str))
; and then 2 next lines should be valid
(fn.callable 123)
(apply fn.callable '(321))
But best I can get is to eval string and get output, instead my target is to get the actual holding value (λ in this case).
In general, this is also desired effect:
(define val.num "500")
(define val.li "'(1 2 3)")
(define val.fn "(λ (a) a)")
(define num (string->value val.num)) ; => num is now holding 500
(define li (string->value val.li)) ; => list '(1 2 3)
(define fn (string->value val.fn)) ; => callable lambda
Maybe I came close enough to solution, but it's got bad smell.
More info:
- Those strings came into program from outside (file/user input).
- Extracted/parsed values should be binded to something (hash table, for example) for further access.
eval. When possible it's preferable to make your own#langin Racket.