Question: Hello, for the following problems the solutions are given in lisp. please help me understand the problem, and the solution. I understand neither. Please me
Hello,
for the following problems the solutions are given in lisp.
please help me understand the problem, and the solution. I understand neither. Please me help me figure out a way to approach these problems, I already tried writing some steps down but still don't understand how to try solving them.
thank you for your help in advance


4) Write a tail-recursive function myMaxAt which accepts a list of integers, position of the assumed maximum integer in the list, the assumed maximum integer in the list, and the current position of the item being examined, and returns a list with first item as the maximum integer and the second item as the position of the maximum integer. Position 0 corresponds to the first item. For example, LSIP> (myMaxAt (2 37-5 4) 0 2 0) (7 2) (defun myMaxAt (xlist mxPos mx Pos) (if (null xlist) (cons mx (cons mxPos '0))) (if (car xlist) mx) (myMaxAt (cdr xlist) Pos (car xlist) Pos 1)) (myMaxAt (cdr xlist) mxPos mx Pos 1)) 8) Consider the list, colors, given below in which a color and its attribute are specified for various colors. (setf colors ( (red 0.7) (blue 0.3) (purple 0.1) (violet 0.05) (black 0.8) (green 0.5))) Write a CLISP function, fmax, which accepts the above list & initial max value of an attribute, and returns the highest attribute. Use tail-recursive approach. For example, CLISP> (fmax colors 0.0) 0.8 (defun fimax (clrs mx) (if (null clrs) mx (if ((cadar clrs) mx) (fmax (cdr clrs) (cadar clrs)) (fmax (cdr clrs) mx) 4) Write a tail-recursive function myMaxAt which accepts a list of integers, position of the assumed maximum integer in the list, the assumed maximum integer in the list, and the current position of the item being examined, and returns a list with first item as the maximum integer and the second item as the position of the maximum integer. Position 0 corresponds to the first item. For example, LSIP> (myMaxAt (2 37-5 4) 0 2 0) (7 2) (defun myMaxAt (xlist mxPos mx Pos) (if (null xlist) (cons mx (cons mxPos '0))) (if (car xlist) mx) (myMaxAt (cdr xlist) Pos (car xlist) Pos 1)) (myMaxAt (cdr xlist) mxPos mx Pos 1)) 8) Consider the list, colors, given below in which a color and its attribute are specified for various colors. (setf colors ( (red 0.7) (blue 0.3) (purple 0.1) (violet 0.05) (black 0.8) (green 0.5))) Write a CLISP function, fmax, which accepts the above list & initial max value of an attribute, and returns the highest attribute. Use tail-recursive approach. For example, CLISP> (fmax colors 0.0) 0.8 (defun fimax (clrs mx) (if (null clrs) mx (if ((cadar clrs) mx) (fmax (cdr clrs) (cadar clrs)) (fmax (cdr clrs) mx)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
