Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ Loading .. ../test/closure2.lisp
Welcome to lisp in slisp!
Enter :quit to exit.

; loading "closure2.lisp" will produce a (defun main) now we call it.
; loading "closure2.lisp" will define (defun main)
; now we call it via the REPL:
> (main)
25
35
Expand All @@ -226,28 +227,22 @@ Enter :quit to exit.
Perhaps more interesting is that we can execute the [examples/nqueens.lisp](examples/nqueens.lisp) example, with no changes:

```
$ ./inception nqueens.lisp --repl
$ ./inception nqueens.lisp --main
Loading .. nqueens.lisp
Welcome to lisp in slisp!
Enter :quit to exit.

> (main)
8 Queens Solver for board size 8x8

Solution 1 (1 5 8 6 3 7 2 4):

Q . . . . . . .
. . . . Q . . .
. . . . . . . Q
. . . . . Q . .
. . Q . . . . .
. . . . . . Q .
. Q . . . . . .
. . . Q . . . .

..
..
```

> Here you'll see we added `--main` which automatically runs the `(main)` function our examples define.

So what are the differences between our _compiler_ and our _interpreter_? Well in some ways the interpreter is more advanced as it has support for `(quote)`, it has a symbol-type, and you can get references to functions using them. The lambdas/defuns are real standalone objects which are treated largely interchangeably and which you can print. But the biggest difference is that the compiler has a significantly larger standard-library.

The compiler prepends [stdlib.slisp](stdlib.slisp) to all programs, so you always have `map`, `filter`, etc, available. By contrast the interpreter has a very small standard library - it exposes `print`, `println`, `cons`, `list` and the special forms. It understands strings, integers, and floating-point numbers but it doesn't have a character-type.
Expand Down
8 changes: 7 additions & 1 deletion examples/inception.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@
(eval-defun expr env))
((= op "defvar")
(eval-defvar expr env))
((= op "defconst")
(eval-defvar expr env))
((= op "do")
(eval-do expr env))
((= op "if")
Expand Down Expand Up @@ -813,7 +815,8 @@

;; We process each named file (skipping --repl)
(map (lambda (name)
(if (!= name "--repl")
(if (and (!= name "--repl")
(!= name "--main"))
(do
(println "Loading .. " name)
(let ((handle (fopen name "r")) ; open
Expand All @@ -823,6 +826,9 @@
(run-program data))))))
(cdr args))

;; Should we auto-run (defun main) ..?
(if (member? args "--main")
(repl-execute-line "(main)"))

;; Is this REPL mode? Then run it
(if (member? args "--repl")
Expand Down
Loading