Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 390 lines (320 sloc) 8.514 kb
3d91713 @djui Remove Go programming language dependency from README
djui authored
1 # Efene
c2278bd @marianoguerra added readme, modified the website
authored
2
fb307f4 @DavidMikeSimon A little cleanup work in the README
DavidMikeSimon authored
3 Efene is a programming language that runs on the Erlang virtual machine.
c2278bd @marianoguerra added readme, modified the website
authored
4
fb307f4 @DavidMikeSimon A little cleanup work in the README
DavidMikeSimon authored
5 The idea is to provide an alternative syntax for Erlang that is more comfortable
6 for people coming from languages like Java, C, C++, C#, Javascript, Ruby, or Python.
c2278bd @marianoguerra added readme, modified the website
authored
7
fb307f4 @DavidMikeSimon A little cleanup work in the README
DavidMikeSimon authored
8 Efene comes in two language dialects: Efene (Ruby style) and Ifene (Python style).
3d91713 @djui Remove Go programming language dependency from README
djui authored
9
fb307f4 @DavidMikeSimon A little cleanup work in the README
DavidMikeSimon authored
10 The language is almost 100% compatible with Erlang (and soon will be at 100%), and your
11 Efene programs can easily interact with regular Erlang programs, or vice-versa. The compiler
12 can translate an Efene source file into readable Erlang, or compile it directly to BEAM bytecode.
c2278bd @marianoguerra added readme, modified the website
authored
13
fb307f4 @DavidMikeSimon A little cleanup work in the README
DavidMikeSimon authored
14 ## Quick! Show me an example!
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
15
16 ### efene (hello.fn)
17 <pre>
18 <code>
19 # public will allow accessing this function from other modules
21423ee @marianoguerra changed readme to reflect the change in public
authored
20 @public
21 run() {
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
22 io.format("hello world!")
23 }
24 </code>
25 </pre>
26
27 ### compile
28 <pre>
29 <code>
30 fnc hello.fn
31 </code>
32 </pre>
33
34 ### run (call the run function from the hello module)
35 <pre>
36 <code>
7aaa881 @marianoguerra changed readme to use the new compiler frontend
authored
37 fnc -r hello run
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
38 </code>
39 </pre>
40
41 ### ifene (hello.ifn)
42 <pre>
43 <code>
44 # public will allow accessing this function from other modules
21423ee @marianoguerra changed readme to reflect the change in public
authored
45 @public
46 run()
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
47 io.format("hello world!")
48 </code>
49 </pre>
50
51 ### compile
52 <pre>
53 <code>
54 fnc hello.ifn
55 </code>
56 </pre>
57
58 ### run (call the run function from the hello module)
59 <pre>
60 <code>
7aaa881 @marianoguerra changed readme to use the new compiler frontend
authored
61 fnc -r hello run
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
62 </code>
63 </pre>
64
3d91713 @djui Remove Go programming language dependency from README
djui authored
65 ## That was simple, a more complex one!
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
66
67 ### efene (demo.fn)
68 <pre>
69 <code>
70 # if statement
71 compare = fn (A, B) {
72 if A < B {
73 lt
74 }
75 else if A > B {
76 gt
77 }
78 else {
79 eq
80 }
81 }
82
83 # switch statement and multiline expressions
84 compare_to_string = fn (Result) {
85 switch Result {
86 case lt {
87 "lower than"
88 }
89 case gt {
90 "greater than"
91 }
92 case eq {
93 "equal to"
94 }
95 else {
96 "invalid value '" ++
97 atom_to_list(Result) ++
98 "'"
99 }
100 }
101 }
102
103 # multiple function definition and guards
104 compare_to_string_guards = fn (Result) when Result == lt {
105 "lower than"
106 }
107 fn (Result) when Result == gt {
108 "greater than"
109 }
110 fn (Result) when Result == eq {
111 "equal to"
112 }
113 fn (Result) {
114 "invalid value '" ++
115 atom_to_list(Result) ++
116 "'"
117 }
118
119 # try/catch expression and tuples
120 fail = fn (Fun) {
121 try {
122 Fun()
123 }
124 catch error Error {
125 ("error", Error)
126 }
127 catch throw Throw {
128 ("throw", Throw)
129 }
130 catch Type Desc {
131 (atom_to_list(Type), Desc)
132 }
133 }
134
135 # pattern match
136 do = fn (add, A, B) {
137 A + B
138 }
139 fn (mul, A, B) {
140 A * B
141 }
142 fn (div, _A, 0) {
143 invalid_division
144 }
145 fn (div, A, B) {
146 A / B
147 }
148
149 # main function, made public to access it outside the module
21423ee @marianoguerra changed readme to reflect the change in public
authored
150 @public
151 run = fn () {
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
152 # lambda functions
8de2492 @marianoguerra now the examples in readme compile and run
authored
153 Print = fn (Expr) { io.format("~p~n", [Expr]) }
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
154
155 Print(compare(1, 2))
156 Print(compare(2, 1))
157 Print(compare(2, 2))
158
159 Print(compare_to_string(lt))
160 Print(compare_to_string(gt))
161 Print(compare_to_string(eq))
162 Print(compare_to_string(this_is_an_invalid_value))
163
164 Print(compare_to_string_guards(lt))
165 Print(compare_to_string_guards(gt))
166 Print(compare_to_string_guards(eq))
167 Print(compare_to_string_guards(this_is_an_invalid_value))
168
169 # call fail with a function that will fail in different ways
8de2492 @marianoguerra now the examples in readme compile and run
authored
170 Print(fail(fn () { throw("throw here") }))
171 Print(fail(fn () { erlang.error("error here") }))
172 Print(fail(fn () { exit("exit here") }))
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
173
174 Print(do(add, 10, 2))
175 Print(do(mul, 10, 2))
176 Print(do(div, 10, 2))
177 Print(do(div, 1, 0))
178 }
179 </code>
180 </pre>
181
182 ### compile
183 <pre>
184 <code>
185 fnc demo.fn
186 </code>
187 </pre>
188
189 ### run
190 <pre>
191 <code>
7aaa881 @marianoguerra changed readme to use the new compiler frontend
authored
192 fnc -r demo run
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
193 </code>
194 </pre>
195
196 ### ifene (demo.ifn)
197 <pre>
198 <code>
199 # if statement
200 compare = fn (A, B)
201 if A < B
202 lt
203 else if A > B
204 gt
205 else
206 eq
207
208 # switch statement and multiline expressions
209 compare_to_string = fn (Result)
210 switch Result
211 case lt
212 "lower than"
213 case gt
214 "greater than"
215 case eq
216 "equal to"
217 else
218 "invalid value '" ++
219 atom_to_list(Result) ++
220 "'"
221
222 # multiple function definition and guards
223 compare_to_string_guards = fn (Result) when Result == lt
224 "lower than"
225 fn (Result) when Result == gt
226 "greater than"
227 fn (Result) when Result == eq
228 "equal to"
229 fn (Result)
230 "invalid value '" ++
231 atom_to_list(Result) ++
232 "'"
233
234 # try/catch expression and tuples
235 fail = fn (Fun)
236 try
237 Fun()
238 catch error Error
239 ("error", Error)
240 catch throw Throw
241 ("throw", Throw)
242 catch Type Desc
243 (atom_to_list(Type), Desc)
244
245 # pattern match
246 do = fn (add, A, B)
247 A + B
248 fn (mul, A, B)
249 A * B
250 fn (div, _A, 0)
251 invalid_division
252 fn (div, A, B)
253 A / B
254
255 # main function, made public to access it outside the module
21423ee @marianoguerra changed readme to reflect the change in public
authored
256 @public
257 run = fn ()
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
258 # lambda functions
8de2492 @marianoguerra now the examples in readme compile and run
authored
259 Print = fn (Expr) { io.format("~p~n", [Expr]) }
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
260
261 Print(compare(1, 2))
262 Print(compare(2, 1))
263 Print(compare(2, 2))
264
265 Print(compare_to_string(lt))
266 Print(compare_to_string(gt))
267 Print(compare_to_string(eq))
268 Print(compare_to_string(this_is_an_invalid_value))
269
270 Print(compare_to_string_guards(lt))
271 Print(compare_to_string_guards(gt))
272 Print(compare_to_string_guards(eq))
273 Print(compare_to_string_guards(this_is_an_invalid_value))
274
275 # call fail with a function that will fail in different ways
8de2492 @marianoguerra now the examples in readme compile and run
authored
276 Print(fail(fn () { throw("throw here") }))
277 Print(fail(fn () { erlang.error("error here") }))
278 Print(fail(fn () { exit("exit here") }))
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
279
280 Print(do(add, 10, 2))
281 Print(do(mul, 10, 2))
282 Print(do(div, 10, 2))
283 Print(do(div, 1, 0))
284
285 </code>
286 </pre>
287
288 ### compile
289 <pre>
290 <code>
291 fnc demo.ifn
292 </code>
293 </pre>
294
295 ### run
296 <pre>
297 <code>
7aaa881 @marianoguerra changed readme to use the new compiler frontend
authored
298 fnc -r demo run
759fa91 @marianoguerra added two examples and updated the readme, fixed a bug with multiline ex...
authored
299 </code>
300 </pre>
301
fb307f4 @DavidMikeSimon A little cleanup work in the README
DavidMikeSimon authored
302 You can see more examples in the [examples dir](http://github.com/marianoguerra/efene/tree/master/examples/).
303
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
304 ## Using Efene in your app
1bdba51 @marianoguerra website and readme updated
authored
305
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
306 You will need a recent Erlang/OTP release. If you are on a Debian-based distribution, you can install it with apt-get:
3d91713 @djui Remove Go programming language dependency from README
djui authored
307
a9dcb5e @DavidMikeSimon Code sections in markdown need 4 spaces of indent
DavidMikeSimon authored
308 $ sudo apt-get erlang erlang-parsetools
3d91713 @djui Remove Go programming language dependency from README
djui authored
309
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
310 Create a directory for your new project, and download rebar, an Erlang build tool:
311
b0a3ce5 @DavidMikeSimon Simplified mkdir example
DavidMikeSimon authored
312 $ mkdir myapp
a9dcb5e @DavidMikeSimon Code sections in markdown need 4 spaces of indent
DavidMikeSimon authored
313 $ cd myapp
314 $ wget http://bitbucket.org/basho/rebar/downloads/rebar; chmod u+x rebar
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
315
316 Create a file named `rebar.config` in the myapp directory:
317
a9dcb5e @DavidMikeSimon Code sections in markdown need 4 spaces of indent
DavidMikeSimon authored
318 {deps, [
319 {efene, ".*",
320 {git, "git://github.com/marianoguerra/efene.git", "master"}
321 },
322 {rebar_efene_plugin, ".*",
323 {git, "git://github.com/DavidMikeSimon/rebar_efene_plugin.git", "stable"}
324 }
325 ]}.
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
326
60ead9c @DavidMikeSimon Added plugin_dir line to README guide as well.
DavidMikeSimon authored
327 {plugins, [ rebar_efene_plugin ]}.
328 {plugin_dir, "deps/rebar_efene_plugin/src"}.
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
329
330 Create a directory named `src`, and within it create a `myapp.app.src` file:
1bdba51 @marianoguerra website and readme updated
authored
331
a9dcb5e @DavidMikeSimon Code sections in markdown need 4 spaces of indent
DavidMikeSimon authored
332 {application, myapp, [
333 {description, "My first app ever"},
57575b8 @DavidMikeSimon Fixed a typo in the sample app.src file, clarified README instructions
DavidMikeSimon authored
334 {vsn, "0.0.1"}
a9dcb5e @DavidMikeSimon Code sections in markdown need 4 spaces of indent
DavidMikeSimon authored
335 ]}.
1bdba51 @marianoguerra website and readme updated
authored
336
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
337 Finally, go ahead and write a simple Efene (.fn) or Ifene (.ifn) file in
338 the src directory. Then tell rebar to download your dependencies and
339 compile everything:
340
a9dcb5e @DavidMikeSimon Code sections in markdown need 4 spaces of indent
DavidMikeSimon authored
341 $ rebar get-deps
342 $ rebar compile
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
343
57575b8 @DavidMikeSimon Fixed a typo in the sample app.src file, clarified README instructions
DavidMikeSimon authored
344 And there you go! You now have BEAM files in the `ebin` directory, just
345 as with a regular Erlang project; you can load them and run functions
346 from them using the Erlang shell.
347
348 After you make more changes to your source code, just run the rebar compile command again:
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
349
a9dcb5e @DavidMikeSimon Code sections in markdown need 4 spaces of indent
DavidMikeSimon authored
350 $ rebar compile
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
351
352 ## Standalone build instructions
353
354 To build efene by itself, rather than as a dependency for your project:
6844b81 @marianoguerra readme updated
authored
355
3d91713 @djui Remove Go programming language dependency from README
djui authored
356 $ git clone git://github.com/marianoguerra/efene.git
357 $ cd efene
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
358 $ ./build.sh
6844b81 @marianoguerra readme updated
authored
359
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
360 This will also create an executable `bin/fnc`, which functions similarly to `erl` and `erlc`.
6844b81 @marianoguerra readme updated
authored
361
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
362 Additionally, you can build and run the examples:
6844b81 @marianoguerra readme updated
authored
363
3d91713 @djui Remove Go programming language dependency from README
djui authored
364 $ cd examples
365 $ ./build.sh
366 $ ./run.sh
dba69f8 @marianoguerra added relative references to fnc
authored
367
cf78a27 @DavidMikeSimon Added to README an example of using rebar to set up an efene project
DavidMikeSimon authored
368 ## Participate
369
370 A mailing-list is available at [librelist](http://librelist.com/browser/efene/), just send a mail to [efene@librelist.com](mailto:efene@librelist.com) to subscribe.
371
3d91713 @djui Remove Go programming language dependency from README
djui authored
372 ## Requirements
6844b81 @marianoguerra readme updated
authored
373
fb307f4 @DavidMikeSimon A little cleanup work in the README
DavidMikeSimon authored
374 To create the Efene compiler you will need a C compiler like GCC or LLVM-GCC, and any recent Erlang/OTP release.
6844b81 @marianoguerra readme updated
authored
375
3d91713 @djui Remove Go programming language dependency from README
djui authored
376 * Erlang
377 * (GCC or LLVM-GCC)
6844b81 @marianoguerra readme updated
authored
378
d7aa1e1 @marianoguerra clarify package requirement for debian based distributions
authored
379
c2278bd @marianoguerra added readme, modified the website
authored
380 ## Useful links
381
7d91598 @marianoguerra added link to download latest snapshot to the README
authored
382 * [Download the latest snapshot](http://github.com/marianoguerra/efene/tarball/master)
6844b81 @marianoguerra readme updated
authored
383 * [Website](http://marianoguerra.com.ar/efene)
6934455 @marianoguerra added reference to the documentation in the readme and the website
authored
384 * [Documentation](http://marianoguerra.com.ar/efene/docs)
bff683b @marianoguerra added links to the tutorial in README and website, updated the examples ...
authored
385 * [Tutorial](http://marianoguerra.com.ar/efene/tutorial)
6844b81 @marianoguerra readme updated
authored
386 * [Blog](http://efene.tumblr.com)
3d91713 @djui Remove Go programming language dependency from README
djui authored
387 * [Central git repo](http://github.com/marianoguerra/efene) (fork this one)
c2278bd @marianoguerra added readme, modified the website
authored
388 * [Tracker](http://github.com/marianoguerra/efene/issues)
7b5cdec @marianoguerra updated the readme
authored
389 * [Rosetta code page](http://rosettacode.org/wiki/Efene)
Something went wrong with that request. Please try again.