Skip to content

General Structure

Anssi Halmeaho edited this page Apr 25, 2020 · 12 revisions

General structure

FunL source files extension is assumed to be ".fnl".

FunL source file implements module (namespace) which is defined to namespace block:

ns <module>

import <some-module-name>
<symbol> = <expression>
<symbol> = <expression>
...

endns 

Example module:

ns mymodule

# symbol my-example contains string value
my-example = 'some text...'

# just some test function which gives sum of two parameters 
my-adder = proc(a b)
  plus(a b)
end

endns

Namespace consists of let-definitions and module imports. Let-definition assigns value (evaluated from expression) to symbol. Module import brings some other module definitions visible to current namespace.

By default interpreter (funla) assumes that given source file is "main" namespace and there is proc/func named "main" and execution starts by calling that.

main module and main function/procedure are defined as:

ns main

import <some-module-name>
<symbol> = <expression>
<symbol> = <expression>
...
main = proc/func(<arguments>)
  ...
end

endns

Example: source file (somesource.fnl):

ns main

main = func()
  'this is return value'
end

endns

Run source file (somesource.fnl):

./funla somesource.fnl
    -> execution starts in main function/procedure, namespace in somesource.fnl is main

By default result of evaluation (value returned from entrypoint function/procedure) is printed but printing can be disabled with -silent option.

With option -mod some other namespace/module can be given as target.

With option -name some other procedure/function (than "main") can be given as entrypoint.

With option -args arguments can be given to entrypoint function/procedure.

Example: give module name from which execution is started:

./funla -mod=mymodule  
    -> execution starts in mymodule -module, entrypoint function/procedure is main
./funla -mod=mymodule
    -> execution starts in mymodule -module, entrypoint function/procedure is main
./funla -mod=mymodule -name=my-adder -args="1 2" 
    -> execution starts in mymodule, entrypoint function/procedure my-adder, arguments are 1 and 2
Clone this wiki locally