Site icon Tutor Bin

University of Guadalajara DR Raquet Programming Language Worksheet

University of Guadalajara DR Raquet Programming Language Worksheet

Description

Dr. Raquet language program

Implement the following functions. Functions should return values which will can then be printed by racket (as a result of the function call).
Include display/printf statements as necessary to label the results (of the function calls) in order to demonstrate that your code works properly.
Functions should not internally contain display or printf statements within other than when you are tracing/debugging the code. Email your racket file to me when done (normally a .rkt extension).

Write two functions to convert between miles and kilometers: kilometres(miles) → kilometres and miles(km) → miles. To get from miles to kilometers, multiply by 1.609. To convert the other way, multiply by 0.6215.
To demonstrate that each function works, you might have something like the following:
; using display
(display “(miles-to-km 10) = “)(miles-to-km 10)(newline)(newline)

; Or, using printf
(printf “(miles-to-km 10) = ~an” (miles-to-km 10))

Give the values returned by each of the following function calls in Dr. Racket.
You can mainly just label the output, and look at each to understand what they do.
(define (foo x y)
(+ x y (- x)))
Expression:

(foo (- 2) 4)
(define (a b c d)
(e b c d))

(define f +)

(define e f)
Expression:

(a (+ 3 2) (* 4 5) 3)
(define (a1 b c d)
((e1 (f1 b)) c d))

(define (e1 a)
a)

(define (f1 a)
(if (positive? a)
+
-))
Expression:

(a1 1 (+ 2 3) 4)
Rewrite the following functions so that the definitions are nested lexically within each other.
Only the entry procedure baz should be visible in the global environment. Take advantage of lexical scoping to remove redundant parameters.

(define (foo a)
(* a (+ a 2)))

(define (bar a b)
(if (= a 14)
b
(bar (+ a 1) (+ (foo a) b))))

(define (baz n)
(bar 3 n))
Write a function sum-range (from-to) for finding the sum of integers in the range from to, inclusive.
Make sure that (sum-range 4 18), (sum-range 18 4), and (sum-range 7 7) all give the expected result.
Note that this function should be able to count up or count down depending on the order of the paramaters.
So, (sum-range 4 18) and (sum-range 18 4) should give the same result. (sum-range 7 7) should return 7.

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Exit mobile version