scheme - Dereference variable inside list -
is possible dereference variable contained inside list, obtain value? example:
(define 1 1) (define 2 2) (define list '(one two)) (display (list-ref list 0)) here list-ref references one, , display shows one in letters. instead one dereference value contained homonym variable?
eval can solve problem... situations eval applicable, it's large , dangerous hammer.
matthew flatt's blog post on topic has become go-to explanation:
http://blog.racket-lang.org/2011/10/on-eval-in-dynamic-languages-generally.html
here's how might without eval in racket. stripping away cruft, "dict-ref" can find named element (or elements) in "association list".
#lang racket (define data '((one 1) (two 2))) (define wanted-list '(two one)) ;; evaluates '((2) (1)): (for/list ([wanted wanted-list]) (dict-ref data wanted))
Comments
Post a Comment