Question: This question is to be solved in the coding language scheme. 2. Familiarize yourself with the following Scheme procedures 1. (string-length abc) produces 3 2.

This question is to be solved in the coding language scheme.

This question is to be solved in the coding language scheme. 2.Familiarize yourself with the following Scheme procedures 1. (string-length "abc") produces 32. (string-length "") produces 0 3. (substring "hello world" 0 5) produces

2. Familiarize yourself with the following Scheme procedures 1. (string-length "abc") produces 3 2. (string-length "") produces 0 3. (substring "hello world" 0 5) produces "hello" 4. (string=? "hello" "good bye") produces # 5. (string-ci-? "hello" "HELLO") produces #t 6. (string-append "Hello" " Goodness") produces "Hello Goodness" (a) Define a recursive procedure my-str-len taking one string arguments. The procedure my-str-len computes the length of the string in s. You must use the following procedure, (define (my - substrs) (cond ((string-? 1111 111) (else (substring s 1 (string-length s))))) (b) Define a recursive procedure substring? taking two arguments sstr and main-str that determines if sstr is a substring of main-str. Use only the string functions: string-length substring and string=?. (c) Write a recursive procedure string-reverse that takes a single argument in-string The procedure string-reverse takes its argument in-string and returns its reverse, For example, (string-reverse "dad n mom')) produces "mom n dad" The next helper function may be useful: (define (substr-ref str n) (substring strn (+ n 1))) 3. Functions declared using define can be expressed as the lambda special form. That is, (define (fx) is the same as (define f (lambda (x) )) Lambda forms can be used to return anonymous functions. Anonymous functions have a number of important applications in Scheme. For example, here is a function apply-two-unary that returns an anonymous procedure bound to two unary procedures and g. This anonymous function takes e as an argument. (define (apply-two- un ar y f g) (1 ambda (x) (f (g x)))) (a) Write a procedure binary-plus returning a lambd a expression. The procedure binary-plus takes two arguments and adds them together. It should work like, (define plus5 (binary-plus 5)) (plus57) produces 12. (b) Write a procedure to compute trinary-plus returning nested lambd a expressions. The procedure trinary-plus takes three arguments and adds them together, (define plus 5+4 ((trinary-plus 5) 4)) (plus 5+4 6) produces 15. 2. Familiarize yourself with the following Scheme procedures 1. (string-length "abc") produces 3 2. (string-length "") produces 0 3. (substring "hello world" 0 5) produces "hello" 4. (string=? "hello" "good bye") produces # 5. (string-ci-? "hello" "HELLO") produces #t 6. (string-append "Hello" " Goodness") produces "Hello Goodness" (a) Define a recursive procedure my-str-len taking one string arguments. The procedure my-str-len computes the length of the string in s. You must use the following procedure, (define (my - substrs) (cond ((string-? 1111 111) (else (substring s 1 (string-length s))))) (b) Define a recursive procedure substring? taking two arguments sstr and main-str that determines if sstr is a substring of main-str. Use only the string functions: string-length substring and string=?. (c) Write a recursive procedure string-reverse that takes a single argument in-string The procedure string-reverse takes its argument in-string and returns its reverse, For example, (string-reverse "dad n mom')) produces "mom n dad" The next helper function may be useful: (define (substr-ref str n) (substring strn (+ n 1))) 3. Functions declared using define can be expressed as the lambda special form. That is, (define (fx) is the same as (define f (lambda (x) )) Lambda forms can be used to return anonymous functions. Anonymous functions have a number of important applications in Scheme. For example, here is a function apply-two-unary that returns an anonymous procedure bound to two unary procedures and g. This anonymous function takes e as an argument. (define (apply-two- un ar y f g) (1 ambda (x) (f (g x)))) (a) Write a procedure binary-plus returning a lambd a expression. The procedure binary-plus takes two arguments and adds them together. It should work like, (define plus5 (binary-plus 5)) (plus57) produces 12. (b) Write a procedure to compute trinary-plus returning nested lambd a expressions. The procedure trinary-plus takes three arguments and adds them together, (define plus 5+4 ((trinary-plus 5) 4)) (plus 5+4 6) produces 15

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!