Andmap\ormap - 方案

Ada*_* Sh 4 scheme chez-scheme

我试图在 chez 方案中查找有关 andmap 和 ormap 操作的信息。

尽管如此,我还是不明白这些操作的用途,以及它和map有什么区别。

Mat*_*ard 6

在伪方案中,

(andmap f xs)  ==  (fold and #t (map f xs))
(ormap  f xs)  ==  (fold or  #f (map f xs))
Run Code Online (Sandbox Code Playgroud)

除了那个:

  1. 你不能以这种方式使用andand 。or
  2. andmapormap可以短路处理列表。

也就是说,除了短路行为略有不同之外,

(andmap f (list x1 x2 x3 ...))  ==  (and (f x1) (f x2) (f x3) ...)
(ormap  f (list x1 x2 x3 ...))  ==  (or  (f x1) (f x2) (f x3) ...)
Run Code Online (Sandbox Code Playgroud)