diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-06-01 07:05:35 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-06-01 07:05:35 -0700 |
commit | cd8cf4f8fd827e428c53f2e6d7fcce5cd9727e7f (patch) | |
tree | 5acb1cb50e758409457f971d3e2fefa484ed9890 /struct.h | |
parent | 8a443d67ef95021529db7eb451479e79fb39b272 (diff) | |
download | txr-cd8cf4f8fd827e428c53f2e6d7fcce5cd9727e7f.tar.gz txr-cd8cf4f8fd827e428c53f2e6d7fcce5cd9727e7f.tar.bz2 txr-cd8cf4f8fd827e428c53f2e6d7fcce5cd9727e7f.zip |
Methods for turning objects into sequences.
Struct objects can now define methods car, cdr and nullify.
With these, they can participate in operations on sequences.
* eval.h (car_s, cdr_s): Declared.
* lib.c (nullify_s): New symbol variable.
(car, cdr): Implement for struct objects via, respectively,
their car and cdr methods.
(tolist): Handle objects by mapping through identity.
(nullify): Implement for objects optionally: if an object
is a struct with a nullify method, use it, otherwise go
through default case of just returning the object.
(empty): Implement for objects that have nullify method.
(obj_init): Initialize nullify_s.
* struct.c (maybe_slot): New function.
* struct.h (maybe_slot): Declared.
* txr.1: Documented car, cdr and nullify method
convention.
Diffstat (limited to 'struct.h')
-rw-r--r-- | struct.h | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -39,6 +39,7 @@ val replace_struct(val target, val source); val reset_struct(val strct); val find_struct_type(val sym); val slot(val strct, val sym); +val maybe_slot(val strct, val sym); val slotset(val strct, val sym, val newval); val static_slot(val stype, val sym); val static_slot_set(val stype, val sym, val newval); |