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:
parent
c6a9a7e775
commit
2b6083865a
3 changed files with 52 additions and 42 deletions
11
NEWS
11
NEWS
|
@ -4,6 +4,17 @@ See the end for copying conditions.
|
||||||
|
|
||||||
Please send Guile bug reports to bug-guile@gnu.org.
|
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):
|
Changes in alpha 2.9.6 (since alpha 2.9.5):
|
||||||
|
|
|
@ -883,10 +883,15 @@ VALUE."
|
||||||
;;; {IOTA functions: generating lists of numbers}
|
;;; {IOTA functions: generating lists of numbers}
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
(define (iota n)
|
;;; Compatible with srfi-1 so it can just be reused there.
|
||||||
(let loop ((count (1- n)) (result '()))
|
|
||||||
(if (< count 0) result
|
(define* (iota count #:optional (start 0) (step 1))
|
||||||
(loop (1- count) (cons count result)))))
|
(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)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
list-tabulate
|
list-tabulate
|
||||||
list-copy
|
list-copy
|
||||||
circular-list
|
circular-list
|
||||||
;; iota ; Extended.
|
;; iota <= in the core
|
||||||
|
|
||||||
;;; Predicates
|
;;; Predicates
|
||||||
proper-list?
|
proper-list?
|
||||||
|
@ -216,8 +216,9 @@
|
||||||
caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr
|
caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr
|
||||||
cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr
|
cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr
|
||||||
list-ref last-pair length append append! reverse reverse!
|
list-ref last-pair length append append! reverse reverse!
|
||||||
filter filter! memq memv assq assv set-car! set-cdr!)
|
filter filter! memq memv assq assv set-car! set-cdr!
|
||||||
:replace (iota map for-each map-in-order list-copy list-index member
|
iota)
|
||||||
|
:replace (map for-each map-in-order list-copy list-index member
|
||||||
delete delete! assoc)
|
delete delete! assoc)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -266,13 +267,6 @@ INIT-PROC is applied to the indices is not specified."
|
||||||
(set-cdr! (last-pair elts) elts)
|
(set-cdr! (last-pair elts) 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
|
;;; Predicates
|
||||||
|
|
||||||
(define (proper-list? x)
|
(define (proper-list? x)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue