Ch 4 Flashcards

1
Q

In Scheme, the primitive (char? “%\A”) will return…

A

f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

(member ‘2 ‘(3 4 2 1)) will return…

A

(2 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

(caddr ‘(2 4 6 8 10)) will return…

A

6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The most efficient way, in terms of the execution time, to check whether a list L is empty is by…

A

(NULL? L)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following forms is an unnamed procedure?

(+ z 3)

((lambda (z) (+z 3)) 4)

(define foo (lambda (z) (+ z 3)))

(define bar 25)

None of them

A

((lambda (z) (+ z 3)) 4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Eager evaluation evaluates…

A

all parameters of a function first.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Lazy evaluation evaluates…

A

a parameter of a function only if it is necessary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In “imperative” programming languages, different orders of evaluations (eager or lazy)…

A

may produce different results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In “functional” programming languages, different orders of evaluations (eager or lazy)…

A

never produce different results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Each let-form in Scheme can be converted into…

A

an unnamed procedure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Assume that you have (define x ‘(5)) and (define y ‘(8 9)). What operation will return the list (5 8 9)?

A

(append x y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which of the followings is NOT a Scheme pair?

A

’()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the return value of the following form?
(filter (lambda (x) (> x 20)) ‘(10 30 15 10 80))

A

(30 80)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A deep-filter can be used in the situation where the list…

A

contains sublists.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the return value of the following form?
(map (lambda (x) (+ x 10)) ‘(10 30 15))

A

(20 40 25)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In Scheme, an empty list is…

A

not a pair.

17
Q

What mechanism cannot be used for passing a value into a Scheme procedure?

A

Call-by-alias

18
Q

How is a procedure name (operator) passed into a procedure?

A

Call-by-name

19
Q

If you want to return multiple values from a Scheme procedure, which of these methods is invalid?

A

Use multiple return-statements.

20
Q

Normally, a recursive procedure can be written following these steps: Define the size-n problem, find the solution for the base case or the stopping condition, and then find…

A

the solution of the size-n problem based on the hypothetical solution of the size-(n-1) problem.

21
Q

In the Functional Paradigm, what are functions treated as?

A

First-class objects. They can be placed anywhere where a value is expected.

22
Q

From what programming language is Scheme derived?

A

LISP

23
Q

What order to eager and lazy evaluation, evaluate parameters?

A

Eager - innermost first

Lazy - outermost first

24
Q

What are the three parts of defining a procedure in Scheme?

A

Define, Name and parameters, Argument

(define (<name><parameters>) <body>)</parameters></name>

25
Q

How should procedures and variables be named in Scheme?

A

With lower case words separated by dashes.

26
Q

What are the basic data types in Scheme?

A

Number - includes integers and floats
String - uses “ “
Symbol - uses a single ‘
List - can be a list of elements of any type ‘(2 5 5 Hi Jim (5 9) “Hello”)

27
Q

What is the difference between “James” and ‘James ?

A

“James” is a string.
‘James is a symbol.

28
Q

What C or C++ structure is closest to resembling a Scheme Symbol?

A

enum

29
Q

Lists in Scheme are just…

A

parameterized expressions.

30
Q

In Scheme, the primitive (char? #\A) will return…

A

t

must be #, not %
must not have “ “

31
Q

What does (char=? #\A #\a) return?

A

f

characters must be identical for (char=?

32
Q

What does (char=? #\A #\A) return?

A

t

because characters are identical

33
Q

What must we always have in a Functional language?

A

A return value.