Question: Hi! Can someone please help me figure out this (common) LISP programming question? So far, I have the following: (defun satisfy (fun lst) (fun lst)

Hi! Can someone please help me figure out this (common) LISP programming question?

Hi! Can someone please help me figure out this (common) LISP programming

So far, I have the following:

(defun satisfy (fun lst) "(fun lst) Returns a list of the items in a list that satisfy a function." (do ((numbers lst (cdr numbers)) (sat ())) ((null numbers) sat) (if (funcall #'fun (car numbers)) (cons (car numbers) sat))))

I tried to cons all the numbers that satisfy the function into the list "sat", but it's not working properly... I think it's an issue with the way I've used the funcall function. Can someone explain it to me?

Use do, if, and funcall to define (satisfy fun 1st) which returns a list of the items in a list that satisfy a function. An item satisfies a function if the function returns true when that item is used as the function's argument. Use do, if, and funcall to define (satisfy fun 1st) which returns a list of the items in a list that satisfy a function. An item satisfies a function if the function returns true when that item is used as the function's argument

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!