diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-10-26 06:41:57 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-10-26 06:41:57 -0700 |
commit | c2d87ddcd9e18d7088448533ba8203cd9a8a042e (patch) | |
tree | ec4a0ec4f732fef9c9cd87ab3276ece7a407673b /eval.c | |
parent | bc0d27c80e2f7b534ba1efd3f60210b5855f65c1 (diff) | |
download | txr-c2d87ddcd9e18d7088448533ba8203cd9a8a042e.tar.gz txr-c2d87ddcd9e18d7088448533ba8203cd9a8a042e.tar.bz2 txr-c2d87ddcd9e18d7088448533ba8203cd9a8a042e.zip |
last, butlast: become accessors, get optional arg.
* eval.c (optimize_qquote_form): Pass nil to default
new argument of butlast.
(me_whilet, me_iflet_whenlet): Likewise for last.
(eval_init): Add optional argument to registration
of last and butlast intrinsics.
* lib.c (last, butlast): Support optional numeric
argument, like in Common Lisp.
* lib.h (last, butlast): Declarations updated.
* share/txr/stdlib/place.tl (last, butlast): New
place macros.
* txr.1: Updated documentation. The description of
last is now moved into the sequence functions
section.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -2669,11 +2669,11 @@ static val optimize_qquote_form(val form) sym = list_s; args = mappend(cdr_f, args); } else { - val blargs = butlast(args); + val blargs = butlast(args, nil); if (all_satisfy(blargs, list_form_p_f, nil)) return rlcp_tree(cons(list_star_s, nappend2(mappend(cdr_f, blargs), - last(args))), form); + last(args, one))), form); } } @@ -3229,7 +3229,7 @@ static val me_whilet(val form, val env) val body = form; val sym = pop(&body); val lets = pop(&body); - val lastlet = last(lets); + val lastlet = last(lets, nil); val not_done = gensym(lit("not-done")); if (nilp(lastlet)) @@ -3253,7 +3253,7 @@ static val me_iflet_whenlet(val form, val env) return apply_frob_args(list(if3(sym == iflet_s, if_s, when_s), lets, args, nao)); } else { - val lastlet = last(lets); + val lastlet = last(lets, nil); if (nilp(lastlet)) eval_error(form, lit("~s: empty binding list"), sym, nao); @@ -4975,8 +4975,8 @@ void eval_init(void) reg_fun(intern(lit("nreverse"), user_package), func_n1(nreverse)); reg_fun(intern(lit("reverse"), user_package), func_n1(reverse)); reg_fun(intern(lit("ldiff"), user_package), func_n2(ldiff)); - reg_fun(intern(lit("last"), user_package), func_n1(last)); - reg_fun(intern(lit("butlast"), user_package), func_n1(butlast)); + reg_fun(intern(lit("last"), user_package), func_n2o(last, 1)); + reg_fun(intern(lit("butlast"), user_package), func_n2o(butlast, 1)); reg_fun(intern(lit("nthlast"), user_package), func_n2(nthlast)); reg_fun(intern(lit("nthcdr"), user_package), func_n2(nthcdr)); reg_fun(intern(lit("butlastn"), user_package), func_n2(butlastn)); |