ShenDoc 30


 

 

Property Vectors and Hashing

Like Qi, Shen includes property lists. However they are not implemented using CL property lists, but instead rely on a hashing function into a standard vector *property-vector* which is internal to the Shen package and by default set to hold 20,000 elements.

The expression '(put Mark sex male)' creates a pointer 'sex' from 'Mark' to the object 'male'. The expression '(get Mark sex)' retrieves 'male'. If no pointer exists from the object then get returns an error.

The functions 'put' and 'get' index into the vector by converting their first argument A into a number via the hashing function (see below). This hashing function h may be a many-one function, hence *property-vector* is a vector of lists and a list search is used at position (h A) in V to locate the correct value. This function is subject to any improvements and changes that are consistent with the language specification (see optimising the system functions in the document on porting).

In Qi, 'get-prop' was a 3-place function (get-prop X P Y) where the third argument was returned if no pointer P existed from X. In Shen, if no pointer exists then an error is returned. Using exception handling, assuming X and P are well-defined, 'get-prop' is easily defined in Shen.

(get-prop X P Y) = (trap-error (get X P) (/. E Y))

Unline CL, arguments to 'get' and 'put' can be objects of any type provided their constituents are representable within the default string set. If the hash value (h A) of the argument A exceeds the limit of the property list vector, the modulus M of (h A) to the size of the vector is taken and the data is placed in the Mth address of the vector.

'put' and 'get' are actually polyadic functions which appear as such by the grace of the Shen reader. There is an optional final argument which should be a standard vector; thus '(put Mark sex male (value *myvector*))' will use the vector *myvector* as the hashing table. If the optional argument is missing then *property-vector* is used.

In version 17 'unput' was introduced which cancels the effect of put. '(unput Mark sex)' will remove the pointer. Again this function allows for an optional vector argument which defaults unless specified otherwise to the property vector.

The hash function 'hash' takes as arguments a Shen object X and a positive number N (which need not be whole) and returns a number M between zero and N, where M represents the hash value of X within that interval.

Acknowledgements

History
Basic Types in Shen and Kλ
The Primitive Functions of Kλ
The Syntax of Kλ
Notes on the Implementation of Kλ
Boolean Operators
The Syntax of Symbols
The Semantics of Symbols in Shen and Kλ
Packages
Prolog
Shen-YACC
Strings
Strings and Pattern Matching
Lists
Streams
Character Streams and Byte Streams
Bytes and Unicode
Reader Macros
Vectors
Standard Vectors and Pattern Matching
Non-standard Vectors and Tuples
Equality
I/O
Generic Functions
Eval
Type Declarations
External Global Variables
Property Lists and Hashing
Error Handling
Numbers
Floats and Integers
The Timer
Comments
Special Forms

Built by Shen Technology (c) Mark Tarver, September 2021