Running Lunula
To experiment with Lunula, run Lunula.exe to launch the read-eval-print-loop (REPL).
c:\lunula\bin>lunula.exe
Lunula 0.4.0
type (quit) to exit
>
You can then evaluate Lisp expressions at the REPL:
> (+ 1 2 3)
6
> (display "Lunula is great!")
Lunula is great!
Writing your own Lunula programs
To write your own Lunula programs, put the source code of your program in one or more .lun files. For example create a file called hello-factorial.lun and put the following sample code in it:
(define (hw-factorial n)
(if (= n 0)
1
(* n (hw-factorial (- n 1)))))
(printf "hello world!~%")
(printf "The factorial of ~A is ~A~%"
10
(hw-factorial 10))
Then load the file into the running Lunula system using the REPL:
> (load "hello-factorial.lun")
hello world!
The factorial of 10 is 3628800
Loading a file using (load …) will read the file in and compile it to byte code in memory. If you want to save time loading a file you can compile a file directly to byte code before loading it. Lunula byte code files have a .lvm extension.
> (compile-file "hello-factorial.lun")
"hello-factorial.lvm"
> (load "hello-factorial.lvm")
hello world!
The factorial of 10 is 3628800
You can also load .lun or .lvm files using a command line parameter to Lunula.exe. Note that loading files at the command line will not launch the REPL.
c:\lunula\bin>lunula.exe hello-factorial.lvm
hello world!
The factorial of 10 is 3628800