Chapter 15 Flashcards

1
Q

What is imperative language design based on?

A

von Neumann architecture with efficiency as primary concern

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

What is functional language design based on?

A

Mathematical functions

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

What are functional side effects?

A

When a function changes a parameter or a 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

Unpredictable, Concurrency issues

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

How to solve functional side effects?

A

1) No 2 way parameters, No non-local references in functions. but it is very inflexible

2) Demand fixed operand evaluation order. limits some complier optimizations

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

When does a program have referential transparency?

A

Any 2 expressions that are equivalent can be substituted for one another and it doesn’t affect the action.

There are no functional side effects

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

What is the advantage of referential transparency?

A

semantics are easier to understand

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

Are Pure Functional Languages referentially transparent? and why?

A

Yes. No global variables. parameter values are constants. functions cannot have state, value of function depends only on parameters

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

What is the objective of functional language designs?

A

mimic math functions as closely as possible

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

What are the LISP Data Objects and Structures?

A

Only consists of atoms and lists

2 types of atoms (symbols and numeric literals)

List = sequence of atoms or sublists

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

What does Scheme and Lisp have in common?

A

They use the same atoms and lists

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

What is Scheme interpreter interactive mode?

A

Mode that allows you to type code in line by line rahter than programming in an editor

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

Scheme interpreter is just a Scheme function?

A

Yes

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

How are functions evaluated?

A

Parameters (in no order)
values of parameters substituted into the function body
Value of last expression evaluated in the body is the value that the function defines

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

What are the Primitive Numeric Functions

A

+,-,*,/,abs,sqrt,remainder,min,max

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

Which primitive numeric functions cannot accept multiple parameters?

A

abs,sqrt,remainder

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

What are lambda functions used for?

A

Nameless functions

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

how many parameters can lambda functions have?

A

any number of parameters

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

how do you bind names to lambda expressions?

A

(define (square x) (* x x))

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

how do you bind a name to the value of an expression

A

(define pi 3.142) or (define two_pi (* 2 pi))

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

Hoe is the evaluation process for defined different?

A

Since the 1st parameter is a name and not a parameter it is not evaluated (otherwise it would be evaluated as undefined)

22
Q

How do you output a expression in Scheme?

A

(display expression)

23
Q

what is used for true and false in scheme?

A

t and #f (or () for false)

24
Q

What are the predicate values for numbers with multiple parameters?

A

=, <>, > ,<, >= and <=

25
Q

Predefined predicate functions for numbers, single value test.

A

even?,odd?,zero?,negative?,positive?

26
Q

what does <> mean?

A

not equals

27
Q

how does a if function look like?

A

(if predicate then_exp else_exp)
example
(define (divide number denom)
(if (<> denom 0)
(/ number denom) // returns this if true
0 // returns this if false
)
)

28
Q

what is the cond function?

A

conditional control flow function

29
Q

how does the cond function work?

A

“Accepts” the 1st expression that evaluates to true.
if no expression is true it goes to the else expression if there is one

30
Q

how is repetition handled?

A

through recursion

31
Q

how is a list created?

A

‘(A B) or (quote (A B))

32
Q

how does “list” work in scheme?

A

(list ‘A ‘B ‘C) yields (A B C)
(list ‘A ‘B ‘(C D)) yields (A B (C D ))

33
Q

How do you get the 1st element of a list?

A

(car list)

34
Q

how do you get the remainder of a list after its 1st element has been removed?

A

(cdr list)

35
Q

what does cons do?

A

outs the 1st oarameter into the 2nd parameter (a list) to make a new parameter

36
Q

examples of cons

A

(cons ‘A ‘(B C)) = (A B C)
(cons ‘(A B) ‘(C D)) = ((A B) C D)
(cons ‘() ‘(A B)) = (() A B)
(cons ‘A ‘B) = (A . B)
(cons ‘(A B) ‘C) = (( A B) .C)

37
Q

How many parameters does list? take?

A

1

38
Q

What does the null? predicate function do?

A

Checks if the list is empty ( (()) is not an empty list)

39
Q

what does eqv? do?

A

checks if 2 values are the same.
Doesnt work for lists but does work for (eqv? ‘A ‘A)

40
Q

what does eq? check?

A

if the 2 parameters are the same object in memory (for 2 list parameters or numeric atoms the result is not reliable)

41
Q

What is the general form of let?

A

(let ((name1 exp1)(name2 exp2))body that uses the names in the bindings)

42
Q

what does the let construct yield?

A

the value of the last application

43
Q

What does the member function do?

A

Checks if an atom is in a simple list

44
Q

With which function do you check if 2 lists are equal?

A

equalsimp

45
Q

how is equal different from equalsimp?

A

equalsimp = atoms, equal = atoms + lists

46
Q

What does (append lis1 lis2) yield?

A

all elements of list 1 followed by all elements of list 2

47
Q

When is a recursive function tail recursive?

A

When the recursive call is the last operation in the function

48
Q

What does mapcar do?

A

“Does” the function to everything in the list
(define (add-two number)
(+ number 2))

(mapcar add-two ‘(1 3 5 7))

results in (2 5 7 9)

49
Q

What is a function that builds code

A

A function that can build code that can be executed

50
Q

What is LISP used for?

A

AI

51
Q

What is scheme used for?

A

To teach intro to programming

52
Q
A