[plt-scheme] question about symbol data type implementation in mzscheme

From: Kim Gybels (kgybels at vub.ac.be)
Date: Sat Nov 20 23:23:39 EST 2004


Its nice to hear that some real-world stuff is going on with scheme
instead of just academic research :)

>    This same problem must come up in the implementation of scheme
>    interpreters and compilers. I don't really know but my guess is that
>    inside mzscheme at runtime there is a single instance of a symbol like
>    "red" and that a symbol value in a list like (1 red 17) is just a pointer
>    back to this instance. To compare two symbols it is just necessary to
>    compare the pointer values. Now according to the documentation "MzScheme's
>    units are ... separately compilable and reusable components". How is a
>    symbol like "red" represented in a separately compiled unit. How is this
>    encoding mapped back to a run-time symbol value when the unit is loaded.
>    I would appreciate advice or even just an article reference that would
>    help me solve this problem in an elegant manner.

What I gathered from quickly browsing through the "Inside PLT MzScheme"
documentation (which you can find here: http://download.plt-scheme.org/doc/.
Is the following:

MzScheme doesnt store a symbol map in the native code. When a symbol
is needed, mzscheme looks if it already exists, and if so returns this
symbol, otherwise it creates a new one. I guess its just a simpel
string-pool :)

I deducted this from the following:

 Scheme_Object * scheme_intern_exact_symbol(char *name, int len) 

 Creates or finds a symbol given the symbol's length. The the case of
 name is not normalized.

 ¤ Scheme_Object * scheme_make_symbol(char *name) 

 Creates an uninterned symbol from a null-terminated string.

Note that uninterned symbol is not eq? or equal? to any other symbol.

Scheme ofcourse doesn't have the problem of syncing a symbol-map
between server and client, and so pointer comparisons are sufficient.

I hope this helps, and correct me if I am wrong :)


Posted on the users mailing list.