Permalink
Browse files

public is not a keyword anymore, to make a function public add the @p…

…ublic attribute before the function
  • Loading branch information...
1 parent df44d09 commit bd15d78853c458e16751ef2c58c5cb9ec2a06ed7 @marianoguerra committed May 7, 2010
View
@@ -13,7 +13,8 @@ bar = fn (A, B, C, D) {
(D, B, C, A)
}
-public run = fn () {
+@public
+run = fn () {
# this expression is the same as the one below
A = 1->foo(2)->
foo(3,4)->
View
@@ -10,7 +10,8 @@ foo = fn (A, B, C)
bar = fn (A, B, C, D)
(D, B, C, A)
-public run = fn ()
+@public
+run = fn ()
# this expression is the same as the one below
A = 1->foo(2)->
foo(3,4)->
View
@@ -6,7 +6,8 @@
# after it
@get("/")
@produces(html)
-public index = fn (_Req)
+@public
+index = fn (_Req)
"hello world!"
# another global attribute, you can place attributes anywhere
@@ -15,10 +16,12 @@ public index = fn (_Req)
@post("/user/")
@accepts(json)
@produces(txt)
-public create_user = fn (_Req, _Body)
+@public
+create_user = fn (_Req, _Body)
(200, "ok")
-public run = fn ()
+@public
+run = fn ()
Api = get_rest_api(module_info(attributes))
pretty_print_api(Api)
View
@@ -78,7 +78,8 @@ fn (div, A, B) {
}
# main function, made public to access it outside the module
-public run = fn () {
+@public
+run = fn () {
# lambda functions
Print = fn (Expr) { io.format("~p~n", [Expr]) }
View
@@ -57,7 +57,8 @@ fn (div, A, B)
A / B
# main function, made public to access it outside the module
-public run = fn ()
+@public
+run = fn ()
# lambda functions
Print = fn (Expr) { io.format("~p~n", [Expr]) }
View
@@ -8,7 +8,8 @@ add = fn (A, B) {
A + B
}
-public run = fn () {
+@public
+run = fn () {
ByTwo = fn bytwo:1
Add = fn add:2
View
@@ -6,7 +6,8 @@ bytwo = fn (A)
add = fn (A, B)
A + B
-public run = fn ()
+@public
+run = fn ()
ByTwo = fn bytwo:1
Add = fn add:2
@@ -4,6 +4,7 @@ hello = fn (Who) {
io.format("hello ~s!~n", [Who])
}
-public run = fn () {
+@public
+run = fn () {
hello("world")
}
@@ -3,5 +3,6 @@
hello = fn (Who)
io.format("hello ~s!~n", [Who])
-public run = fn ()
+@public
+run = fn ()
hello("world")
@@ -4,7 +4,8 @@
# http://en.wikipedia.org/wiki/List_comprehension
# http://www.erlang.org/doc/programming_examples/list_comprehensions.html
-public run = fn () {
+@public
+run = fn () {
A = [X for X in lists.seq(1, 10)]
B = [X for X in lists.seq(1, 10) if X % 2 == 0]
C = [X for X in lists.seq(1, 10) if X % 2 == 0 and X != 4]
@@ -4,7 +4,8 @@
# http://en.wikipedia.org/wiki/List_comprehension
# http://www.erlang.org/doc/programming_examples/list_comprehensions.html
-public run = fn ()
+@public
+run = fn ()
A = [X for X in lists.seq(1, 10)]
B = [X for X in lists.seq(1, 10) if X % 2 == 0]
C = [X for X in lists.seq(1, 10) if X % 2 == 0 and X != 4]
View
@@ -1,7 +1,8 @@
person = record(firstname, lastname, mail="none")
-public run = fn () {
+@public
+run = fn () {
P = person[firstname="mariano", lastname="guerra", mail="no@spam.com"]
io.format("firstname: ~s~n", [person.P.firstname])
P1 = person.P[firstname="Mariano", lastname="Guerra"]
@@ -2,7 +2,8 @@
person = record(firstname, lastname, mail="none")
-public run = fn ()
+@public
+run = fn ()
P = person[firstname="mariano", lastname="guerra", mail="no@spam.com"]
io.format("firstname: ~s~n", [person.P.firstname])
P1 = person.P[firstname="Mariano", lastname="Guerra"]
View
@@ -1,4 +1,5 @@
-public run = fn () {
+@public
+run = fn () {
# create a list with the numbers from 1 to 10
l.range(2, 10)->
# increment each item by 1
View
@@ -1,40 +1,49 @@
-public each = fn (List, Fun) {
+@public
+each = fn (List, Fun) {
lists.foreach(Fun, List)
List
}
-public map = fn (List, Fun) {
+@public
+map = fn (List, Fun) {
lists.map(Fun, List)
}
-public keep = fn (List, Fun) {
+@public
+keep = fn (List, Fun) {
lists.filter(Fun, List)
}
-public remove = fn (List, Fun) {
+@public
+remove = fn (List, Fun) {
keep(List, fn (X) { not Fun(X) })
}
-public flatten = fn (List) {
+@public
+flatten = fn (List) {
lists.flatten(List)
}
-public uniq = fn (_List) {
+@public
+uniq = fn (_List) {
throw(notimplemented)
}
-public tap = fn (List, Fun) {
+@public
+tap = fn (List, Fun) {
Fun(List)
List
}
-public print = fn (List) {
+@public
+print = fn (List) {
io.format("~p~n", [List])
List
}
-public times = fn (Num, _Fun) when Num < 0 {
+@public
+times = fn (Num, _Fun) when Num < 0 {
throw(invalid_times_value)
} fn (Num, Fun) {
times_acc(1, Fun, Num)
@@ -48,31 +57,38 @@ times_acc = fn (Stop, Fun, Stop) {
times_acc(Count + 1, Fun, Stop)
}
-public zip = fn (List, NewList) {
+@public
+zip = fn (List, NewList) {
lists.zip(List, NewList)
}
-public append = fn (List, NewList) {
+@public
+append = fn (List, NewList) {
lists.append(List, NewList)
}
-public length = fn (List) {
+@public
+length = fn (List) {
erlang.length(List)
}
-public range = fn (Stop) {
+@public
+range = fn (Stop) {
range(0, Stop, 1, [])
}
-public range = fn (Start, Stop) {
+@public
+range = fn (Start, Stop) {
range(Start, Stop, 1, [])
}
-public range = fn (Start, Stop, Step) {
+@public
+range = fn (Start, Stop, Step) {
range(Start, Stop, Step, [])
}
-public reverse = fn (List) {
+@public
+reverse = fn (List) {
lists.reverse(List)
}
@@ -90,47 +106,58 @@ range = fn (_Start, _Stop, 0, _Accum) {
range(Start + Step, Stop, Step, [Start:Accum])
}
-public all = fn (List) {
+@public
+all = fn (List) {
all(List, fn (Item) { to_bool(Item) })
}
-public all = fn (List, Fun) {
+@public
+all = fn (List, Fun) {
lists.all(Fun, List)
}
-public any = fn (List) {
+@public
+any = fn (List) {
any(List, fn (Item) { to_bool(Item) })
}
-public any = fn (List, Fun) {
+@public
+any = fn (List, Fun) {
lists.any(Fun, List)
}
-public max = fn (List) {
+@public
+max = fn (List) {
lists.max(List)
}
-public max = fn (_List, _Fun) {
+@public
+max = fn (_List, _Fun) {
throw(notimplemented)
}
-public min = fn (List) {
+@public
+min = fn (List) {
lists.min(List)
}
-public min = fn (_List, _Fun) {
+@public
+min = fn (_List, _Fun) {
throw(notimplemented)
}
-public reduce = fn (_List, _Start, _Fun) {
+@public
+reduce = fn (_List, _Start, _Fun) {
throw(notimplemented)
}
-public detect = fn (_List, _Fun) {
+@public
+detect = fn (_List, _Fun) {
throw(notimplemented)
}
-public to_bool = fn (0) {
+@public
+to_bool = fn (0) {
false
} fn ([]) {
false
View
@@ -1,5 +1,6 @@
-public assert = fn (Item, Fun) {
+@public
+assert = fn (Item, Fun) {
Result = Fun(Item)
if Result !== true {
@@ -10,7 +11,8 @@ public assert = fn (Item, Fun) {
}
}
-public equals = fn (A, B) {
+@public
+equals = fn (A, B) {
if A != B {
throw(assert_failed)
} else {
View
@@ -1,4 +1,5 @@
-public run = fn () {
+@public
+run = fn () {
l.range(2, 10)->
t.equals([2, 3, 4, 5, 6, 7, 8, 9, 10])->
l.reverse()->
View
@@ -89,27 +89,30 @@ tree_to_ast([{global_attribute, Line, Name, Value}|Tree], Publics, Ast, CurrAttr
tree_to_ast([{attribute, _Line, _Name, _Value}=Attr|Tree], Publics, Ast, CurrAttrs, Attrs) ->
tree_to_ast(Tree, Publics, Ast, [Attr|CurrAttrs], Attrs);
-tree_to_ast([{public_function, Line, Name, Arity, Body}|Tree], Publics, Ast, CurrAttrs, Attrs) ->
- Fun = {Name, Arity},
- NewAttrs = modify_attrs(CurrAttrs, Fun),
- tree_to_ast(Tree, [Fun|Publics],
- [{function, Line, Name, Arity, Body}|Ast], [], [NewAttrs|Attrs]);
-
tree_to_ast([{function, _Line, Name, Arity, _Body}=H|Tree], Publics, Ast, CurrAttrs, Attrs) ->
Fun = {Name, Arity},
- NewAttrs = modify_attrs(CurrAttrs, Fun),
- tree_to_ast(Tree, Publics,
+ {IsPublic, NewAttrs} = modify_attrs(CurrAttrs, Fun),
+
+ NewPublics = if
+ IsPublic -> [Fun|Publics];
+ true -> Publics
+ end,
+
+ tree_to_ast(Tree, NewPublics,
[H|Ast], [], [NewAttrs|Attrs]);
+
tree_to_ast([H|Tree], Publics, Ast, CurrAttrs, Attrs) ->
tree_to_ast(Tree, Publics, [H|Ast], CurrAttrs, Attrs).
modify_attrs(Attrs, Fun) ->
- modify_attrs(Attrs, Fun, []).
-
-modify_attrs([], _Fun, Accum) ->
- lists:reverse(Accum);
-modify_attrs([{attribute, Line, Name, Args}|Attrs], Fun, Accum) ->
- modify_attrs(Attrs, Fun, [{attribute, Line, Name, {Fun, Args}}|Accum]).
+ modify_attrs(Attrs, Fun, [], false).
+
+modify_attrs([], _Fun, Accum, IsPublic) ->
+ {IsPublic, lists:reverse(Accum)};
+modify_attrs([{attribute, _Line, public, nil}|Attrs], Fun, Accum, _IsPublic) ->
+ modify_attrs(Attrs, Fun, Accum, true);
+modify_attrs([{attribute, Line, Name, Args}|Attrs], Fun, Accum, IsPublic) ->
+ modify_attrs(Attrs, Fun, [{attribute, Line, Name, {Fun, Args}}|Accum], IsPublic).
get_publics(Tree) ->
Oops, something went wrong.

0 comments on commit bd15d78

Please sign in to comment.