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) procedure
- (make-jso PROTO) procedure
Constructs a new JSO. If PROTO is supplied, it must be a JSO and is used as the prototype for the new object.
- (jso? OBJ) procedure
Returns true if OBJ is a JSO.
- (jso-undef? OBJ) procedure
Returns true if OBJ is the undefined value.
- (jso-ref JSO KEY) procedure
Retrieves the value for KEY in JSO, or the undefined value if KEY is not found.
- (jso-set! JSO KEY VALUE) procedure
Sets VALUE to be the value of KEY in JSO; the prototype chain is not searched.
- (jso-remove! JSO KEY) procedure
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 jso) procedure
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 JSO) procedure
Returns the special value of JSO.
- (jso-set-value! JSO VALUE) procedure
Sets the special value of JSO to VALUE.
- (jso-copy JSO) procedure
Returns a shallow copy of JSO that shares the same prototype chain.
- (jso-full-copy JSO) procedure
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 JSO) procedure
Returns a new JSO after applying PROC to each key-value pair of JSO. The new and old JSOs share prototypes.
- (jso-map! PROC JSO) procedure
Modifies JSO by applying PROC to each key-value pair of JSO. The prototype chain is left undisturbed.
- (jso-for-each proc jso) procedure
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 JSO) procedure
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 JSO) procedure
Executes PROC over all the key-value pairs of JSO, including the whole prototype chain. The returned values are ignored.
- (jso-apply JSO KEY . ARGS) procedure
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 . ARGS) procedure
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.