1. Homepage
  2. Exam
  3. CS440 Programming Languages - Midterm Exam - Part 2: Higher order functions

CS440 Programming Languages - Midterm Exam - Part 2: Higher order functions

This question has been solved
Contact Us On WeChat

CS 440 Midterm Exam (Take-Home) CourseNana.COM

This midterm exam consists of 7 separate exercises --- 3 on recursion and lists, 3 on higher order functions, and 1 involving an addition to an interpreter. They are described below: CourseNana.COM

Part 2: Higher order functions CourseNana.COM

until: takes a predicate pred, a function fn, and a starting value x, and returns the list of CourseNana.COM

values (x, (fn x), (fn (fn x)), ...), terminating on the first value which satisfies pred. CourseNana.COM

E.g., CourseNana.COM

> (until (lambda (x) (> x 100)) (lambda (x) (* 2 x)) CourseNana.COM

'(1 2 4 8 16 32 64)

> (until (curry = 10) add1 0) '(0 1 2 3 4 5 6 7 8 9) CourseNana.COM


alternately: takes a list of functions and a list of values, and returns the list created by CourseNana.COM

applying each function, in turn, to successive values of the list. E.g., CourseNana.COM

> (alternately (list add1 sub1 sqr) (range 10)) '(1 0 4 4 3 25 7 6 64 10) CourseNana.COM

> (alternately (list string-upcase string-downcase string-length) (list "Hello" "How" "Are" "You" "This" "Fine" "Day?")) CourseNana.COM

'("HELLO" "how" 3 "YOU" "this" 4 "DAY?") CourseNana.COM


stride: a macro that takes a variable name var, a stride length n, a list lst, and an expression expr, and returns the list of values resulting from evaluating expr with var set to each n-th value from the lst. E.g., CourseNana.COM

> (stride
> (stride
'(0 25 100 225 400 625)

x 2 '("hello" "how" "are" "you" "this" "fine" "day") (string-upcase x))

x 5 (range 30) (sqr x)) CourseNana.COM

Get Solution for This Question

Scan above qrcode with Wechat

IIT代写,US代写,CS440代写,CS 440代写,Programming Languages代写,Racket代写,Higher Order Functions代写,IIT代编,US代编,CS440代编,CS 440代编,Programming Languages代编,Racket代编,Higher Order Functions代编,IIT代考,US代考,CS440代考,CS 440代考,Programming Languages代考,Racket代考,Higher Order Functions代考,IIThelp,UShelp,CS440help,CS 440help,Programming Languageshelp,Rackethelp,Higher Order Functionshelp,IIT作业代写,US作业代写,CS440作业代写,CS 440作业代写,Programming Languages作业代写,Racket作业代写,Higher Order Functions作业代写,IIT编程代写,US编程代写,CS440编程代写,CS 440编程代写,Programming Languages编程代写,Racket编程代写,Higher Order Functions编程代写,IITprogramming help,USprogramming help,CS440programming help,CS 440programming help,Programming Languagesprogramming help,Racketprogramming help,Higher Order Functionsprogramming help,IITassignment help,USassignment help,CS440assignment help,CS 440assignment help,Programming Languagesassignment help,Racketassignment help,Higher Order Functionsassignment help,IITsolution,USsolution,CS440solution,CS 440solution,Programming Languagessolution,Racketsolution,Higher Order Functionssolution,