1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

* srfi-1.scm (check-arg-type, non-negative-integer?): a couple of new

internal definitions.
	(list-tabulate, iota): check for bad arguments that otherwise
	give weird output.
	(filter): check for proper list, to avoid infinite recursion on
	a circular list.
This commit is contained in:
Gary Houston 2001-08-05 10:12:37 +00:00
parent 848458d990
commit 5753f02f67
2 changed files with 22 additions and 0 deletions

View file

@ -1,3 +1,12 @@
2001-08-05 Gary Houston <ghouston@arglist.com>
* srfi-1.scm (check-arg-type, non-negative-integer?): a couple of new
internal definitions.
(list-tabulate, iota): check for bad arguments that otherwise
give weird output.
(filter): check for proper list, to avoid infinite recursion on
a circular list.
2001-08-04 Gary Houston <ghouston@arglist.com>
* srfi-1.scm (filter): replaced with a tail-recursive version.

View file

@ -254,7 +254,18 @@
(define (xcons d a)
(cons a d))
;; internal helper, similar to (scsh utilities) check-arg.
(define (check-arg-type pred arg caller)
(if (pred arg)
arg
(scm-error 'wrong-type-arg caller
"Wrong type argument: ~S" (list arg) '())))
;; the srfi spec doesn't seem to forbid inexact integers.
(define (non-negative-integer? x) (and (integer? x) (>= x 0)))
(define (list-tabulate n init-proc)
(check-arg-type non-negative-integer? n "list-tabulate")
(let lp ((n n) (acc '()))
(if (<= n 0)
acc
@ -272,6 +283,7 @@
(lp (cdr r) (cdr p)))))))
(define (iota count . rest)
(check-arg-type non-negative-integer? count "iota")
(let ((start (if (pair? rest) (car rest) 0))
(step (if (and (pair? rest) (pair? (cdr rest))) (cadr rest) 1)))
(let lp ((n 0) (acc '()))
@ -720,6 +732,7 @@
;;; Filtering & partitioning
(define (filter pred list)
(check-arg-type list? list "caller") ; reject circular lists.
(letrec ((filiter (lambda (pred rest result)
(if (null? rest)
(reverse! result)