Question

Function 4: my-map In CLISP define your own function that duplicates the functionality of mapcar from...

Function 4: my-map

In CLISP define your own function that duplicates the functionality of mapcar from the standard library. You may not use the built-in mapcar function as a helper function. Your implementation must be recursive.

·         Input: The input to my-map is a function that takes a single argument and a homogeneous list of elements of the same data type compatible with the procedure. Note: the function argument can be named or anonymous (lambda).

·         Output: A new list of the original elements with the same procedure applied to each.

·         Examples:

> (my-map 'sqrt '(9 25 81 49))

'(3 5 9 7)

> (my-map '1+ '(6 4 8 3))

'(7 5 9 4)

> (my-map (lambda (n) (* n n)) '(5 7))

'(25 49)

> (my-map 'evenp '(2 5 7 12))

'(t NIL NIL t)

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Function 4: my-map In CLISP define your own function that duplicates the functionality of mapcar from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use scheme to solve this: MUST USE A COMBINATION OF MAP AND FILTER or MAP AND...

    Use scheme to solve this: MUST USE A COMBINATION OF MAP AND FILTER or MAP AND APPLY: THIS ANSWER IS NOT WHAT I NEED: (define perfect-square-helper (lambda (x y) (if (null? x) (reverse y) (if (integer? (sqrt (car x))) (perfect-square-helper (cdr x) (cons (car x) y)) (perfect-square-helper (cdr x) y))))) (define perfect-square (lambda (x) (perfect-square-helper x '()))) (define x '(1 2 9 16 5 64)) (perfect-square x) Map/Apply/Filter 7. Perfect Squares (10 Points) Using a combination of map, apply and/or...

  • how would i create the function apply in scheme? A my-apply function that does the same...

    how would i create the function apply in scheme? A my-apply function that does the same thing as it Higher-order Functions A function is called a higher-order function (also called a functional form) if it takes a function as an argument or returns a newly constructed function as a result Scheme has several built-in higher-order functions, for example apply takes a function and a list and applies the function with the elements of the list as arguments input (apply (3...

  • Any help is appreciated , I am working on a practice review for my class. higher...

    Any help is appreciated , I am working on a practice review for my class. higher order function in 18. Assume you are working with a scheme interpret that does not have a definition for the function 'map'. map is a common list. higher order Scheme. ap typically, takes a list and transforms it by applying a function to each of its elements. It returns the new transformed (fmap sqrt (o 14) For example: (map double '0) (map double (list...

  • Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that...

    Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that it is tail-recursive. You may use the letrec form but do not use any additional forms and functions besides those we've talked about in class. (define filter (lambda (input-list func)     (cond ((null? input-list) '())           ((func (car input-list))            (cons (car input-list) (filter (cdr input-list) func)))           (else            (filter (cdr input-list) func))))) 2. Test your filter function on '(25 -22 44 56...

  • Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n):...

    Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n): 2 "*"Returns the nth Fibonacci number. " 3 if n < 3: lil 4 return 1 Modify the recursive Fibonacci function to employ the memoization technique discussed in this chapter. The function creates a dictionary and then defines a nested recursive helper function named memoizedFib You will need to create a dictionary to cache the sum of the fib function. The base case of...

  • Please help with all four questions regarding LISP Programming. Thank you. Please answer all questions with...

    Please help with all four questions regarding LISP Programming. Thank you. Please answer all questions with output plesase. LISP Programming Assignment It is a good idea to start this assignment early; Lisp programming, while not inherently difficult, often seem somewhat foreign at first, particularly when it comes to recursion and list manipulation. This assignment is loosely based on material by Dr. Henri Casanova.   Problem #1 Define a function that takes two arguments and returns the greater of the two. Problem...

  • In C++: Write a hash.cpp that does the following: Write your own main and insert function...

    In C++: Write a hash.cpp that does the following: Write your own main and insert function to insert the sequence of integers 121, 81, 16, 100, 25, 0, 1, 9, 4, 36, 64, 49,) into a hash table using initial table of size 17. Implement rehashing and run the same sequence of input using initial table of size 7. You can choose any rehashing function for this part. Thanks!

  • Define a function called collapse() which takes a list as input. Each element of the list...

    Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...

  • May I please know how to program this question in python step by step? Thank you...

    May I please know how to program this question in python step by step? Thank you You are to write a function called arrange. Your function will reorder a given list, where even indexed elements are arranged by descending order (based on index order) from 0 to n/2 of the list and odd indexed elements arranged in ascending order from (n/2) + 1 to n 1. Your function does not need to return the list but to change the existing...

  • 1. Define a function in python that returns the sum of the following 4 lists. Remember...

    1. Define a function in python that returns the sum of the following 4 lists. Remember to store and re- use your code instead of summing the values for each list 4 times. Hence, define a function that takes as an argument a list and returns the sum of values. Copy the following lists and paste them in a Python file after you define the sum_of_values function Call the function and pass to it a different list each call as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT