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
how would you use filter in SML
Usage: filter (fn n => n mod 2 = 0); filter (fn n => n mod 2 = 0) [1,2,3,4,5];
26
how would you use foldL / foldR in SML
(* Sum of all elements in a list *) val sum = foldl (fn (x, acc) => x + acc) 0 [1, 2, 3, 4] (* Result: 10 *)
27
what does static mean in java
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
what is garbage collection
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
explain marking and sweeping
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
what is parent(eric, carson). what is eric what is carson
parent(eric, carson) is a fact eric and carson are atoms
31
how to identify atom vs variable
lowercase is atom uppercase is variable
32
what is ?- parent(eric, jenna). true.
a goal it asks is this true or can you make it true
33
what is grandparent(G, C) :- parent(G, P), parent(P, C).
a rule
34
what is a functor
a compoud data object that holds data together can be dynamic
35
what is the number of arguments of a functor called?
the functors arity
36
what does = do in prolog
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
what is ! in prolog
the cut operator. It stops the search after a successful unity
38
where does the assembly code live for the JVM
in class files the class file is binary so not text but a series of bytes hence the name "bytecode"
39
what is the left side called and what is the right side called aload 1
left side is opcode right side is operand
40
what is the type for String
Ljava/lang/String
41
what is the magic number
0xCAFEBABE
42
is damlang statically typed or dynamically typed
dynamically it is implemented using a statically typed lang (java)
43
what are the 2 types of parsers
top down (LL1) and bottom up (LALR1)
44
what does LL1 mean
L Left-to-right scanning L While doing left-most derivation 1 only 1 symbol of lookahead is needed to chose next production
45
what does LALR1 mean
LA LookAhead LR Input scanned L-to-R w/ right-most derivation 1 1 symbol lookahead
46
is this LL1 or LALR1 5.* 4 + 3 T
LALR1
47
does LL1 or LALR1 have the tree
LL1