DATA.txt 1.1 KB

123456789101112131415
  1. == How are scheme values represented in C? ==
  2. There are simple "immediate" data types like booleans and numbers. They are self contained and can be built like this:
  3. #define SDBOOL(t) (sdata){.tag = tbool, .value = t}
  4. #define SDNUMB(t) (sdata){.tag = tnumb, .ivalue = t}
  5. Then there are symbols which are sort of like a mid-way between immediate and complex data that requires allocation. We "intern" symbol names into a symbol table. That enables us to reference a long complicated symbol name just using one integer.
  6. You might intern("x"), intern("y") then {.tag = tsymb, .value = 0} would represent 'x and {.tag = tsymb, .value = 1} would represent 'y.
  7. A similar but a more general structure is the heap which is just scratch space for any number of data. When we allocate a cons cell we ask for 2 spaces in the heap. For example we might end up with {.tag = tcons, .value = 325} which means that the car is at place 325 and the cdr is at place 326 of the heap.
  8. Vectors work in a similar way but they reserve 1 + length slots in the heap, first to store their length then to store their elements.