2017-04-26 3 views
1

Je veux un prédicat en tant que paramètre d'une fonction.LISP: avec prédicat comme paramètre

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

(per 'numberp 3) 

comme résultat soulève une erreur:

Undefined operator F in form (F L).

Répondre

0

tard à la fête, mais voici un autre exemple:

(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)))))) 

Cela pourrait être utilisé sur des prédicats tels que atome ou numberp:

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

(a b c d)

ou:

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

((a b))