code-engine: sh
author: Colin MacDonald
email: colin@bluegraybox.com
title: Erlang Intro
footer:
subfooter:
{% css }
.syntaxhighlighter {
padding: 0.2em 0 0.2em 1em;
margin: 0 0 0 0 !important;
width: 100;
}
.syntaxhighlighter table td.code .line {
padding: 0 0 0 0 !important;
}
.code {
background-color: #DDDDDD;
padding: 1px;
}
.slide h1 {
text-align: left;
color: #FF6633;
}
.codeurl {
color: grey;
font-style: italic;
}
body {
color: grey;
}
small {
color: lightgrey;
}
.author {
color: grey;
font-style: italic;
margin-top: 6em;
}
table.author td {
padding-left: 4em;
}
table.author td:first-child {
padding-left: 0;
}
li.none {
list-style-type: none;
}
a:link, a:visited {
color: grey;
text-decoration: none;
}
.credit, .credit a, .aside {
color: #888;
}
.credit, .credit a {
font-size: medium;
}
.error {
color: red;
}
.bullets.code ul li {
text-align: left;
padding: 10px 25px;
}
{% end %}
!SLIDE
!SLIDE
!SLIDE
f(x)
What does that even mean?
!SLIDE
- 1 + 2 + 3 + 4 + 5 + … + n
- 1 + 2 + 3 + 4 + 5 + … + n
- n(n+1)/2
!SLIDE
- % comment
!SLIDE
- atom
- ‘atom’
- but not “atom”
!SLIDE
- Variable
!SLIDE
- [1, 2, 3] % list
- {1, 2, 3} % tuple
!SLIDE
- [X, Y, Z] = [1, 2, 3]
!SLIDE
- [First, Second | Rest] = [1, 2, 3, 4]
- [First, Second | Rest] = [1, 2]
- [First, Second] = [1, 2, 3, 4](error)
- [First, Second | _ ] = [1, 2, 3, 4]
- [First, Second | _Rest ] = [1, 2, 3, 4]
!SLIDE
{% code lang=erlang line_numbers=false }
my_func(Param1, … ) →
% intermediate stuff
Value.
{% end %}
!SLIDE
{% code lang=erlang line_numbers=false }
f(X) → X * 2.
{ end %}
!SLIDE
!SLIDE
{% code lang=erlang line_numbers=false %}
my_func(Param1) →
my_func(Param1, “default”).
{% end %}
!SLIDE
{% code lang=erlang line_numbers=false %}
my_func([]) → …
{% end %}
!SLIDE
{% code lang=erlang line_numbers=false %}
my_func(0) → …
{% end %}
!SLIDE
{% code lang=erlang line_numbers=false }
if
X >= 100 → 100;
X >= 0 → X;
true → 0
end
{ end %}
!SLIDE
{% code lang=erlang line_numbers=false }
case my_func(X) of
error → [];
List → List
end
{ end %}
!SLIDE
{% code lang=erlang line_numbers=false }
Output = case file:open(Filename, [read]) of
{ok, Handle} →
process_file(Handle);
{error, Reason} →
log_error(Reason, Filename),
[]
end.
{ end %}
- Output = process_file(Handle)
- Output = []
!SLIDE
{% code lang=erlang line_numbers=false %}
#!/usr/bin/escript
{% end %}
!SLIDE
{% code lang=erlang line_numbers=false %}
#!/usr/bin/escript
{% end %}
!SLIDE
!SLIDE
project
action
sub-project
action
action
project
sub-project
sub-project
action
!SLIDE
p=. * work on presentation [computer, quiet] (2011-08-24) !!
!SLIDE
!SLIDE
!SLIDE
!SLIDE
!SLIDE
!SLIDE
!SLIDE
{% code lang=java line_numbers=false }
String[] process(String[] input) {
String[] output = new String[input.length];
for (int i=0; i < input.length; i++) {
output[i] = do_stuff(input[i]);
}
return output;
}
{ end %}
!SLIDE
{% code lang=erlang line_numbers=false }
process([First|Rest], Output) →
NewFirst = do_stuff(First),
process(Rest, [NewFirst|Output]);
{ end %}
!SLIDE
{% code lang=erlang line_numbers=false %}
Output = process(Input, []).
{% end %}
!SLIDE
!SLIDE
!SLIDE
!SLIDE
!SLIDE
!SLIDE
!SLIDE
!SLIDE
{% code lang=erlang line_numbers=false %}
build_nodes([{Content, Indent}|Rest]) →
IsChild = fun({_C, I}) → I > Indent end,
{ChildLines, SiblingLines} = lists:splitwith(IsChild, Rest),
Children = build_nodes(ChildLines),
Siblings = build_nodes(SiblingLines),
[{Content, Children}|Siblings];
{% end %}
!SLIDE
!SLIDE
!SLIDE
{% code lang=erlang line_numbers=false %}
score(Rolls) → frame(Rolls, 1, 0).
{% end %}
!SLIDE
{% code lang=erlang line_numbers=false %}
test() →
test(0, [0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0]),
test(20, [1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1]),
test(150, [5,5, 5,5, 5,5, 5,5, 5,5, 5,5, 5,5, 5,5, 5,5, 5,5, 5]),
test(47, [1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 10, 10 ,9]),
test(173, [7,3, 7,3, 7,3, 7,3, 7,3, 7,3, 7,3, 7,3, 7,3, 7,3, 10]),
{% end %}
!SLIDE
!SLIDE
!SLIDE
!SLIDE
!SLIDE
!SLIDE




























