summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--eval.c12
-rw-r--r--txr.114
3 files changed, 27 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 9fde9b76..7d55f198 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2014-07-29 Kaz Kylheku <kaz@kylheku.com>
+ * eval.c (repeatv): Renamed to repeat. Turned into function
+ with one optional argument, reflecting existing behavior.
+ (eval_init): Registration of repeat updated.
+
+ * txr.1: Fixed incorrect documentation which falsely suggests
+ that repeat takes multiple lists, and doesn't mention
+ the optional count.
+
+2014-07-29 Kaz Kylheku <kaz@kylheku.com>
+
* arith.c (plus, minus, mul): Fix missing breaks
to switch statements, leading to strange error
messages when wrong types are passed in.
diff --git a/eval.c b/eval.c
index dabb40bf..359c4988 100644
--- a/eval.c
+++ b/eval.c
@@ -3213,15 +3213,15 @@ static val repeat_times_func(val env, val lcons)
return nil;
}
-static val repeatv(val list, val rest)
+static val repeat(val list, val count)
{
if (!list)
return nil;
- if (rest) {
- val count = car(rest);
- if (count == zero)
+
+ if (!missingp(count)) {
+ if (le(count, zero))
return nil;
- return make_lazy_cons(func_f1(cons(list, cons(list, count)),
+ return make_lazy_cons(func_f1(cons(list, cons(list, count)),
repeat_times_func));
}
return make_lazy_cons(func_f1(cons(list, list), repeat_infinite_func));
@@ -3971,7 +3971,7 @@ void eval_init(void)
reg_fun(intern(lit("range*"), user_package), func_n0v(range_star_v));
reg_fun(generate_s, func_n2(generate));
reg_fun(intern(lit("giterate"), user_package), func_n3o(giterate, 2));
- reg_fun(intern(lit("repeat"), user_package), func_n1v(repeatv));
+ reg_fun(intern(lit("repeat"), user_package), func_n2o(repeat, 2));
reg_fun(intern(lit("force"), user_package), func_n1(force));
reg_fun(intern(lit("rperm"), user_package), func_n2(rperm));
reg_fun(intern(lit("perm"), user_package), func_n2o(perm, 1));
diff --git a/txr.1 b/txr.1
index 7fda0ce7..33c634d7 100644
--- a/txr.1
+++ b/txr.1
@@ -9062,13 +9062,21 @@ Example:
Syntax:
- (repeat <list1> <list>*)
+ (repeat <list> [<count>])
.TP
Description:
-The repeat function produces an infinite lazy list formed by the repeatedly
-cycled catenation of the argument lists.
+If <list> is empty, then repeat returns an empty list.
+
+If <count> is omitted, the repeat function produces an infinite lazy list
+formed by catenating together copies of <list>.
+
+If <count> is specified and is zero or negative, then an empty list is
+returned.
+
+Otherwise a list is returned consisting of <count> repetitions of <list>
+catenated together.
.SS Macros gen and gun