When you create a JSO, you can specify a prototype JSO. The recursive sequence of a JSO's prototype, the prototype of its prototype, and so on, is called the prototype chain. If a JSO doesn't contain a particular key, the prototype chain will be searched for it. Modifications, however, are only applied to the referenced JSO, never to anything along the prototype chain. An attempt to look up an unknown key returns a unique value known as the undefined value, which can be tested with jso-undef?. Note that this value is not itself a JSO.
A JSO is an ordinary Scheme association list with a special key in the first key-value pair. As long as this pair is left undisturbed, they can be searched with assq and the resulting pairs mutated with set-car! and set-cdr!. However, it is safer to use the jso-ref and jso-set! procedures instead.
- make-jso PROTOprocedure
Constructs a new JSO. If PROTO is supplied, it must be a JSO and is used as the prototype for the new object.
- jso? OBJprocedure
Returns true if OBJ is a JSO.
- jso-undef? OBJprocedure
Returns true if OBJ is the undefined value.
- jso-ref JSO KEYprocedure
Retrieves the value for KEY in JSO, or the undefined value if KEY is not found.
- jso-set! JSO KEY VALUEprocedure
Sets VALUE to be the value of KEY in JSO; the prototype chain is not searched.
- jso-remove! JSO KEYprocedure
Removes KEY and the associated value from JSO. The prototype chain is not searched. Therefore, if the same key exists in the prototype chain, it will now be exposed. Attempts to remove nonexistent keys are ignored.
- jso-proto jsoprocedure
Returns the JSO's prototype, or the undefined value if it has none.
In addition to key-value pairs, a JSO also has an associated special value, which is the undefined value by default but can be changed to be any Scheme object.
- jso-value JSOprocedure
Returns the special value of JSO.
- jso-set-value! JSO VALUEprocedure
Sets the special value of JSO to VALUE.
- jso-copy JSOprocedure
Returns a shallow copy of JSO that shares the same prototype chain.
- jso-full-copy JSOprocedure
Returns a shallow copy of JSO including the whole prototype chain. The old and the new JSOs share nothing.
These all accept procedures which take two arguments, the key and the value respectively, and return the new value.
- jso-map PROC JSOprocedure
Returns a new JSO after applying PROC to each key-value pair of JSO. The new and old JSOs share prototypes.
- jso-map! PROC JSOprocedure
Modifies JSO by applying PROC to each key-value pair of JSO. The prototype chain is left undisturbed.
- jso-for-each proc jsoprocedure
Executes PROC over all the key-value pairs of JSO. The returned values are ignored. The prototype chain is not processed.
- jso-full-map PROC JSOprocedure
Returns a new JSO after applying PROC to each key-value pair of JSO including the whole prototype chain. The new and old JSOs share nothing.
Note that there is no jso-full-map!, on the principle that no standard JSO procedure makes a destructive change to the prototype chain.
- jso-full-for-each PROC JSOprocedure
Executes PROC over all the key-value pairs of JSO, including the whole prototype chain. The returned values are ignored.
- jso-apply JSO KEY #!rest ARGSprocedure
Applies the procedure (method) which is the value of KEY in JSO to JSO. Any trailing arguments are also passed.
- jso-apply/fallback JSO KEY FALLBACK #!rest ARGSprocedure
Applies the procedure (method) which is the value of KEY in JSO to JSO. Any trailing arguments are also passed. If there is no such key, the fallback procedure is invoked instead.