guile-user
[Top][All Lists]

## Re: Bug in and-map and or-map? What am I doing wrong?

 From: Alejandro Forero Cuervo Subject: Re: Bug in and-map and or-map? What am I doing wrong? Date: Wed, 9 May 2001 18:21:01 -0500 User-agent: Mutt/1.2.5i

```    Should I replace the existing `and-map' and `or-map' (in
boot-9.scm) with this generalization?

My humble user's vote is: YES, please!

However, rather than the definitions you sent me (and, by the way,
thank you very much for your prompt reply), I would use the following
two:

(define (and-map f . lsts)
(let loop ((l lsts))
(if (null? (car l))
(if (or (null? (cdr l))
(and-map null? (cdr l)))
#t
(error "Lists have different lengths"))
(and (apply f (map (lambda (c) (if (null? c)
(error "Lists have different
lengths")
(car c)))
l))
(loop (map cdr l))))))

(define (or-map f . lsts)
(let loop ((l lsts))
(if (null? (car l))
(if (or (null? (cdr l))
(and-map null? (cdr l)))
#f
(error "Lists have different lengths"))
(or  (apply f (map (lambda (c) (if (null? c)
(error "Lists have different
lengths")
(car c)))
l))
(loop (map cdr l))))))

I don't really know about the internals of Guile but I am guessing
these versions would be faster since most of the time they will run on
lists of the same lengths and they do not compute their lengths at
startup.

Thank you very much!

Alejo.
http://bachue.com/alejo

--
The mere formulation of a problem is far more essential than its solution.
-- Albert Einstein.

\$0='!/sfldbi!yjoV0msfQ!sfiupob!utvK'x44;print map{("\e[7m \e[0m",chr ord
(chop\$0)-1)[\$_].("\n")[++\$i%77]}split//,unpack'B*',pack'H*',(\$F='F'x19).
"F0F3E0607879CC1E0F0F339F3FF399C666733333CCF87F99E6133999999E67CFFCCF3".
"219CC1CCC033E7E660198CCE4E66798303873CCE60F3387\$F"#Don't you love Perl?
```

pgpSyHK3BSzWp.pgp
Description: PGP signature