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.

1
  • 1
    You might also want to have a look at the function REMOVE-IF-NOT which does exactly this. Commented Oct 31, 2012 at 8:34

1 Answer 1

6

You want

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

instead of

(when (func x) (list x))

More information about function vs. variable namespace:

Sign up to request clarification or add additional context in comments.

1 Comment

Just mentioning that (func x) tries to evaluate a function called func whereas (funcall func x) call a function called func with x as its argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.