-
Notifications
You must be signed in to change notification settings - Fork 126
your own modules
Phil Hagelberg edited this page Mar 18, 2022
·
1 revision
To create and use your own lib/my-module.fnl:
$ cd my-project
$ tree
.
├── lib
│ └── my-module.fnl
└── my-program.fnl
In lib/my-module.fnl:
(fn say-hi [s]
(print (.. "Hi, " s "!")))
(fn add-em [a b]
(+ a b))
;; This table is returned when you `require` the module.
{: say-hi
: add-em}
In my-program.fnl:
#!/usr/bin/env fennel
(local my-m (require :lib.my-module))
(my-m.say-hi "Module")
(print (my-m.add-em 1 3))
Make your program executable: chmod +x my-program.fnl
, and run it:
$ ./my-program.fnl
Hi, Module!
4
For more info on modules, see the modules section of the tutorial.