Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changed the : separator to call a function in a module to . to make i…

…t more js like

changed the examples and updated the website
  • Loading branch information...
commit 134883f474044b463b0b89726b84923a2b9cfed1 1 parent c3c61ae
@marianoguerra marianoguerra authored
View
12 examples/arraycb.fn
@@ -11,12 +11,12 @@ squares1 = fn (Numbers) {
# functional form
squares2a = fn (Numbers) {
- lists:map(fn (N) { square(N); }, Numbers);
+ lists.map(fn (N) { square(N); }, Numbers);
};
# functional form with lambda
squares2b = fn (Numbers) {
- lists:map(fn (N) { N * N; }, Numbers);
+ lists.map(fn (N) { N * N; }, Numbers);
};
# no need for a function
@@ -26,9 +26,9 @@ squares3 = fn (Numbers) {
run = fn () {
Numbers = [1, 3, 5, 7];
- io:format("squares1 : ~p~n", [squares1(Numbers)]);
- io:format("squares2a: ~p~n", [squares2a(Numbers)]);
- io:format("squares2b: ~p~n", [squares2b(Numbers)]);
- io:format("squares3 : ~p~n", [squares3(Numbers)]);
+ io.format("squares1 : ~p~n", [squares1(Numbers)]);
+ io.format("squares2a: ~p~n", [squares2a(Numbers)]);
+ io.format("squares2b: ~p~n", [squares2b(Numbers)]);
+ io.format("squares3 : ~p~n", [squares3(Numbers)]);
};
View
4 examples/binary.fn
@@ -1,8 +1,8 @@
match = fn (<[A:8 unsigned little integer, B:4, C:2, D]>) {
- io:format("match: ~p ~p ~p ~p~n", [A, B, C, D]);
+ io.format("match: ~p ~p ~p ~p~n", [A, B, C, D]);
}
(Other) {
- io:format("other: ~p~n", [Other]);
+ io.format("other: ~p~n", [Other]);
};
run = fn () {
View
11 examples/code.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env sh
+echo "<html><head><style>" > code.html
+
+pygmentize -f html -S colorful >> code.html
+
+echo "</style></head><body>" >> code.html
+
+for file in $(ls *.fn); do echo "<h2>$file</h2>" >> code.html; pygmentize -f html $file >> code.html; done
+
+echo "</body></html>" >> code.html
+
View
4 examples/concat.fn
@@ -2,8 +2,8 @@
run = fn () {
S = "hello";
- io:format("~s~n", [S ++ " lite" ++ "ral"]);
+ io.format("~s~n", [S ++ " lite" ++ "ral"]);
S1 = S ++ " lite" ++ "ral";
- io:format("~s~n", [S1]);
+ io.format("~s~n", [S1]);
1 + 2; # just to test that the ++ doesn't break the +
};
View
2  examples/concurrent.fn
@@ -2,7 +2,7 @@ is_zero = fn (0, FunTrue, _) { FunTrue(); }
(_, _, FunFalse) { FunFalse(); };
say = fn (Pid, Str) {
- io:fwrite("~s~n", [Str]);
+ io.fwrite("~s~n", [Str]);
Pid ! done;
};
View
8 examples/evennums.fn
@@ -1,7 +1,7 @@
# http://rosettacode.org/wiki/Select_from_Array
even1 = fn (Numbers) {
- lists:filter(fn (N) { N % 2 == 0; }, Numbers);
+ lists.filter(fn (N) { N % 2 == 0; }, Numbers);
};
even2 = fn (Numbers) {
@@ -9,7 +9,7 @@ even2 = fn (Numbers) {
};
run = fn () {
- Numbers = lists:seq(1, 15);
- io:format("even1: ~p~n", [even1(Numbers)]);
- io:format("even2: ~p~n", [even2(Numbers)]);
+ Numbers = lists.seq(1, 15);
+ io.format("even1: ~p~n", [even1(Numbers)]);
+ io.format("even2: ~p~n", [even2(Numbers)]);
};
View
2  examples/expressions.fn
@@ -2,7 +2,7 @@
run = fn () {
Print = fn (Expr) {
- io:format("~p~n", [Expr]);
+ io.format("~p~n", [Expr]);
};
Print(1 + 2 * 3 + 4);
View
8 examples/numbers.fn
@@ -1,7 +1,7 @@
run = fn () {
- io:format("0xff : ~B~n", [0xff]);
- io:format("0xFF : ~B~n", [0xFF]);
- io:format("0o777 : ~B~n", [0o777]);
- io:format("0b1011: ~B~n", [0b1011]);
+ io.format("0xff : ~B~n", [0xff]);
+ io.format("0xFF : ~B~n", [0xFF]);
+ io.format("0o777 : ~B~n", [0o777]);
+ io.format("0b1011: ~B~n", [0b1011]);
};
View
8 examples/pythag.fn
@@ -1,11 +1,11 @@
# http://rosettacode.org/wiki/List_Comprehension
pythag = fn (N) {
- [(A, B, C) for A in lists:seq(1, N)
- for B in lists:seq(A, N)
- for C in lists:seq(B, N)
+ [(A, B, C) for A in lists.seq(1, N)
+ for B in lists.seq(A, N)
+ for C in lists.seq(B, N)
if A + B + C <= N and A * A + B * B == C * C];
};
run = fn () {
- io:format("~p~n", [pythag(20)]);
+ io.format("~p~n", [pythag(20)]);
};
View
2  examples/send.fn
@@ -1,7 +1,7 @@
loop = fn () {
receive (Stuff) {
- io:format("~p~n", [Stuff]);
+ io.format("~p~n", [Stuff]);
};
loop();
};
View
6 examples/sleep.fn
@@ -1,7 +1,7 @@
# http://rosettacode.org/wiki/Sleep_the_Main_Thread
run = fn () {
- io:format("Sleeping...~n");
- timer:sleep(1000); # in milliseconds
- io:format("Awake!~n");
+ io.format("Sleeping...~n");
+ timer.sleep(1000); # in milliseconds
+ io.format("Awake!~n");
};
View
10 examples/trycatch.fn
@@ -4,16 +4,16 @@ trycatch = fn (Arg){
make_error(Arg);
}
catch (throw 1) {
- io:format("throw 1~n");
+ io.format("throw 1~n");
}
(exit 2) {
- io:format("exit 2~n");
+ io.format("exit 2~n");
}
(error (some, fancy, tuple, 3)) {
- io:format("error~n");
+ io.format("error~n");
}
finally {
- io:format("finally~n");
+ io.format("finally~n");
};
};
@@ -24,7 +24,7 @@ make_error = fn (1) {
exit(2);
}
(3) {
- erlang:error((some, fancy, tuple, 3));
+ erlang.error((some, fancy, tuple, 3));
};
run = fn () {
View
4 src/lexer.xrl
@@ -33,8 +33,8 @@ End = ;
UnaryOp = (not|~)
% the string stuff taken from Reia
String = "(\\\^.|\\.|[^\"])*"
-Rtl = <-
Split = :
+Dot = \.
Rules.
@@ -65,13 +65,13 @@ Rules.
{Sep} : {token, {sep, TokenLine, list_to_atom(TokenChars)}}.
{End} : {token, {endl, TokenLine, list_to_atom(TokenChars)}}.
{Match} : {token, {match, TokenLine, list_to_atom(TokenChars)}}.
-{Rtl} : {token, {rtl, TokenLine, list_to_atom(TokenChars)}}.
{Identifier} : {token, {var, TokenLine, list_to_atom(TokenChars)}}.
{Atom} : {token, atom_or_identifier(TokenChars, TokenLine)}.
& : {token, {and_op, TokenLine, list_to_atom(TokenChars)}}.
! : {token, {send_op, TokenLine, list_to_atom(TokenChars)}}.
\^ : {token, {xor_op, TokenLine, list_to_atom(TokenChars)}}.
{Split} : {token, {split_op, TokenLine, list_to_atom(TokenChars)}}.
+{Dot} : {token, {dot, TokenLine, list_to_atom(TokenChars)}}.
{White}+ : skip_token.
{Comment} : skip_token.
{String} : build_string(string, TokenChars, TokenLine, TokenLen).
View
7 src/parser.yrl
@@ -10,8 +10,8 @@ Nonterminals
Terminals
comp_op add_op mul_op unary_op match var open close fn sep open_list
close_list open_block close_block open_bin close_bin integer float boolean
- endl atom string concat_op and_op xor_op or_op shift_op send_op rtl
- split_op if try catch finally receive after bool_and_op bool_or_op.
+ endl atom string concat_op and_op xor_op or_op shift_op send_op
+ split_op dot if try catch finally receive after bool_and_op bool_or_op.
Rootsymbol grammar.
@@ -89,8 +89,7 @@ literal -> recv_expr : '$1'.
function_call -> var call_params : {call, line('$1'), '$1', '$2'}.
function_call -> atom call_params : {callatom, line('$1'), ['$1'], '$2'}.
-function_call -> atom rtl atom call_params : {callatom, line('$2'), ['$3', '$1'], '$4'}.
-function_call -> atom split_op atom call_params : {callatom, line('$2'), ['$1', '$3'], '$4'}.
+function_call -> atom dot atom call_params : {callatom, line('$2'), ['$1', '$3'], '$4'}.
function_call -> function_call call_params : {call, line('$1'), '$1', '$2'}.
call_params -> open call_arguments close : lists:flatten('$2').
View
84 www/index.html
@@ -139,12 +139,12 @@
<span class="c"># functional form</span>
<span class="nx">squares2a</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">(</span><span class="nx">Numbers</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">lists</span><span class="o">:</span><span class="nx">map</span><span class="p">(</span><span class="k">fn</span> <span class="p">(</span><span class="nx">N</span><span class="p">)</span> <span class="p">{</span> <span class="nx">square</span><span class="p">(</span><span class="nx">N</span><span class="p">);</span> <span class="p">}</span><span class="o">,</span> <span class="nx">Numbers</span><span class="p">);</span>
+ <span class="nx">lists</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="k">fn</span> <span class="p">(</span><span class="nx">N</span><span class="p">)</span> <span class="p">{</span> <span class="nx">square</span><span class="p">(</span><span class="nx">N</span><span class="p">);</span> <span class="p">}</span><span class="o">,</span> <span class="nx">Numbers</span><span class="p">);</span>
<span class="p">};</span>
<span class="c"># functional form with lambda</span>
<span class="nx">squares2b</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">(</span><span class="nx">Numbers</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">lists</span><span class="o">:</span><span class="nx">map</span><span class="p">(</span><span class="k">fn</span> <span class="p">(</span><span class="nx">N</span><span class="p">)</span> <span class="p">{</span> <span class="nx">N</span> <span class="o">*</span> <span class="nx">N</span><span class="o">;</span> <span class="p">}</span><span class="o">,</span> <span class="nx">Numbers</span><span class="p">);</span>
+ <span class="nx">lists</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="k">fn</span> <span class="p">(</span><span class="nx">N</span><span class="p">)</span> <span class="p">{</span> <span class="nx">N</span> <span class="o">*</span> <span class="nx">N</span><span class="o">;</span> <span class="p">}</span><span class="o">,</span> <span class="nx">Numbers</span><span class="p">);</span>
<span class="p">};</span>
<span class="c"># no need for a function</span>
@@ -154,18 +154,18 @@
<span class="nx">run</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
<span class="nx">Numbers</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="o">,</span> <span class="mi">3</span><span class="o">,</span> <span class="mi">5</span><span class="o">,</span> <span class="mi">7</span><span class="p">];</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;squares1 : ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">squares1</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;squares2a: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">squares2a</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;squares2b: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">squares2b</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;squares3 : ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">squares3</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;squares1 : ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">squares1</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;squares2a: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">squares2a</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;squares2b: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">squares2b</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;squares3 : ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">squares3</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
<span class="p">};</span>
</pre></div>
<h2>binary.fn</h2>
<div class="highlight"><pre><span class="nx">match</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">(</span><span class="o">&lt;</span><span class="p">[</span><span class="nx">A</span><span class="o">:</span><span class="mi">8</span> <span class="nx">unsigned</span> <span class="nx">little</span> <span class="nx">integer</span><span class="o">,</span> <span class="nx">B</span><span class="o">:</span><span class="mi">4</span><span class="o">,</span> <span class="nx">C</span><span class="o">:</span><span class="mi">2</span><span class="o">,</span> <span class="nx">D</span><span class="p">]</span><span class="o">&gt;</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;match: ~p ~p ~p ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">A</span><span class="o">,</span> <span class="nx">B</span><span class="o">,</span> <span class="nx">C</span><span class="o">,</span> <span class="nx">D</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;match: ~p ~p ~p ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">A</span><span class="o">,</span> <span class="nx">B</span><span class="o">,</span> <span class="nx">C</span><span class="o">,</span> <span class="nx">D</span><span class="p">]);</span>
<span class="p">}</span>
<span class="p">(</span><span class="nx">Other</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;other: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">Other</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;other: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">Other</span><span class="p">]);</span>
<span class="p">};</span>
<span class="nx">run</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
@@ -189,9 +189,9 @@
<span class="nx">run</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
<span class="nx">S</span> <span class="o">=</span> <span class="s2">&quot;hello&quot;</span><span class="o">;</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;~s~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">S</span> <span class="o">++</span> <span class="s2">&quot; lite&quot;</span> <span class="o">++</span> <span class="s2">&quot;ral&quot;</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;~s~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">S</span> <span class="o">++</span> <span class="s2">&quot; lite&quot;</span> <span class="o">++</span> <span class="s2">&quot;ral&quot;</span><span class="p">]);</span>
<span class="nx">S1</span> <span class="o">=</span> <span class="nx">S</span> <span class="o">++</span> <span class="s2">&quot; lite&quot;</span> <span class="o">++</span> <span class="s2">&quot;ral&quot;</span><span class="o">;</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;~s~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">S1</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;~s~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">S1</span><span class="p">]);</span>
<span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span><span class="o">;</span> <span class="c"># just to test that the ++ doesn&#39;t break the +</span>
<span class="p">};</span>
</pre></div>
@@ -200,7 +200,7 @@
<span class="p">(</span><span class="nx">_</span><span class="o">,</span> <span class="nx">_</span><span class="o">,</span> <span class="nx">FunFalse</span><span class="p">)</span> <span class="p">{</span> <span class="nx">FunFalse</span><span class="p">();</span> <span class="p">};</span>
<span class="nx">say</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">(</span><span class="nx">Pid</span><span class="o">,</span> <span class="nx">Str</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">fwrite</span><span class="p">(</span><span class="s2">&quot;~s~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">Str</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">fwrite</span><span class="p">(</span><span class="s2">&quot;~s~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">Str</span><span class="p">]);</span>
<span class="nx">Pid</span> <span class="o">!</span> <span class="nx">done</span><span class="o">;</span>
<span class="p">};</span>
@@ -222,7 +222,7 @@
<div class="highlight"><pre><span class="c"># http://rosettacode.org/wiki/Select_from_Array</span>
<span class="nx">even1</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">(</span><span class="nx">Numbers</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">lists</span><span class="o">:</span><span class="nx">filter</span><span class="p">(</span><span class="k">fn</span> <span class="p">(</span><span class="nx">N</span><span class="p">)</span> <span class="p">{</span> <span class="nx">N</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="o">;</span> <span class="p">}</span><span class="o">,</span> <span class="nx">Numbers</span><span class="p">);</span>
+ <span class="nx">lists</span><span class="p">.</span><span class="nx">filter</span><span class="p">(</span><span class="k">fn</span> <span class="p">(</span><span class="nx">N</span><span class="p">)</span> <span class="p">{</span> <span class="nx">N</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="o">;</span> <span class="p">}</span><span class="o">,</span> <span class="nx">Numbers</span><span class="p">);</span>
<span class="p">};</span>
<span class="nx">even2</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">(</span><span class="nx">Numbers</span><span class="p">)</span> <span class="p">{</span>
@@ -230,36 +230,56 @@
<span class="p">};</span>
<span class="nx">run</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
- <span class="nx">Numbers</span> <span class="o">=</span> <span class="nx">lists</span><span class="o">:</span><span class="nx">seq</span><span class="p">(</span><span class="mi">1</span><span class="o">,</span> <span class="mi">15</span><span class="p">);</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;even1: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">even1</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;even2: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">even2</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
+ <span class="nx">Numbers</span> <span class="o">=</span> <span class="nx">lists</span><span class="p">.</span><span class="nx">seq</span><span class="p">(</span><span class="mi">1</span><span class="o">,</span> <span class="mi">15</span><span class="p">);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;even1: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">even1</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;even2: ~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">even2</span><span class="p">(</span><span class="nx">Numbers</span><span class="p">)]);</span>
+<span class="p">};</span>
+</pre></div>
+<h2>expressions.fn</h2>
+<div class="highlight"><pre><span class="c"># some expressions (and a lambda)</span>
+
+<span class="nx">run</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">Print</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">(</span><span class="nx">Expr</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">Expr</span><span class="p">]);</span>
+ <span class="p">};</span>
+
+ <span class="nx">Print</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="mi">4</span><span class="p">);</span>
+ <span class="nx">Print</span><span class="p">((</span><span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">4</span><span class="p">));</span>
+ <span class="nx">Print</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="mi">4</span><span class="p">);</span>
+ <span class="nx">Print</span><span class="p">(</span><span class="mi">7</span> <span class="o">%</span> <span class="mi">3</span> <span class="o">==</span> <span class="mi">0</span><span class="p">);</span>
+ <span class="nx">Print</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="mi">4</span> <span class="o">&gt;</span> <span class="mi">5</span><span class="p">);</span>
+ <span class="nx">Print</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="mi">4</span> <span class="o">&gt;</span> <span class="mi">5</span> <span class="nx">or</span> <span class="kc">true</span><span class="p">);</span>
+ <span class="nx">Print</span><span class="p">(</span><span class="kc">false</span> <span class="nx">or</span> <span class="kc">true</span><span class="p">);</span>
+ <span class="nx">Print</span><span class="p">(</span><span class="kc">true</span> <span class="nx">and</span> <span class="kc">false</span> <span class="nx">or</span> <span class="kc">true</span><span class="p">);</span>
+ <span class="nx">Print</span><span class="p">(</span><span class="kc">true</span> <span class="nx">and</span> <span class="nx">not</span> <span class="kc">false</span> <span class="nx">or</span> <span class="kc">true</span><span class="p">);</span>
+ <span class="nx">Print</span><span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="o">~</span><span class="mi">12</span> <span class="o">|</span> <span class="mi">5</span> <span class="o">&amp;</span> <span class="mi">127</span> <span class="o">^</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">};</span>
</pre></div>
<h2>numbers.fn</h2>
<div class="highlight"><pre><span class="nx">run</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;0xff : ~B~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="mi">0xff</span><span class="p">]);</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;0xFF : ~B~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="mi">0xFF</span><span class="p">]);</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;0o777 : ~B~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="mi">0o777</span><span class="p">]);</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;0b1011: ~B~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="mi">0b1011</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;0xff : ~B~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="mi">0xff</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;0xFF : ~B~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="mi">0xFF</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;0o777 : ~B~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="mi">0o777</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;0b1011: ~B~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="mi">0b1011</span><span class="p">]);</span>
<span class="p">};</span>
</pre></div>
<h2>pythag.fn</h2>
<div class="highlight"><pre><span class="c"># http://rosettacode.org/wiki/List_Comprehension</span>
<span class="nx">pythag</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">(</span><span class="nx">N</span><span class="p">)</span> <span class="p">{</span>
- <span class="p">[(</span><span class="nx">A</span><span class="o">,</span> <span class="nx">B</span><span class="o">,</span> <span class="nx">C</span><span class="p">)</span> <span class="k">for</span> <span class="nx">A</span> <span class="k">in</span> <span class="nx">lists</span><span class="o">:</span><span class="nx">seq</span><span class="p">(</span><span class="mi">1</span><span class="o">,</span> <span class="nx">N</span><span class="p">)</span>
- <span class="k">for</span> <span class="nx">B</span> <span class="k">in</span> <span class="nx">lists</span><span class="o">:</span><span class="nx">seq</span><span class="p">(</span><span class="nx">A</span><span class="o">,</span> <span class="nx">N</span><span class="p">)</span>
- <span class="k">for</span> <span class="nx">C</span> <span class="k">in</span> <span class="nx">lists</span><span class="o">:</span><span class="nx">seq</span><span class="p">(</span><span class="nx">B</span><span class="o">,</span> <span class="nx">N</span><span class="p">)</span>
+ <span class="p">[(</span><span class="nx">A</span><span class="o">,</span> <span class="nx">B</span><span class="o">,</span> <span class="nx">C</span><span class="p">)</span> <span class="k">for</span> <span class="nx">A</span> <span class="k">in</span> <span class="nx">lists</span><span class="p">.</span><span class="nx">seq</span><span class="p">(</span><span class="mi">1</span><span class="o">,</span> <span class="nx">N</span><span class="p">)</span>
+ <span class="k">for</span> <span class="nx">B</span> <span class="k">in</span> <span class="nx">lists</span><span class="p">.</span><span class="nx">seq</span><span class="p">(</span><span class="nx">A</span><span class="o">,</span> <span class="nx">N</span><span class="p">)</span>
+ <span class="k">for</span> <span class="nx">C</span> <span class="k">in</span> <span class="nx">lists</span><span class="p">.</span><span class="nx">seq</span><span class="p">(</span><span class="nx">B</span><span class="o">,</span> <span class="nx">N</span><span class="p">)</span>
<span class="k">if</span> <span class="nx">A</span> <span class="o">+</span> <span class="nx">B</span> <span class="o">+</span> <span class="nx">C</span> <span class="o">&lt;=</span> <span class="nx">N</span> <span class="nx">and</span> <span class="nx">A</span> <span class="o">*</span> <span class="nx">A</span> <span class="o">+</span> <span class="nx">B</span> <span class="o">*</span> <span class="nx">B</span> <span class="o">==</span> <span class="nx">C</span> <span class="o">*</span> <span class="nx">C</span><span class="p">];</span>
<span class="p">};</span>
<span class="nx">run</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">pythag</span><span class="p">(</span><span class="mi">20</span><span class="p">)]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">pythag</span><span class="p">(</span><span class="mi">20</span><span class="p">)]);</span>
<span class="p">};</span>
</pre></div>
<h2>send.fn</h2>
<div class="highlight"><pre><span class="nx">loop</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">receive</span> <span class="p">(</span><span class="nx">Stuff</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">Stuff</span><span class="p">]);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;~p~n&quot;</span><span class="o">,</span> <span class="p">[</span><span class="nx">Stuff</span><span class="p">]);</span>
<span class="p">};</span>
<span class="nx">loop</span><span class="p">();</span>
<span class="p">};</span>
@@ -277,9 +297,9 @@
<div class="highlight"><pre><span class="c"># http://rosettacode.org/wiki/Sleep_the_Main_Thread</span>
<span class="nx">run</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;Sleeping...~n&quot;</span><span class="p">);</span>
- <span class="nx">timer</span><span class="o">:</span><span class="nx">sleep</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span> <span class="c"># in milliseconds</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;Awake!~n&quot;</span><span class="p">);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;Sleeping...~n&quot;</span><span class="p">);</span>
+ <span class="nx">timer</span><span class="p">.</span><span class="nx">sleep</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span> <span class="c"># in milliseconds</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;Awake!~n&quot;</span><span class="p">);</span>
<span class="p">};</span>
</pre></div>
<h2>trycatch.fn</h2>
@@ -288,16 +308,16 @@
<span class="nx">make_error</span><span class="p">(</span><span class="nx">Arg</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">catch</span> <span class="p">(</span><span class="nx">throw</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;throw 1~n&quot;</span><span class="p">);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;throw 1~n&quot;</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">(</span><span class="nx">exit</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;exit 2~n&quot;</span><span class="p">);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;exit 2~n&quot;</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">(</span><span class="nx">error</span> <span class="p">(</span><span class="nx">some</span><span class="o">,</span> <span class="nx">fancy</span><span class="o">,</span> <span class="nx">tuple</span><span class="o">,</span> <span class="mi">3</span><span class="p">))</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;error~n&quot;</span><span class="p">);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;error~n&quot;</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">finally</span> <span class="p">{</span>
- <span class="nx">io</span><span class="o">:</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;finally~n&quot;</span><span class="p">);</span>
+ <span class="nx">io</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="s2">&quot;finally~n&quot;</span><span class="p">);</span>
<span class="p">};</span>
<span class="p">};</span>
@@ -308,7 +328,7 @@
<span class="nx">exit</span><span class="p">(</span><span class="mi">2</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">erlang</span><span class="o">:</span><span class="nx">error</span><span class="p">((</span><span class="nx">some</span><span class="o">,</span> <span class="nx">fancy</span><span class="o">,</span> <span class="nx">tuple</span><span class="o">,</span> <span class="mi">3</span><span class="p">));</span>
+ <span class="nx">erlang</span><span class="p">.</span><span class="nx">error</span><span class="p">((</span><span class="nx">some</span><span class="o">,</span> <span class="nx">fancy</span><span class="o">,</span> <span class="nx">tuple</span><span class="o">,</span> <span class="mi">3</span><span class="p">));</span>
<span class="p">};</span>
<span class="nx">run</span> <span class="o">=</span> <span class="k">fn</span> <span class="p">()</span> <span class="p">{</span>
Please sign in to comment.
Something went wrong with that request. Please try again.