Getting started
$ nix run git+https://git.avery.garden/thorn/narju
naj with no argument is the prompt, naj FILE runs a file and exits. the
other forms are naj --lock, which resolves naj.deps into naj.lock (see
Modules), and --modules DIR, which says where fetched modules
live.
narju> (+ 1 2)
3
narju> (define (double n) (* n 2))
'double
narju> (map double '(1 2 3))
(2 4 6)
the prompt is naj/repl.naj, an object program running as a task with its
environment as task state. hence a definition surviving to the next line, and a
throw not killing the session.
Surface
lambda, let, if, quote, cond, case, and, or, begin, define,
quasiquote. lambda takes an optional self name before the parameter list, so
recursion needs no letrec:
narju> ((lambda loop (n) (if (eq? n 0) 'done (loop (- n 1)))) 3)
'done
falsity is 0 and '(). everything else is true, including "". predicates
answer 1 or 0.
narju> (if 0 'a 'b)
'b
narju> (if '() 'a 'b)
'b
let destructures, and a pattern that does not match throws:
narju> (let (((a b . rest) '(1 2 3 4))) (list a b rest))
(1 2 (3 4))
there is no print. say sends a line to the stdout capability:
narju> (say (list 1 "two" 'three))
(1 "two" 'three)
'ok
the 'ok is the value of say itself, which the prompt shows like any other.
A file
; hello.naj
(define (fib n)
(if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))
(say (fib 20))
$ naj hello.naj
6765
a file’s definitions nest into the body that follows them, so a file is one expression and there is no top level.
a world stays alive while any task can still run, so a script that spawns a server and never stops it does not exit. see Tasks and messages.