mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-07 05:06:37 +02:00
moving generalized every/any from srfi-1 to init
This commit is contained in:
parent
2b86320652
commit
24631a8cf2
2 changed files with 16 additions and 18 deletions
19
lib/init.scm
19
lib/init.scm
|
@ -89,11 +89,22 @@
|
||||||
(define (for1 f ls) (if (pair? ls) (begin (f (car ls)) (for1 f (cdr ls)))))
|
(define (for1 f ls) (if (pair? ls) (begin (f (car ls)) (for1 f (cdr ls)))))
|
||||||
(if (null? lol) (for1 f ls) (begin (apply map f ls lol) (if #f #f))))
|
(if (null? lol) (for1 f ls) (begin (apply map f ls lol) (if #f #f))))
|
||||||
|
|
||||||
(define (any pred ls)
|
(define (any pred ls . lol)
|
||||||
(if (pair? ls) (if (pred (car ls)) (car ls) (any pred (cdr ls))) #f))
|
(define (any1 pred ls)
|
||||||
|
(if (pair? ls) (if (pred (car ls)) (car ls) (any1 pred (cdr ls))) #f))
|
||||||
|
(define (anyn pred lol)
|
||||||
|
(if (every pair? lol)
|
||||||
|
((lambda (args) (if (apply pred args) args (anyn pred (map cdr lol))))
|
||||||
|
(map car lol))
|
||||||
|
#f))
|
||||||
|
(if (null? lol) (any1 pred ls) (anyn pred (cons ls lol))))
|
||||||
|
|
||||||
(define (every pred ls)
|
(define (every pred ls . lol)
|
||||||
(if (pair? ls) (if (pred (car ls)) (every pred (cdr ls)) #f) #t))
|
(define (every1 pred ls)
|
||||||
|
(if (pair? ls) (if (pred (car ls)) (every1 pred (cdr ls)) #f) #t))
|
||||||
|
(if (null? lol)
|
||||||
|
(every1 pred ls)
|
||||||
|
(not (apply any (lambda (x) (not (pred x))) ls lol))))
|
||||||
|
|
||||||
(define (delq x ls)
|
(define (delq x ls)
|
||||||
(if (pair? ls)
|
(if (pair? ls)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
;; search.scm -- list searching and splitting
|
;; search.scm -- list searching and splitting
|
||||||
;; Copyright (c) 2009 Alex Shinn. All rights reserved.
|
;; Copyright (c) 2009-2011 Alex Shinn. All rights reserved.
|
||||||
;; BSD-style license: http://synthcode.com/license.txt
|
;; BSD-style license: http://synthcode.com/license.txt
|
||||||
|
|
||||||
(define (find pred ls)
|
(define (find pred ls)
|
||||||
|
@ -31,19 +31,6 @@
|
||||||
|
|
||||||
(define break! break)
|
(define break! break)
|
||||||
|
|
||||||
(define (any pred ls . lists)
|
|
||||||
(if (null? lists)
|
|
||||||
(let lp ((ls ls)) (and (pair? ls) (if (pred (car ls)) (car ls) (lp (cdr ls)))))
|
|
||||||
(let lp ((lists (cons ls lists)))
|
|
||||||
(and (every pair? lists)
|
|
||||||
(let ((args (map car lists)))
|
|
||||||
(if (apply pred args) args (lp (map cdr lists))))))))
|
|
||||||
|
|
||||||
(define (every pred ls . lists)
|
|
||||||
(if (null? lists)
|
|
||||||
(let lp ((ls ls)) (if (pair? ls) (and (pred (car ls)) (lp (cdr ls))) #t))
|
|
||||||
(not (apply any (lambda (x) (not (pred x))) ls lists))))
|
|
||||||
|
|
||||||
(define (list-index pred ls . lists)
|
(define (list-index pred ls . lists)
|
||||||
(if (null? lists)
|
(if (null? lists)
|
||||||
(let lp ((ls ls) (n 0))
|
(let lp ((ls ls) (n 0))
|
||||||
|
|
Loading…
Add table
Reference in a new issue