[racket] Question about string->symbol

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Thu Mar 10 18:43:11 EST 2011

Symbols are values (just like strings, numbers, etc). Identifiers are
not values, but thigns that can be bound to values. The request below
combines the two, as if they were the same thing.

While it is possible to do things that approximate what you want, most
programming problems can be solved without them (and they often bring
in complexity that you don't really want to deal with).

How about using a hash table instead? You can say:

(define my-hash (make-hash))

and then when you would have written

  (set! number3 3)

you isntead write

  (hash-set! 'number3 3)

and this will also work:

  (hash-set! (string->symbol (format "number~a" 3)) 3)

And when you would have said


to get the current value bound to that identifier, you instead say:

  (hash-ref my-hash 'number3)


On Thu, Mar 10, 2011 at 5:28 PM, Brian Moriarty <prof at ludix.com> wrote:
> Hello! I'm new to Scheme/Racket, and have a quick question.
> Is there any way to assign an arbitrary value to a symbol created with
> string->symbol?
> I want to do the equivalent of  (set! (string-symbol "number3") 3).
> That is, I want the symbol number3 to evaluate to 3.
> Thanks in advance for advice!
> - prof
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Posted on the users mailing list.