[plt-scheme] setting a var whose name is det'ed at runtime (newb)
> (set! (get-name) (car some-list)) returns "set!: not an identifier in:
> (get-name)". I think this behavior is required by lexical scoping, in
> which case, How do we set a variable whose name is dynamically
> determined? thanks
Are you familiar with hash tables? They go by different names
(dictionaries, maps, associative lists). This data structure provides a
container to associate a key to a value: the key can be calculated at
runtime to get (or set) the corresponding value.
For example:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (define classes (make-hash-table 'equal))
> (hash-table-put! classes "cs525f" "security")
> (hash-table-get classes "cs525f")
"security"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
For more information on hash tables, see:
http://download.plt-scheme.org/doc/360/html/mzscheme/mzscheme-Z-H-3.html#node_sec_3.14