2017-04-26 109 views
1

我想要謂詞作爲函數的參數。LISP:謂詞作爲參數

(DEFUN per (F L) 
    (cond ((F L) 'working) 
      (T  'anything))) 

(per 'numberp 3) 

因爲導致它提出了一個錯誤:

Undefined operator F in form (F L).

回答

0

遲到了,但這裏有一個例子:

(defun strip-predicate (p list) 
    (cond ((endp list) nil) 
     ((funcall p (first list)) (strip-predicate (rest list))) 
     (T (cons (first list) (strip-Predicate p (rest list)))))) 

這可能對謂語,如原子或numberp使用:

(strip-predicate 'numberp '(a 1 b 2 c 3 d)) 

(a b c d)

或:

(strip-predicate 'atom '(a (a b) b c d)) 

((a b))