Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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?
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 argumentStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started