Commit fc6ef0b2 authored by Dave Cooper's avatar Dave Cooper
Browse files

merged enhanced/corrected version of list-of-numbers from REC

parent c2854726
...@@ -124,6 +124,30 @@ object in <b>object-list</b>. ...@@ -124,6 +124,30 @@ object in <b>object-list</b>.
(the-object object (evaluate message))) object-list))) (the-object object (evaluate message))) object-list)))
(defun list-of-numbers (num1 num2 &optional (increment 1) (tolerance (/ increment 10)))
"List of Numbers. Returns a list of incrementing numbers starting
from <b>num1</b> and ending with <b>num2</b>, inclusive. Increment can
be positive for num1 < num2, or negative for num1 > num2. This version
was contributed by Reinier van Dijk.
:arguments (num1 \"Number\"
num2 \"Number\")
:&optional ((increment 1) \"Number. The distance between the returned listed numbers.\"
(tolerance (/ increment 10)) \"Number. tolerance for increment.\")"
(cond ((zerop increment) (error "increment of zero is not allowed"))
((and (< increment 0.0) (> num2 num1)) (error "increment is negative, while difference between num2 and num1 is positive."))
((and (> increment 0.0) (< num2 num1)) (error "increment is positive, while difference between num2 and num1 is negative."))
(t (let ((predicate (if (> increment 0.0) #'>= #'<=))
(result-list nil))
(do ((num num1 (+ num increment)))
((or (funcall predicate num num2) (< (abs (- num2 num)) tolerance)) (nreverse (cons num2 result-list)))
(push num result-list))))))
;;
;; FLAG -- remove this when above version is fully tested.
;;
#+nil
(defun list-of-numbers (num1 num2 &optional (increment 1)) (defun list-of-numbers (num1 num2 &optional (increment 1))
"List of Numbers. Returns a list of incrementing numbers starting from "List of Numbers. Returns a list of incrementing numbers starting from
<b>num1</b> and ending with <b>num2</b>, inclusive. <b>num1</b> and ending with <b>num2</b>, inclusive.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment