r coMp I r coMpa r co x 4. Heap e 2282 c Here ls l Egyptia l In Jobs H l 3. Inse
ID: 3779268 • Letter: R
Question
r coMp I r coMpa r co x 4. Heap e 2282 c Here ls l Egyptia l In Jobs H l 3. Inser coMp: l E ENGR2 n course r Divide, Merges O users oncardia.ca 2/notes/COMP348 assignment 2 FALL 2016.pdf 3 of 8 In this question assume: "first car" and "rest cdr" and E is a given element, and L is list of some items such as numbers, etc. a) Analyze this code and explain what myfunction1 is doing? (defun my function (E L) (if (null L) nil (if (equal (first L) E) my function E (rest L b) Test your function on your computer by some (at least 3 examples) of different values for its input parameter (E L) and show results of your examples for this function. nuactinnit A. r2n+A Markel Ask me anything 40 ENG 0:40 PM US 2016-11-22Explanation / Answer
a).
Explanation :-
if(null L) --> If the list is empty.
nil --> nil
if (equal (first L) E) --> If first element of L equals E
T --> true
1). if the list is null, go to nil; else go to next if clause.
2). If the first element of L equals E. Halt with T
Else recurively call the function with (E rest L)
The function always return either T or nil. If E is present in L. Output is T otherwise nil
b).
myFunction1 20 (10 20 30) --> T
myFunction1 20 (10 40 30) --> nil
myFunction1 0 (0 430 210) --> T
This is a very simple use case. You can create your own use cases. Comment if you have any concern.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.