Question

Exercise 6.7.17: Explain the evaluation of the following Scheme code: 1 (define x 10) 2 (define y 11) 4 (define proc2 5 (lambda 6 (cons x (cons y 8 (define procl CHAPTER 6. BINDING AND SCOPE 248 9 (lambda (x y) 10 proc2 12 (define main 13 (lambda (cond 14 zero? read (procl 5 20) 15 (else (proc2 16 17 18 (main

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution: Evaluation ofscheme code: The first line of code assigns values into variables x →10 y →11 * In main procedure defi

Add a comment
Know the answer?
Add Answer to:
Explain the evaluation of the following Scheme code: (define x 10) (define y 11) (define proc2...
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
  • Consider this scheme function and explain it Consider the following Scheme function: (define f (lambda (1st)...

    Consider this scheme function and explain it Consider the following Scheme function: (define f (lambda (1st) (cond (null? 1st)) 0) ((number? (car 1st) (+ 1 (f (cdr 1st)))) (else (f (cdr 1st))))) Explain what the function f computes for lists. consider (f '(1 a b 2)) for example.

  • Question 10 (1 point) Consider the following Scheme code: Which bindings are active in the closure...

    Question 10 (1 point) Consider the following Scheme code: Which bindings are active in the closure returned by new-mystery-closure? (define toks (; code here (define curr '()) ) (define new-mystery-closure (lambda (L) (define foo (lambda (x) (define z 0) ; foo code here ) (define closure (lambda (y) ; CLOSURE CODE (define closure (lambda (y) ; CLOSURE CODE ) ) closure ) ) toks, new-mystery-closure, L, foo, curr, closure, y toks, new-mystery-closure, L, foo, x, z, curr, closure, y toks,...

  • In scheme coding language Write a function filterN that returns only the numbers n through m...

    In scheme coding language Write a function filterN that returns only the numbers n through m from a lat. For example: (filterN 4 6 (1 turkey 5 9 4 bacon 6 cheese)) returns (5 4 6). Use only functions add1, sub1, and, or, <, >, null?, number?, zero?, define, lambda, cond, and else in the code. Assume n < m

  • #define minl (x, y) ( (x < y) ? x : y) #define min 10 #include...

    #define minl (x, y) ( (x < y) ? x : y) #define min 10 #include <stdio.h> int min2(int x, int y) { if (x < y) return x; else return y; } main() { int a, b; scanf("%d %d", &a, &b); if (b < min) printf("input out of range\n"); else { a = minl(a, b++); printf("a = %d, b %d\n", a, b); a = min2(a, b++); printf("a = %d, b %d\n", a, b); } } ------------------------- 1 Give the...

  • in java Assuming that x is 11 and y is 9, EXPLAIN why the output of...

    in java Assuming that x is 11 and y is 9, EXPLAIN why the output of the following code is ????? if (x < 10) if ( y < 10) ​System.out.println(“*****”); else ​System.out.println(“#####”); ​System.out.println(“?????”);

  • ) ) (define counter (new-count)) (define foo (lambda (x) (+ x (- 0 x) x)) )...

    ) ) (define counter (new-count)) (define foo (lambda (x) (+ x (- 0 x) x)) ) (display (foo (counter))) 1 0 N (display (foo (counter) ) ) 1 0 2 -1 Question 13 (1 point) What would be output of the following code, assuming that normal order evaluation is used? (You may assume all arguments are evaluated left to right.) (define new-count (lambda () (let ((cnt 0)) (lambda () (set! cnt (+ 1 cnt)) cnt ) ) ) (define counter...

  • Using the Scheme functional language AND do not use set! (or any procedure with !) Question...

    Using the Scheme functional language AND do not use set! (or any procedure with !) Question 5 [4 marks] The following program can be used to determine if a given interpreter is using applicative-order or normal- order evaluation: (define (test x y) (if (= x 0) y)) (test 0 (1 3 0)) a. What will be the behaviour of this code on an interpreter that uses applicative-order evaluation? Explain why. b. What behaviour will be observed with an interpreter that...

  • OUTPUT IF: X = 10 Y = -5 X = 5 Y = -5 X =...

    OUTPUT IF: X = 10 Y = -5 X = 5 Y = -5 X = -15 Y = 5 Consider the following code segment, clearly showing a blank with a carat (™). What are the outputs? int x, y; cout << "This summer I am going to learn"; if (x > 10) cout << "swimming,"; else if (y > 0) cout << "surfing." else if (x > 0) cout << "dancing."; if (x <-10) cout << "spinning,"; else cout...

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

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

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