1

I want to implement filter function that would filter a list based on a condition

(defun filter (func xs)                                                          
  (mapcan                                                                        
    (lambda (x)                                                                  
      (when (func x) (list x))) xs ))                                            

but I get an error:

*** - EVAL: undefined function FUNC

I thought that lambda should see func. How to pass func to lambda correctly?

I use CLISP.

Community
  • 1
  • 1
Jakub M.
  • 30,095
  • 43
  • 103
  • 169

1 Answers1

5

You want

(when (funcall func x) (list x))

instead of

(when (func x) (list x))

More information about function vs. variable namespace:

Community
  • 1
  • 1
finnw
  • 46,680
  • 24
  • 139
  • 216