Tuesday, 12 November 2013

The symbol-pointer equivalence.

Recently, I realized an interesting little fact when comparing LISP-type and C-type languages. It may seem that, by their design and philosophy, they cannot be more distant from each other, but well, it all boils down to memory locations and addresses.

Let's take the a LISP symbol a, and a C++ object obj. If you take a for itself, it resolves to its value, if you don't want that, you have to quote it. On the other side, of you take a pointer to the C++ obj, you have to dereference it directly if you want the underlying value:
  'a <=> &obj
   a <=> obj
   a <=> *obj_ptr
  'a <=> obj_ptr
I think it's cool. Think of symbols as pointers.

No comments: