the page:
http://www.erlang-factory.com/
the talks:
http://www.erlang-factory.com/
the schedule:
http://www.erlang-factory.com/
see you there :)
-module(emacro).
-export([run_erl/0]).
-define(PRINT(A, B, C), io:format("~p ~p ~p~n", [A, B, C])).
-define(BORING_ERL_CONSTANT, 42).
run_erl() ->
?PRINT(1, two, "asd").
@import("emacro.erl")
$boring_fn_constant = 1337
$PrintReverse = fn (A, B, C)
io.format("~p ~p ~p~n", [C, B, A])
$PrintReverseAndSayGoodBye = fn (A, B, C)
io.format("~p ~p ~p~n", [C, B, A])
io.format("goodbye~n")
@public
run = fn ()
$PRINT(1, asd, $BORING_ERL_CONSTANT)
$PrintReverse(1, 2, $boring_fn_constant)
$PrintReverseAndSayGoodBye("world", "macro", "hello")
mariano@ganesha:~/tmp$ fnc -t erl fmacro.ifn
-module(fmacro).
-export([run/0]).
-export([run_erl/0]).
run_erl() -> io:format("~p ~p ~p~n", [1, two, "asd"]).
run() ->
io:format("~p ~p ~p~n", [1, asd, 42]),
io:format("~p ~p ~p~n", [1337, 2, 1]),
begin
io:format("~p ~p ~p~n", ["hello", "macro", "world"]),
io:format("goodbye~n")
end.
mariano@ganesha:~/tmp$ fnc fmacro.ifn Compiling fmacro.ifn mariano@ganesha:~/tmp$ fnc -r fmacro run 1 asd 42 1337 2 1 "hello" "macro" "world" goodbye mariano@ganesha:~/tmp$ fnc -r fmacro run_erl 1 two "asd"
$PrintReverse = fn (A, B, C)
io.format("~p ~p ~p~n", [C, B, A])
@public
run = fn ()
A = $PrintReverse
line 7: trying to use a macro function as a value?
$PrintReverse = fn (A, B, C)
io.format("~p ~p ~p~n", [C, B, A])
@public
run = fn ()
A = $PrintReverse(1, 2)
Compiling nicemacroerrors.ifn:line 7: calling macro nicemacroerrors.'PrintReverse' that expects 3 args with 2 instead
$PrintReverse = fn (pattern_match=A, B, C)
io.format("~p ~p ~p~n", [C, B, A])
@public
run = fn ()
A = $PrintReverse(1, 2, 3)
Compiling nicemacroerrors.ifn:line 2: all parameters in a macro must be variables
$PrintReverse = fn (A, B, C) when is_list(A)
io.format("~p ~p ~p~n", [C, B, A])
@public
run = fn ()
A = $PrintReverse(1, 2, 3)
Compiling nicemacroerrors.ifn:line 2: macro can't contain guards
$PrintReverse = fn (A, B, C)
io.format("~p ~p ~p~n", [C, B, A])
syntax error
@public
run = fn ()
A = $PrintReverse(1, 2, 3)
Compiling nicemacroerrors.ifn:line 4: syntax error before: "error"
$PrintReverse = fn (A, B, C)
io.format("~p ~p ~p~n", [C, B, A])
fn (A, B, C)
io.format("another clause")
@public
run = fn ()
A = $PrintReverse(1, 2, 3)
Compiling nicemacroerrors.ifn:line 2: macro can't contain multiple clauses
$PrintReverse = fn (A, B, C)
io.format("~p ~p ~p~n", [C, B, A])
$Constant = not_a_function
@public
run = fn ()
$PrintReverse(1, 2, 3)
$Constant(1)
Compiling nicemacroerrors.ifn:line 10: trying to call macro nicemacroerrors.'Constant' but it's not a function
git clone git://github.com/marianoguerra/efene.git cd efene ./build.sh ./build.sh
$foo = 4
$bar = 6
@public
to_import_ifn = fn ()
io.format("i'm a function from module toimport.ifn~n")
-module(asd).
-export([runerl/0]).
-define(FOO, 4).
-define(BAR, "asd").
runerl() ->
io:format("~p ~p~n", [?FOO, ?BAR]).
@import("toimport.ifn")
@import("asd.erl")
$baz = 1
@public
run = fn () {
to_import_ifn()
io.format("constans from this module ~p~n", [$baz])
io.format("constans from toimport.ifn module ~p ~p~n", [$foo, $bar])
io.format("constans from asd.erl module ~p ~p~n", [$FOO, $BAR])
}
mariano@ganesha:~$ fnc importall.fn Compiling importall.fn mariano@ganesha:~$ fnc -r importall run i'm a function from module toimport.ifn constans from this module 1 constans from toimport.ifn module 4 6 constans from asd.erl module 4 "asd"
@import("toimport.ifn")
@import("asd.erl")
$baz = 1
$FOO = "redefining"
@public
run = fn () {
to_import_ifn()
io.format("constans from this module ~p~n", [$baz])
io.format("constans from toimport.ifn module ~p ~p~n", [$foo, $bar])
io.format("constans from asd.erl module ~p ~p~n", [$FOO, $BAR])
}
mariano@ganesha:~$ fnc importall.fn
Compiling importall.fn
line 5: constant 'FOO' already defined at {asd,4}
This is a guest post from David Simon who implemented rebar support for efene, a round of applauses to him!
Rebar is a build and project-management system for Erlang, similar to tools such as SCons, autotools, and ant. It has a lot of cool features, including release packaging, templates, automatic dependency management, and support for various testing systems.
Recently, we've got Rebar to work together with Efene using a plugin, and also switched Efene from its custom build system to a Rebar-based one. This means that you can now use Rebar to manage your Efene projects. Specifically, you can now have Rebar:
To do this, your project needs specify in its rebar.config that it uses rebar_efene_plugin and that it depends on Efene and the plugin:
{deps, [
{efene, ".*",
{git, "git://github.com/marianoguerra/efene.git", "master"}
},
{rebar_efene_plugin, ".*",
{git, "git://github.com/DavidMikeSimon/rebar_efene_plugin.git",
"stable"}
}
]}.
{rebar_plugins, [ rebar_efene_plugin ]}.
Once you've done that, you can run the appropriate rebar commands to download the dependencies and compile everything:
$ rebar get-deps $ rebar compile
And you should be good to go! Any .fn or .ifn files in your src directory (or any other source directory you specify using the src_dirs directive in erl_opts) will be compiled as needed whenever you run rebar compile.
More detailed instructions on how to start an Efene project from scratch using Rebar are available in Efene's README file (viewable at https://github.com/marianoguerra/efene), under the heading "Using Efene in your app".
Unfortunately, we don't yet support EUnit tests written in Efene, as the EUnit module in Rebar is hard-coded to look only at regular .erl files. Look for this to be addressed fairly soon.
@public
to_import_ifn = fn ()
io.format("i'm a function from module toimport.ifn~n")
@public
to_import_fn = fn () {
io.format("i'm a function from module toimport.fn~n")
}
-module(toimport).
-export([to_import_erl/0]).
to_import_erl() ->
io:format("i'm a function from module toimport.erl~n").
-module(toimport).
-export([to_import_hrl/0]).
to_import_hrl() ->
io:format("i'm a function from module toimport.hrl~n").
@import("toimport.ifn")
@import("toimport.fn")
@import("toimport.erl")
@import("toimport.hrl")
@public
run = fn ()
to_import_ifn()
to_import_fn()
to_import_erl()
to_import_hrl()
$ fnc importall.ifn Compiling importall.ifn $ fnc -r importall run i'm a function from module toimport.ifn i'm a function from module toimport.fn i'm a function from module toimport.erl i'm a function from module toimport.hrl