diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-06-01 20:57:01 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-06-01 20:57:01 -0700 |
commit | b0ae3c5e66313a7f58d346a55c80df355b63c559 (patch) | |
tree | 83da9651ebcfcf6f516d2138225e2e22e2e915ec /lib.c | |
parent | 7bfad97bfbcfea8c6e500565a629341419471013 (diff) | |
download | txr-b0ae3c5e66313a7f58d346a55c80df355b63c559.tar.gz txr-b0ae3c5e66313a7f58d346a55c80df355b63c559.tar.bz2 txr-b0ae3c5e66313a7f58d346a55c80df355b63c559.zip |
Adding special function from-list.
* lib.c (from_list_s): New symbol variable.
(make_like): Handle a COBJ. If it's a structure with a
from-list method, then use it, otherwise the
default handling applies of returning the list.
(obj_init): Initialize from_list_s.
* txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -101,7 +101,7 @@ val error_s, type_error_s, internal_error_s, panic_s; val numeric_error_s, range_error_s; val query_error_s, file_error_s, process_error_s, syntax_error_s; val timeout_error_s, system_error_s; -val gensym_counter_s, nullify_s; +val gensym_counter_s, nullify_s, from_list_s; val nothrow_k, args_k, colon_k, auto_k, fun_k; val wrap_k, reflect_k; @@ -662,6 +662,13 @@ val make_like(val list, val thatobj) if (is_chr(car(list))) return cat_str(list, nil); break; + case COBJ: + if (structp(thatobj)) { + val from_list_meth = maybe_slot(thatobj, from_list_s); + if (from_list_meth) + return funcall1(from_list_meth, list); + } + break; case NIL: case CONS: case LCONS: @@ -8652,6 +8659,7 @@ static void obj_init(void) assert_s = intern(lit("assert"), user_package); name_s = intern(lit("name"), user_package); nullify_s = intern(lit("nullify"), user_package); + from_list_s = intern(lit("from-list"), user_package); args_k = intern(lit("args"), keyword_package); nothrow_k = intern(lit("nothrow"), keyword_package); |