lispcommon-lispfunction-call

EVAL: undefined function. Function as a param in Common LISP


Starting to learn LISP and wrote two simple programs, which uses functions as params.

The first:

;gnu clisp  2.49.60
(defun pf (x f123) (cond ((null x) nil)
                      (T (cons ( f123 (car x) ) (pf (cdr x) f123)))))

(defun f2 (x) (* x x)) 

(print (pf '(1 2 3 4) 'f2 ) )

The second:

(defun some1(P1 P2 x)
   (if (not( = (length x) 0))
    (cond 
       (
        (or ( P1 (car x) ) ( P2 (car x)) )
        (cons (car x) (some1 P1 P2 (cdr x) ))
        )
       (t (some1 P1 P2 (cdr x) ))
    )
  )
)

(print (some1 'atom 'null '( 5 1 0 (1 2) 10 a b c) )     )

The both of program aren't working. And I don't know how to fix it :(


Solution

  • (funcall f123 x y z) works, results:

    ;gnu clisp  2.49.60
    (defun pf (x f123)
      (cond ((null x) nil)
            (T (cons (funcall f123 (car x))
                     (pf (cdr x) f123)))))
    
    (defun f2 (x) (* x x)) 
    
    (print (pf '(1 2 3 4) 'f2))
    

    And

    ;gnu clisp  2.49.60
    
    (defun eq0(x)
      (if (= x 0)
          t
          nil))
    
    (defun bg10(x)
      (if (> x 10)
          t
          nil))
    
    (defun some1 (P1 P2 x)
      (if (not (= (length x) 0))
        (cond 
           ((or (funcall P1 (car x)) (funcall P2 (car x)))
            (cons (car x) (some1 P1 P2 (cdr x))))
           (t (some1 P1 P2 (cdr x))))))
    
    (print (some1 'eq0 'bg10 '(5 0 0 11)))
    

    Maybe it will be useful for someone :)