From cd8cf4f8fd827e428c53f2e6d7fcce5cd9727e7f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 1 Jun 2016 07:05:35 -0700 Subject: 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. --- struct.h | 1 + 1 file changed, 1 insertion(+) (limited to 'struct.h') diff --git a/struct.h b/struct.h index e71f717b..46dc6542 100644 --- a/struct.h +++ b/struct.h @@ -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); -- cgit v1.2.3