diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | lib.c | 57 | ||||
-rw-r--r-- | lib.h | 3 | ||||
-rw-r--r-- | match.c | 9 | ||||
-rw-r--r-- | txr.1 | 2 | ||||
-rw-r--r-- | txr.vim | 1 |
6 files changed, 76 insertions, 8 deletions
@@ -1,3 +1,15 @@ +2012-02-19 Kaz Kylheku <kaz@kylheku.com> + + * lib.c (sub, ref, replace): New functions. + + * lib.h (sub, ref, replace): Declared. + + * match.c (format_field): Generic indexing using new functions. + + * txr.1: Documentation stub. + + * txr.vim: Highlighting for new functions. + 2012-02-18 Kaz Kylheku <kaz@kylheku.com> * match.c (extract_vars): If a brace var is actually an @@ -3570,7 +3570,62 @@ val length(val seq) case VEC: return length_vec(seq); default: - type_mismatch(lit("~s is not a sequence"), cons, nao); + type_mismatch(lit("length: ~s is not a sequence"), cons, nao); + } +} + +val sub(val seq, val from, val to) +{ + if (seq == nil) + return nil; + else switch (type(seq)) { + case CONS: + case LCONS: + return sub_list(seq, from, to); + case LIT: + case STR: + return sub_str(seq, from, to); + case VEC: + return sub_vec(seq, from, to); + default: + type_mismatch(lit("sub: ~s is not a sequence"), cons, nao); + } +} + +val ref(val seq, val ind) +{ + if (seq == nil) + return nil; + else switch (type(seq)) { + case CONS: + case LCONS: + return listref(seq, ind); + case LIT: + case STR: + return chr_str(seq, ind); + case VEC: + return vecref(seq, ind); + default: + type_mismatch(lit("ref: ~s is not a sequence"), cons, nao); + } +} + +val replace(val seq, val from, val to, val items) +{ + if (seq == nil) + goto list; + switch (type(seq)) { + case CONS: + case LCONS: + list: + return replace_list(seq, from, to, items); + case LIT: + case STR: + return replace_str(seq, from, to, items); + case VEC: + return replace_vec(seq, from, to, items); + default: + type_mismatch(lit("replace: ~s is not a sequence"), cons, nao); } } @@ -557,6 +557,9 @@ val sort(val list, val lessfun, val keyfun); val find(val list, val key, val testfun, val keyfun); val set_diff(val list1, val list2, val testfun, val keyfun); val length(val seq); +val sub(val seq, val from, val to); +val ref(val seq, val ind); +val replace(val seq, val from, val to, val items); val env(void); val obj_print(val obj, val stream); val obj_pprint(val obj, val stream); @@ -1236,16 +1236,11 @@ val format_field(val obj, val modifier, val filter, val eval_fun) val from = funcall1(eval_fun, second(arg_expr)); val to = funcall1(eval_fun, third(arg_expr)); - obj = if3((vectorp(obj)), - sub_vec(obj, from, to), - sub_list(obj, from, to)); + obj = sub(obj, from, to); } else { val arg = funcall1(eval_fun, arg_expr); if (bignump(arg) || fixnump(arg)) { - if (vectorp(obj)) - obj = vecref(obj, arg); - else - obj = listref(obj, arg); + obj = ref(obj, arg); } else { uw_throwf(query_error_s, lit("format_field: bad index: ~s"), arg, nao); @@ -6617,6 +6617,8 @@ Certain object types have a custom equal function. .SS Function length +.SS Functions sub, ref and replace + .SS Function symbol-function .SS Function func-get-form @@ -74,6 +74,7 @@ syn keyword txl_keyword contained list-vector copy-vec sub-vec cat-vec syn keyword txl_keyword contained replace-vec assoc assq acons acons-new syn keyword txl_keyword contained aconsq-new alist-remove alist-nremove copy-cons syn keyword txl_keyword contained copy-alist merge sort find set-diff length +syn keyword txl_keyword contained sub ref replace syn keyword txl_keyword contained symbol-function func-get-form func-get-env syn keyword txl_keyword contained functionp interp-fun-p *random-state* |