Question

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 1 2 4 5) 3 (0.01.02.00 (2 4 68 10) Write a definition for the function map Write a scheme function that counts the number of items in the given including any nested sub lists Call this function mylength. Do not use the pre list, defined length function or the function flatten.) (9)))))) my-length (1 (2 (3 (4 (5 (6 (8 ngth (1 2 3)
Any help is appreciated , I am working on a practice review for my class.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

48. function (define (map fl m) (if (null? m) (cons (fl (car m)) (map double 1 23 4 5)): returns double (eE) (define (doublesqrt function (man sat (list 0 1 4)) Answer 0 1 2 (ex) Math sartlo 1 4) (9x) or sat(o 1 4)49. (define (len L1) (if (null? L1) +1 n (sdx L)) (gx) (define (try lenthlist) ((null? ((list? (cond lengthlist (car 。) leng

copyable code

48.

function

(define (map f1 m)

(if (null? m) ’()

(cons (f1 (car m))

(map f1 (cdr m)))))

(map double ’(1 2 3 4 5)) ;

returns double

(or)

(define (double m)

(cond ((null? m) '())

        ((list? (car1 m)) (cons (double (car1 m)) (double (cdr m))))

        ((number? m) (list m))

        (else (cons (* 2 (car1 m)) (double (cdr m))))

        ))           

(or)

(map (lambda (m) (* m 2)) '(1 2 3 4 5))

sqrt function

(map sqrt (list 0 1 4))

Answer

0 1 2

(or)

Math.sqrt(0 1 4)

(or)

sqrt(0 1 4)

49.

(define (len L1)
                  (if (null? L1)
                        0
                        (+ 1 (len (cdr L1)))))

(or)

(define (try lenthlist)
  (cond ((null? lengthlist '0)
        ((list? (car lengthlist) (+ (try (car lengthlist)) (try
          (cdr lengthlist)))
        (else (+ '1 (try(cdr lengthlist))))
))

(or)

(define (my-length m)
  (cond ((null? m) 0)
        ((list? m) (+ (my-length (car m)) (my-length (cdr m))))
        (else 1)))  
Add a comment
Know the answer?
Add Answer to:
Any help is appreciated , I am working on a practice review for my class. higher...
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
  • I'm Having a problem with my solution, any help would be appreciated. A fast-food vendor sells...

    I'm Having a problem with my solution, any help would be appreciated. A fast-food vendor sells pizza slices ($1.75), fries ($2.00), and soft drinks ($1.25). Write a program to compute a customer’s bill. The program should request the quantity of each item ordered in a Sub procedure, calculate the total cost with a Function procedure, and use a Sub procedure to display an itemized bill. Now I have the code, but the Fries and the Soft Drinks are inverse of...

  • The purpose of this lab is to practice working with Python's higher order functions and ternary...

    The purpose of this lab is to practice working with Python's higher order functions and ternary operator. Write all of your code in one file named lab2.py. You can write the code for items 1 through 6 directly inside the main function. Let a be the list of values produced by list(range(1, 11)). [1 point] Using the map function and a lambda argument, write an expression that produces a list of the cubes of the values in a. Assign the...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • 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...

  • Hello! I am having trouble with a question from my stochastic processes class. Any help would...

    Hello! I am having trouble with a question from my stochastic processes class. Any help would be much appreciated! Traffic on Snyder Hill Road in Ithaca, NY, follows a Poisson process with rate 2/3’s of a vehicle per minute. 10% of the vehicles are trucks, the other 90% are cars. (a) What is the probability at least one truck passes in a hour? (b) Given that ten trucks have passed by in an hour, what is the expected number of...

  • C++, any help would be appreciated. Everything I do doesn't want to work. Thanks Create a...

    C++, any help would be appreciated. Everything I do doesn't want to work. Thanks Create a linked list program with a .h and a .cpp file. A menu is needed like below and the print list should just print the list. Print order summary, an example is bellow butt a cookie and amount would be great. And Exit is to well exit. 1. Print Ordering Summary 2. Print List 3. Exit This is what will be in the text file...

  • MATLAB only please I am trying to get my getdatafuntion to work. I am also trying to get all my x...

    MATLAB only please I am trying to get my getdatafuntion to work. I am also trying to get all my x's, y's, and v's to popup in the command window so I can put in any value and it will find the value for me using the equation I put in. function project_9_sjl() % PROJECT_9_SJL project_9_sjl() is the driver function for the program. % %    Name: Scott Lawrence %   Date: 3/27/2019 %   Class: CMPSC 200 %   Description: Determine the optimal...

  • any help! my program not working , there is an error but cannot solve it i...

    any help! my program not working , there is an error but cannot solve it i did this program after editing a previous program  and i tried to follow the following ; 1. Instead of printing the prime numbers from 2 to n, your program will print the first n prime numbers. 2. It will be an error if n is less than 1. Exampl: $ ./a 1 2 3 #include<stdio.h> 4 int p; // p is the global variable. 5...

  • C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality...

    C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality work. Lab 8 (this is to be turned in) Palindrome is a string that is the same as backwards or forwards “otto” “ababa” “noon” “ababbbbaba” In this lab we will work with strings (so we will be using character arrays). 1. Write a program that reads two strings strl and str2 from the keyboard 2. Print both strings 3. Write a function computeLength and...

  • Hi, I need help with my comp sci assignment. The parameters are listed below, but I...

    Hi, I need help with my comp sci assignment. The parameters are listed below, but I am having trouble generating the number of occurrences of each word. Please use a standard library. Read in the clean text you generated in part 2 (start a new cpp file). Create a list of all the unique words found in the entire text file (use cleanedTextTest.txt for testing). Your list should be in the form of an array of structs, where each struct...

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