2017年3月31日金曜日

and

 たとえば、リストになった数値の合計はapplyを使って次のように書ける。

(apply '+ '(1 2 3))
6

 じゃ、真偽値のリストをまとめるのはこうだな。

(apply 'and '(t t nil))

 と思った。あかんかった。

apply: Invalid function: and

 になってしまった。たしかにandをhelpしてみたら。

and is a special form in `C source code'.

(and CONDITIONS…)

Eval args until one of them yields nil, then return nil.
The remaining args are not evalled at all.
If no arg yields nil, return the last arg's value.

 スペシャルフォームだった。
 まぁ、こう書けばいいんだけど。

(require 'cl)
(cl-reduce (lambda(x y)(and x y)) '(t t nil))
nil

 elisp固有か、と思ったらCommnLispも同じだった。

(apply 'and '(t t t t))

debugger invoked on a UNDEFINED-FUNCTION in thread
#<THREAD "main thread" RUNNING {1002827193}>:
The function COMMON-LISP:AND is undefined.

 なんと。