Final Flashcards

1
Q

Imperative Programming

A

Fundamental operation is the assignment statement

Control flow is dependent on the values of variables

Interpretation of code depends on program state

relies on side effects

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

Functional Programming

A

Principal operation is function application (function calls)

functions bay be passed as arguments to other functions

Functions may be returned by functions

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

Side effect

A

When a function relies on, or modifies, something outside its parameters to do something.

A function is pure if given the same inputs it:
- always returns the same output
- does not have any side effects

more difficult to reason about a program the relies on side effects

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

Compiler

A

source to machine code to run later

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

interpreter

A

source to run now

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

transpiler

A

source to source

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

syntax

A

How a program looks. Is specified / validated by a grammar

A program is syntactically valid if there is a parse tree
for the given grammar

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

Semantics

A

what a program does

what a program means

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

Sentence ( of grammar)

A

string of tokens from the grammar

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

Sentential form

A

String of terminals & non terminals from the grammar

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

derivation

A

sequence of sentential forms that starts with start symbols & ends with a sentence

a sentence is valid if there exists at least one derivation for it

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

grammar

A

A set of instructions about how to write statements that are valid for that programming language.

Grammars consist of
* Non-terminals (or “syntactic categories”)
* Terminals
* Productions
* A start symbol/non-terminal

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

Abstract Syntax Tree

A

A data structure that represents the text of a program

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

Lexer

A

A program that takes source code & turns it into a stream of tokens

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

Parser / Parsing

A

process of detecting whether a stream of tokens is a valid sentence in a grammar.

if fails : syntax error
if pass : return AST

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

what is produced by a parser

A

AST

Abstract Syntax Tree

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

briefly explain when type errors occur in different languages

A

statically typed: c, c++, java
- compile time

dynamically typed: python, ruby
- runtime

bonus:

SML cannot have runtime type errors

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

explain the difference between java and python

A

java is statically typed
variables have types

python is dynamically typed
variables have values. The values have types

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

HOF functions

A

Can take functions as parameters.
Can “build” functions that can be returned.
Functions can be “curried.” (built 1 param at a time)

Common HOFs

map, reduction (reduce, foldl, foldr), filter

20
Q

map

A

transform a list that looks one way into a list that looks a different way

uses a unary function

21
Q

filter

A

shrink a list

exclude certain values or include certain values

uses a unary function

22
Q

reduce

A

combine a list into 1 value

uses a binary function

23
Q

how would you use map

A
  • map (fn x => x * 2) [1, 2, 3, 4];

val it = [2,4,6,8] : int list

24
Q

polymorphism

A

Allows objects of different classes to be treated as objects of a common superclass. This enables a single action to behave differently based on the object it is acting upon.

25
Q

how would you use filter in SML

A

Usage:

filter (fn n => n mod 2 = 0);
filter (fn n => n mod 2 = 0) [1,2,3,4,5];

26
Q

how would you use foldL / foldR in SML

A

(* Sum of all elements in a list )
val sum = foldl (fn (x, acc) => x + acc) 0 [1, 2, 3, 4] (
Result: 10 *)

27
Q

what does static mean in java

A

means that whatever is static belongs to the class not to any specific instance of the class

you don’t need to instantiate the class (make an Object based on your class) to use a static method.

28
Q

what is garbage collection

A

automatic memory management process that manages memory by identifying and reclaiming memory no longer in use

prevents memory leaks

is a part of JVM runtime (not compiler)

29
Q

explain marking and sweeping

A

marking is when during GC, all objects still being referenced are marked

if a object survives long enough is is promoted to the next generation

the GC then sweeps through the heap looking for memory to reclaim

30
Q

what is parent(eric, carson).

what is eric
what is carson

A

parent(eric, carson) is a fact

eric and carson are
atoms

31
Q

how to identify atom vs variable

A

lowercase is atom

uppercase is variable

32
Q

what is
?- parent(eric, jenna).
true.

A

a goal

it asks is this true or can you make it true

33
Q

what is

grandparent(G, C) :- parent(G, P), parent(P, C).

A

a rule

34
Q

what is a functor

A

a compoud data object that holds data together

can be dynamic

35
Q

what is the number of arguments of a functor called?

A

the functors arity

36
Q

what does = do in prolog

A

it is a combination of assingment and equality depending on what the left and right side are

free vs bound (variable vs atom)

if both sides are bound check equal
if one side is free, assign to match other side
if both are free assignment is remembered and eventuyally verified

37
Q

what is ! in prolog

A

the cut operator. It stops the search after a successful unity

38
Q

where does the assembly code live for the JVM

A

in class files

the class file is binary so not text but a series of bytes

hence the name “bytecode”

39
Q

what is the left side called and what is the right side called

aload 1

A

left side is opcode

right side is operand

40
Q

what is the type for String

A

Ljava/lang/String

41
Q

what is the magic number

A

0xCAFEBABE

42
Q

is damlang statically typed or dynamically typed

A

dynamically

it is implemented using a statically typed lang (java)

43
Q

what are the 2 types of parsers

A

top down (LL1)

and

bottom up (LALR1)

44
Q

what does LL1 mean

A

L Left-to-right scanning

L While doing left-most derivation

1 only 1 symbol of lookahead is needed to chose next production

45
Q

what does LALR1 mean

A

LA LookAhead

LR Input scanned L-to-R w/ right-most derivation

1 1 symbol lookahead

46
Q

is this LL1 or LALR1

5.* 4 + 3 T

A

LALR1

47
Q

does LL1 or LALR1 have the tree

A

LL1