mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-17 17:20:29 +02:00
Simplify boot-9 and srfi-1 map
* module/ice-9/boot-9.scm (map): * module/srfi/srfi-1.scm (map): Simplify the implementations to check for list? beforehand. It's faster, and it will be needed if we decide to go recursive.
This commit is contained in:
parent
de3cbadcc0
commit
4926024cfb
2 changed files with 19 additions and 63 deletions
|
@ -566,20 +566,11 @@ has just one element then that's the return value."
|
|||
(case-lambda
|
||||
((f l)
|
||||
(check-arg procedure? f map)
|
||||
(let map1 ((hare l) (tortoise l) (move? #f) (out '()))
|
||||
(if (pair? hare)
|
||||
(if move?
|
||||
(if (eq? tortoise hare)
|
||||
(scm-error 'wrong-type-arg "map" "Circular list: ~S"
|
||||
(list l) #f)
|
||||
(map1 (cdr hare) (cdr tortoise) #f
|
||||
(cons (f (car hare)) out)))
|
||||
(map1 (cdr hare) tortoise #t
|
||||
(cons (f (car hare)) out)))
|
||||
(if (null? hare)
|
||||
(reverse! out)
|
||||
(scm-error 'wrong-type-arg "map" "Not a list: ~S"
|
||||
(list l) #f)))))
|
||||
(check-arg list? l map)
|
||||
(let map1 ((in l) (out '()))
|
||||
(if (pair? in)
|
||||
(map1 (cdr in) (cons (f (car in)) out))
|
||||
(reverse! out))))
|
||||
|
||||
((f l1 . rest)
|
||||
(check-arg procedure? f map)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue