Chapter 15 Flashcards

1
Q

On what is the imperative language’s design based?

A

On the von Neumann architecture (efficiency)

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

On what is functional languages based?

A

Mathematical functions

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

What is a functional side effect?

A

When a function changes a parameter or global variable

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

What is the problem with functional side effects?

A

Unknown execution

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

How do we solve functional side effects?

A

1: Disallow functional side effect ( no global references in functions. No 2-way parameters)

2: Demand fixed operand evaluation order (Operands are evaluated left to right)

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

What is the good and bad about disallowing functional side effects (no non-local references)

A

Good:….. it works
Bad: Inflexible

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

Bad about a fixed operand evaluation order?

A

Not so good compiler optimizations

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

What is referential transparency?

A

2 expressions are the same and can be substituted without affecting the program

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

What causes 2 expressions to not be referentially transparent?

A

Functional side effects occur during evaluation

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

What is good about referential transparency?

A

Program semantics are much easier to understand (the program is more predictable)

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

What is the effects of a language having no variables? ( pure functional languages ) ( only constants)

A

No global variables
No variables as parameters ( only constants )

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

What is an advantage of pure functional languages?

A

They are 100% referentially transparent

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

What is the problem with imperative languages with regards to purely functional languages?

A

Variable management is a big concern + complexity ( in imperative languages as purely functional languages only have constants )

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

What are the Data object categories in LISP?

A

Only has atoms and lists

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

What are the 2 types of atoms in LISP?

A

Symbols + Numeric

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

What is a List made up of in LISP?

A

Sequence of atoms and/or sublists

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

How is Lists stored in LISP?

A

Single-linked list

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

How does the syntax of a lambda expression look like?

A

(lambda (arg1 … argn) expression)

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

How do you bind a name to a lambda expression in LISP

A

(funcName ( lambda (arg1 …. argn) expression ))

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

What type of scoping does scheme have?

A

Static

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

Re the any operators or control structures in scheme?

A

No

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

What is interactive mode in Scheme?

A

Code line by line via a interface rather than in a editor

23
Q

How are Function evaluated in scheme?

A

parameters = in no particular order ( unless they are functions )
Values of parameters are substituted into the body
Body is evaluated
Last expression evaluated is the value that the function defines

24
Q

Which primitive numeric functions in scheme can accept multiple parameters?

A

abs, sqrt and remainder

25
General forms of define in scheme
1: (define pi 3.14) 2: (define ( square x) ( * x x)) (used like (square 5))
26
Why isnt the first parameter evaluated normally in scheme with define functions?
(define ( square x) (* x x)) square x would be "undefined"
27
How do you print in scheme?
(display expression)
28
What is a predicate function in Scheme?
A function that defines a Boolean value
29
2 way selector in scheme (If statement)
(define (divide numer denom) (if ( <> denom 0)(/numer denom) 0 ))
30
Multiple selector in Scheme
(cond (predicate1 expression)(predicate2 expression) ..... )
31
What does the quote primitive function do
Avoid parameter evaluation '(A B)
32
What does the list function do?
yields a list with the parameters as elements (list 'A 'B 'C) == (A B C) (list 'A 'B '(C D)) == (A B (C D))
33
what does the car function do in scheme?
yields the 1st element in a list (car '(A B C)) == A (car '((A B) C D)) == (A B)
34
What does cdr do in Scheme?
Removes the 1st element in the list and returns the rest (cdr (A B C)) == (B C) (cdr ((A B) C D)) == (C D)
35
What does cons do in Scheme?
takes 1st parameter and adds it to the 2nd (cons 'A '(B C)) == (A B C) (cons '(A B) '(C D)) yields ((A B) C D) (cons 'A 'B) == (A . B) (cons '(A B) 'C) == ((A B) .C)
36
What does list? do in scheme?
returns #t if it is a list and #f if its not a list
37
What does null? do in scheme?
returns #t if it is a empty list and #f otherwise () == #t (()) == #f ( its not completely empty )
38
What does eqv? do in scheme?
check if 2 *values* are the same ( doesnt work for lists ) (eqv? 3 3) yields #t (eqv? 'A 'A) yields #t (eqv? '(A B) '(A B)) yields #f
39
what does eq? do in scheme?
Check if the 2 parameters are the same object in memory (pointer comparison) (but not reliable for 2 lists + numeric atoms (eq? 'A 'A) yields #t (eq? 'A 'B) yields #f (eq? 'A '(B C)) yields #f
40
General let format in scheme
(let ( (name_1 expression_1) (name_2 expression_2) ... (name_n expression_n) ) body )
41
What does let function yield?
the value of the body
42
Can multiple functions be inside the body in Scheme?
Yes
43
What does member do in Scheme?
Check if the 1st parameter is a member of the 2nd parameters list
44
What does equalsimp do in scheme?
Checks if one list is equal to the other
45
what does equal doe in scheme?
Checks if 2 lists are equal
46
How does equalsimp and equal differ?
equal compares atoms and lists. equal compares list element pairs
47
What does append do in scheme?
yields a new list containing the elements of list one followed by list2
48
When a function a tail recursive function?
When the recursive call is the last operation in the function
49
if facthelper is a function is this tail recursive? (facthelper (- n 1) (* n partial))
no cause ( * n partial) is the final operation taking place
50
What does mapcar do?
Applies a function to a list (mapcar (lambda (num) (* num num)) '(3 4 2 6)) (lambda (num) (* num num)) = function
51
What is meant by "a scheme function can build scheme code"
Scheme treats code as data hence it can create, manipulate, and execute code. Functions can be represented as lists
52
What is functional language applications used for?
ML Natural language processing Modelling of speech and vision
53
Difference between functional and imperative languages?
Imperative: efficient execution, complex semantics + syntax functional: Simple semantics + syntax, inefficient execution