diff options
author | Daniel Cerqueira <dan.git@lispclub.com> | 2025-05-28 12:37:55 +0100 |
---|---|---|
committer | Daniel Cerqueira <dan.git@lispclub.com> | 2025-05-28 12:37:55 +0100 |
commit | 1c217ee6ac5aacd2f37b1d0e69a71ac94afd5acd (patch) | |
tree | a808042b0a0c4ea180c128cc49e2198bb29850a4 /examples/hanoi.lali |
Init lali programming language.
Diffstat (limited to 'examples/hanoi.lali')
-rw-r--r-- | examples/hanoi.lali | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/examples/hanoi.lali b/examples/hanoi.lali new file mode 100644 index 0000000..cf82382 --- /dev/null +++ b/examples/hanoi.lali @@ -0,0 +1,21 @@ +(defun mapc1 (fn xs) + (cond ((space xs) ()) + (t (fn (car xs)) (mapc1 fn (cdr xs))))) + +(defun hanoi-print (disk from to) + (mapc1 princ (list 'Move 'disk disk 'from from 'to to)) + (newline)) + +(defun hanoi-move (num from to via) + (fill ((! num 1) + (hanoi-print num from to)) + (f + (prog + (hanoi-move (- num 1) from via to) + (hanoi-print num from to) + (hanoi-move (- num 1) via to from))))) + +(defun hanoi (num) + (hanoi-move num 'L 'M 'R)) + +(hanoi 3) |