CS152 Midterm Study Guide

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/138

encourage image

There's no tags or description

Looks like no tags are added yet.

139 Terms

1
New cards

key traits of scheme

functional, dynamically typed, minimal, lists

2
New cards

what is scheme?

functional and minimal language; dialect of Lisp

3
New cards

Lisp

list processing language

4
New cards

racket simple data types

booleans, numbers, characters

5
New cards

racket compunds data types

strings, pairs, lists

6
New cards

s-expressions

simple and compound data types

7
New cards

cons

makes a pair from a obj and a list

8
New cards

append

puts together 2 lists

9
New cards

car

get head of list

10
New cards

cdr

get tail of list

11
New cards

list

a pair made of "head of list" and "tail of list"

12
New cards

head of list

first obj in list

13
New cards

tail of list

list containing everything except head

14
New cards

keyword define

defines a global variable

15
New cards

keyword displayln

displays value

16
New cards

let*

allows previous variable definitions to be used in following variable definitions

17
New cards

letrec

allows later variable definitions to use previous variable definitions

18
New cards

lamdas can be used like

functions

19
New cards

alternate format for (define square (lambda (x) (* x x)))

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

20
New cards

higher-order function

function that takes functions as arguments; returns a function as its result; dynamically construct new functions

21
New cards

when the second item of cons is not list, will create a pair (T/F)

T

22
New cards

recursion consists of

base case, recursive step

23
New cards

base case

when to stop

24
New cards

recursive step

calls function with a smaller version of the same problem

25
New cards

goal of recursive step

to move the problem closer to the base case

26
New cards

in tail recursion,

the recursive call is the last step performed before returning a value

27
New cards

functional languages

treat programs as mathematic functions

28
New cards

qualities of functional programming

functions clearly distinguish input from outputs, result depend only on input values, no assignments or loops

29
New cards

most important feature of functional programming

functions are first class values/objects

30
New cards

functions are first class values/objects

functions can be treated as any other value

31
New cards

referential transparency

abiility to replace an expression with its value, write code free of side-effects

32
New cards

packages

provide units of code

33
New cards

exports

specify public values

34
New cards

imports

specify code dependencies

35
New cards

keyword provide

specifies public values

36
New cards

keyword require

specifies code dependencies

37
New cards

structures

allow us to create more sophisticated data structures

38
New cards

keyword match

access to structure by destructuring

39
New cards

hash

map of key/value pairs

40
New cards

Scheme hashes are immutable (T/F)

T

41
New cards

Java lambdas only close over values, not variables (T/F)

T

42
New cards

supplier interface parameter and return types

none; T

43
New cards

consumer interface parameter and return types

T; void

44
New cards

biconsumer interface parameter and return type

T, U; void

45
New cards

predicate interface parameter and return type

T; boolean

46
New cards

stream API

pipeline of collection of objects and methods returned as stream

47
New cards

exception handling

unwinds the stack and transfers control possibly to a different function/file

48
New cards

setjmp

sets a "bookmark" in the code

49
New cards

longjmp

returns to bookmark

50
New cards

goto in C

allows execution to jump to any point within function

51
New cards

setjmp(jmp_buf env)

bookmarks point in code by saving current execution context into a buffer

52
New cards

longjmp(jmp_buf env, int val)

returns back to setjmp location, replaces setjmp call with given value and restores execution context

53
New cards

continuations

"the rest of the program"

54
New cards

components of continuation

return point, call stack, remainder of program

55
New cards

keyword call/cc

"bookmarks" location in code, saves current execution state, invokes lambda function with continuation

56
New cards

contracts

establishes who is to blame when something goes wrong by setting responsibilies for each party to guarantee what to expect from others

57
New cards

preconditions

requirements for the input

58
New cards

postconditions

promises for the output

59
New cards

holds blame for failing preconditions

caller

60
New cards

holds blame for failing postconditions

library

61
New cards

blaming

error message to indicate which file broke contract

62
New cards

how is type checking different from contracts?

enforcement at compile time, less flexible, and less runtime overhead

63
New cards

how are contracts different from type checking?

enforcement at run time, more flexible, more runtime overhead

64
New cards

flat contracts

simple predicates

65
New cards

contract combinator

function that combines contracts to make new contracts

66
New cards

examples of contract combinators

and/c; listof; cons/c

67
New cards

what is the benefit to using contracts on functions?

able to catch internal errors

68
New cards

what is the drawback to using contracts on functions?

repeats checking of contracts, especially in recursive functions

69
New cards

Programming contracts are useful for estabilishing blame when things go wrong (T/F)

T

70
New cards

If a precondition is not satisfied, then the library writer is at fault for any errors (T/F)

F

71
New cards

Contracts may only be specified on modules (T/F)

F

72
New cards

Specifying a contract for a function is more efficient than specifying one for a module, since it avoids repeated checks on the contract for a recursive call (T/F)

F

73
New cards

In Racket, the ->i operator is used to specify contracts on functions where the validity of the arguments or result depend on each other (T/F)

T

74
New cards

syntax

structure of a program

75
New cards

semantics

meaning of a program

76
New cards

2 aspects of a language

syntax; semantics

77
New cards

2 parts of syntax

lexemes or tokens; grammar

78
New cards

lexemes or tokens

"words" of the language

79
New cards

grammar

the way that words can be ordered

80
New cards

what does the lexer/tokenizer do?

filters out spaces and comments

81
New cards

what does the parser do?

filters out syntax sugar

82
New cards

input of lexer/tokenizer

source code

83
New cards

input of parser

tokens

84
New cards

output of lexer/tokenizer

keywords, literals, valid variables

85
New cards

output of parser

abstract syntax tree

86
New cards

types of tokens

identifiers, numbers, reserved words, special characters

87
New cards

AST

abstract syntax tree

88
New cards

use of ASTs

meaning is derived by compilers and interpreters to turn programs into actions

89
New cards

example of syntactic sugar

y++ => y + y

90
New cards

The job of a parser is to take in tokens and produce an abstract syntax tree (AST) (T/F)

T

91
New cards

Abstract syntax trees are sometimes called "lexemes" (T/F)

F

92
New cards

Tokens may be though of as the "words" of a language (T/F)

T

93
New cards

Once an abstract syntax tree is produced, it is only useful for evaluations by an interpreter; for efficiency, compilers typically work directly from the stream of tokens (T/F)

F

94
New cards

A transpiler is a compiler that translates one high-level language to another (T/F)

T

95
New cards

Louden & Lambert's Design Criteria

efficiency, regularity, security, extensibility

96
New cards

efficiency

machine efficiency, programmer efficiency, reliability

97
New cards

machine efficiency

tips to the compiler

98
New cards

programmer efficiency

writing speed, expressive, concise

99
New cards

reliability

code maintenance

100
New cards

regularity

generality, orthogonal design, uniformity