1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 04:10:18 +02:00

Single definition of (iota)

* module/ice-9/boot-9.scm (iota): Fix to be SRFI-1 compatible.
* module/srfi/srfi-1.scm: Re-export iota.
This commit is contained in:
Daniel Llorens 2019-12-06 14:14:30 +01:00
parent c6a9a7e775
commit 2b6083865a
3 changed files with 52 additions and 42 deletions

11
NEWS
View file

@ -4,6 +4,17 @@ See the end for copying conditions.
Please send Guile bug reports to bug-guile@gnu.org.
Changes since alpha 2.9.6:
* Notable changes
** (iota) in core and SRFI-1 (iota) are the same
Previously, (iota) in core would not accept start and step arguments and
would return an empty list for negative count. Now there is only one
(iota) function with the semantics of SRFI-1 (negative count is an
error).
Changes in alpha 2.9.6 (since alpha 2.9.5):

View file

@ -883,10 +883,15 @@ VALUE."
;;; {IOTA functions: generating lists of numbers}
;;;
(define (iota n)
(let loop ((count (1- n)) (result '()))
(if (< count 0) result
(loop (1- count) (cons count result)))))
;;; Compatible with srfi-1 so it can just be reused there.
(define* (iota count #:optional (start 0) (step 1))
(unless (and (integer? count) (>= count 0))
(throw 'wrong-type-arg count))
(let loop ((n (- count 1)) (result '()))
(if (negative? n)
result
(loop (- n 1) (cons (+ start (* n step)) result)))))

View file

@ -48,7 +48,7 @@
list-tabulate
list-copy
circular-list
;; iota ; Extended.
;; iota <= in the core
;;; Predicates
proper-list?
@ -216,8 +216,9 @@
caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr
cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr
list-ref last-pair length append append! reverse reverse!
filter filter! memq memv assq assv set-car! set-cdr!)
:replace (iota map for-each map-in-order list-copy list-index member
filter filter! memq memv assq assv set-car! set-cdr!
iota)
:replace (map for-each map-in-order list-copy list-index member
delete delete! assoc)
)
@ -266,13 +267,6 @@ INIT-PROC is applied to the indices is not specified."
(set-cdr! (last-pair elts) elts)
elts)
(define* (iota count #:optional (start 0) (step 1))
(check-arg non-negative-integer? count iota)
(let lp ((n 0) (acc '()))
(if (= n count)
(reverse! acc)
(lp (+ n 1) (cons (+ start (* n step)) acc)))))
;;; Predicates
(define (proper-list? x)