sorawee
2020-8-2 21:43:31

<rant>

(andmap f xs) tries to be clever by returning (f &lt;last-element&gt;) in tail position.

But this is kinda bad, because it doesn’t generalize to other constructs. For example:

(for/and ([x xs] #:when (pred x)) (f x)) In an iteration, for/and can compute (f x). But it can’t ever return (f x) in tail position because it needs to look into the next iterations whether (pred x) are all #f.

</rant>


notjack
2020-8-3 02:37:38

is there a situation where the tail-position-ness mattered to you? wondering how this came up


sorawee
2020-8-3 03:53:59

It’s just inconsistent.

&gt; (andmap (lambda (x) (values 1 2)) '(1)) 1 2 &gt; (for/and ([x (in-list '(1))]) (values 1 2)) error


notjack
2020-8-3 06:35:19

the second behavior seems more sensible to me


sorawee
2020-8-3 06:38:10

Yeah


sorawee
2020-8-3 06:38:37

I think the idea of that behavior is that (andmap f (list 1 2 3)) is supposed to be like (and (f 1) (f 2) (f 3))


sorawee
2020-8-3 06:38:55

and (and #t (values 1 2)) results in (values 1 2) which is kinda useful as a control flow operator.