-
Notifications
You must be signed in to change notification settings - Fork 0
01 Quickstart
Installing Sibilisp is simple, all you need is Node 6 or later and NPM (comes with Node) installed on your system. If you haven't installed Node yet, please do so now.
You might want to install Node via something like NVM, but that's not required.
Open up a terminal and then move to your project folder. Run npm init
to create a minimal package.json
file and afterwards install Sibilisp via:
npm i -D sibilisp
This will install the Sibilisp CLI and transpiler, the base language Sibilant as well as the prelude
toolkit so you are ready after this step. 😌
The CLI supports a read-eval-print-loop (or REPL) mode where you can open up a Node REPL that evaluates Sibilisp code. Go the the folder where you installed Sibilisp and type in the fowllowing:
npx sibilisp --repl
Or just
npx sibilisp -r
This opens a new REPL that waits to evaluate Sibilisp code. To give you a visual feedback that you are working in a Sibilisp REPL instance, the prompt should change to:
sibilisp>
Let's start by evaluating some expressions (or "forms") inside the REPL and then see what their results are. The REPL supports all commands a typical Node REPL supports like .editor
for multi-line editing and .exit
for closing the REPL.
sibilisp> (defvar *greeting* "Hello")
sibilisp> .editor
// Entering editor mode (Ctrl+D to finish, Ctrl+C to cancel)
(defun greet ((subject "World"))
(+ *greeting* " " (if (string? subject)
subject
(as-string subject))))
sibilisp> (greet)
"Hello World"
sibilisp> (greet "John Doe")
"Hello John Doe"
sibilisp> .exit
As you can see, Sibilisp uses s-expressions instead of JavaScript's C-style code. This means that literally every part of Sibilisp's code will be an expression (to be honest: Almost - you can have statements to support certain JS constructs - however, they are meant to be used in special cases) and returns or resembles a value. And it uses so called polish notation, where the operator is noted at the front of the operands. For example: a + b + c + d
becomes + a b c d
.
Besides evaluating Sibilisp forms inside a REPL, the CLI can utilize the transpiler to transpile Sibilisp source files into JavaScript files. Let's try it.
Create a src
directory and inside it a new file with the name hello.slisp
, then open it in your editor of choice*.
Write the following into it (or copy from the REPL):
(defvar *greeting* "Hello")
(defun greet ((subject "World"))
(+ *greeting* " " (if (string? subject)
subject
(as-string subject))))
(.log console (greet))
One interesting thing is the last line which contains a call to a console
. This is interesting, because Sibilisp does not define it's own console
object, so it seems we can call native JavaScript API's from within Sibilisp without having to use any FFI.
That's true. Since Sibilisp compiles to native JavaScript, calling native API's should just feel natural. And besides that, it is also true for every package from NPM. 🤩
For example, imagine you want to set up a REST service with NodeJS and for that use Koa. No problem, just install from NPM:
npm i koa
as you would normally do, create a index.slisp
file and fill in:
(use-all "koa" :as Koa)
(defconstant **APP (new Koa))
(.use **APP
(#(ctx)
(setf ctx 'body "Hello there from Koa!")
ctx))
(.listen **APP 3000)
Then transpile and voilà! 🥳
OK, switch back to the terminal and type the following to compile what you've written:
npx sibilisp --src src/ --dest build/uncompressed/
You can use a shorter form as well:
npx sibilisp -s src/ -d build/uncompressed/
In case you want to use your resulting JavaScript as ES2015+ module, the CLI allows to define the type of output file that is generated via the --filetype
or -f
argument. It accepts the values js
(default value) or mjs
and generates .js
or .mjs
files respectively.
npx sibilisp --src src/ --dest build/uncompressed/ --filetype mjs
The equivalent short form is:
npx sibilisp -s src/ -d build/uncompressed/ -f mjs
Now take a look into the build/uncompressed/
directory that has been created. It should contain a JavaScript file with the name hello.js
that contains your code.
As you can see, Sibilisp doesn't impose any runtime or other dependencies on your resulting code, in the end it's all pure JavaScript. You can now either ship the files as ES2015+ modules or use a JavaScript bundler like Rollup or Webpack for further processing and bundling.
Editor (*)
You can use any editor you like, but tested is VS Code. Some useful extensions are: