what the c?
TRANSCRIPT
C1998
Coolest Hottest Language was ….
Javabut learning C was like learning ABCs
And not very hip companies were making websites in it.
Really!
Ctoday
what is done with it
utilities
git, bash, diff …
language extensions: JSON, ruby => nokogiri
languages!
Dynamic Languages in
CExtends what C programmers have always done
Bend the mind
Allow unknowns at Runtime
to be compiled into extensible ideas
C Building Blocks
int counts[3];
char string[6];
Limitations:• variables can’t be asked about size
• variables can’t be asked about type
• variables can’t be increased
by just adding values beyond declaration
C Building Blocks
Dynamic Array:
Limitation:
• shift/unshift operations costly
• insert in middle inefficient
Benefit:
• efficient modification to end
• easy value extraction from an index
• easy value addition at a particular index
C Building Blocks
Linked Lists:
typedef struct List {
int length;
struct Node *first;
struct Node *last;
} List;
typedef struct Node {
void *value;
struct Node *prev;
struct Node *next;
} Node;
C Building Blocks
Linked Lists (double):
Limitation:
• can’t easily traverse to particular index
Benefits:
• insert anywhere
• easy add to beginning
C Building Blocks
Hash (combining lots):
// javascript
obj = {“hello”: “world”};
obj[‘hello’] // returns “world”
Also called dictionary & map
C Building Blocks
Hash (combining lots):
length: 4
capacity: 5
values: [ ]
dynamic array
of
dynamic arrays
C Building Blocks
Given: string key & value to set
[ ]
dynamic array
of
dynamic arrays
• key converted to hash (long int)
• take modulo of hash to find a bucket
(top level location)
• node has ref to
• original key
• and hash
• and value
• node is shoved into bucket
How to make a
language
1. Lex: convert string to tokens
2. Parse: build a syntax tree from tokens
3. Interpret: evaluate the syntax tree
ParsingConverting 1d array into a tree
<integer 1> <id ‘+’> <id ‘x’>
(method_call,
(receiver, (literal, <integer 1>)),
(message, (lookup, <id ‘+’>)),
(arguments, (lookup, <id ‘x’>))
)
Interpretatio
nTaking the tree expression
and executing it as code!
(method_call,
(receiver, (literal, <integer 1>)),
(message, (lookup, <id ‘+’>)),
(arguments, (lookup, <id ‘x’>))
)
• Find or build literal integer `1`
• Use Integer class to lookup `+`
method
• lookup in nested contexts id `x`
• Call `+` method on integer object
`1` with lookup value of x as
argument
FAUXY!
Faux Objects
Faux Functional
Concurrent
Dynamic
Statically typed and immutable!
with Pattern Matching/Multiple Dispatch
FAUXY!
Faux Objects
Faux Functional
Concurrent
Dynamic
Statically typed and immutable!
with Pattern Matching/Multiple Dispatch
NumberToWords.Digit: Class.new(n) -> {
to-words: -> { convert(n) }
convert: -> (n: 1) { 'one' }
convert: -> (n: 2) { 'two' }
convert: -> (n: 3) { 'three' }
convert: -> (n: 4) { 'four' }
convert: -> (n: 5) { 'five' }
convert: -> (n: 6) { 'six' }
convert: -> (n: 7) { 'seven' }
convert: -> (n: 8) { 'eight' }
convert: -> (n: 9) { 'nine' }
}
Attribution
• Assembly Example: homepage.cs.uri.edu
• Women using punchcards: en.wikipedia.org