Quizzes Flashcards
One of the major differences between the imperative and functional programming languages is that the functional programming languages do NOT (in general)…
have side-effects.
Convert the following expression into prefix-p notation (a Scheme statement):
10 + (5 - 3) + 2/4
(+ 10 (- 5 3) (/ 2 4))
Convert the following expression into prefix-p notation (a Scheme statement):
-5 * (2 + 1/2) + 40
(+ (* (- 5) (+ 2 (/ 1 2))) 40)
The statement “a function is a first-class object” means that a function…
can be placed in a place where a value is expected.
What notation requires parentheses in order to correctly define the order of computation?
infix notation
In Scheme, the form (symbol-length? ‘James) will return:
an error message
Which of the following is a valid Scheme expression?
(* 9 (/ (- 4 2) 7))
What is the expected result for this expression (in Scheme)?
(string-ref “Hello World” 4)
/o
Given an expression: x1 + x2 + x3 + x4
Which language allows us to evaluate the expression in this order: (1) x1 plus x2; (2) x3 plus x4; (3) sum of (x1 + x2) plus sum of (x3 + x4), without concern for producing a different result than other evaluation orders:
Scheme
Which of the following expression will return false (#f)?
(number? #\7)
The Scheme for (char? #\5) will return…
true (#t)
What data structure is used in Scheme for representing extremely large integers?
probably a list. Really, we shouldn’t know or care.
A student is wondering if Scheme is a strong or weakly typed language. How might they check this?
They could execute a form like (+ #\a 10) in the REPL. If i works (like in C), then it is probably weakly typed.
Given this procedure, what is the return result?
(define (guess value)
(cond ((number? value) “I’m a number”)
((char? value “I’m a character”)
((integer? value) “I’m an integer”)))
(guess 10)
“I’m a number”
What statements contain non-functional features of Scheme?
(begin (write x) x)
(display x)
What is the result of this expression (in Scheme)?
(let ((x 10)
(y 10)
(- (* x y) y))
90
What functional feature does the code below best exhibit?
(define start-engine (lambda ()
(error-detection (wheel-velocity (wheel-sensor)) (body-velocity))))
procedures are first class objects
A let-form in Scheme is equivalent (in giving names to values) to…
an unnamed/lambda procedure.
Given the Scheme code, answer the following two questions.
((lambda (x)
((lambda (x y)
(+ x y))
5 (* 7 x)))
3)
1). What is the value passed to parameter y?
2). What is the final output?
y = 21
final output = 26
Given the Scheme code, answer the following two questions.
((lambda (x)
((lambda (x y)
(+ x y))
4 (* 6 x)))
3)
1). What is the value passed to parameter y?
2). What is the final output?
y = 18
final output = 22
Which of the following forms will return an error when run?
(‘+ 2 3)
(define a a)
Given this Scheme procedure:
(define foo (lambda (x)
(if (= x 0)
1
(* x (foo (- x 1)))
)
))
What does this procedure do?
compute x!
Which of the followings is a Scheme pair?
‘(x.y)
‘(x.x)
’(() ())
What is the return value of the code below? (min is a procedure that returns the minimum of two values.)
(define lst ‘(3 5 2 9))
(min (car lst) (cadr lst))
3