Hi Edwin,

> the way i understand it, symbols evaluate to a value. symbols also
> have properties. several questions:

Correct.


> 1) how are symbol properties implemented on the C level?

As you recall from our discussion here about two weeks ago, properties
are stored in a list of cons pairs in the symbol's tail (as shown in the
diagram in "doc/ref.html#symbol").

So the implementation of properties consists of list manipulation
operations.

A new property is a cons pair of the form (val . key), and put into the
front of the property list.

Note that - as opposed to association lists - the key is in the CDR of
the cell. This has advantages when manipulating the value, because the
CAR of a cell is a variable ('var' called in the documentation).

Searching for a property by a key goes through the list, and looks for a
CDR that is '==' (pointer equal) to the key. When a property is found,
it is moved to the front of the list, as a side effect to accelerate
further accesses (last recently used scheme).


> 2) how are symbol properties stored in the db?

The whole symbol (value and properties) is simply stored in the PLIO
format, a binary serialization format. The name of an external symbol
determines its location, at which offset into which file it resides.

The PLIO format is also used by other functions like 'pr', 'rd', 'tell',
'hear' etc. You can experiment with it also outside the database context
by writing it to a plain file:

   : (put 'A 'a 1)                     # Create some properties for 'A'
   -> 1
   : (put 'A 'b 2)
   -> 2
   : (put 'A 'c 3)
   -> 3

   : (getl 'A)                         # See the property list
   -> ((3 . c) (2 . b) (1 . a))

   : (out 'a (pr (getl 'A)))           # Print property list to file "a"
   -> ((3 . c) (2 . b) (1 . a))

   : (hd 'a)                           # Hexdump of the PLIO representation
   00000000  01 01 04 06 02 05 63 01 04 04 02 05 62 01 04 02  ......c.....b...
   00000010  02 05 61 03                                      ..a.
   -> NIL

Does this help?

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[email protected]?subject=unsubscribe

Reply via email to