emulisp
v1.206.0
Published
Description
Downloads
6
Readme
EmuLisp
Javascript partial implementation of PicoLisp
- Home page
- Github pages
- Github repo (
npm
branch)
Instructions
npm install emulisp -g
will make a command available:
pil-njs-w
on Windows,pil-njs
on the other plaforms.
This command should work as the beloved pil
.
Maintainer's note
Please note:
- I'm not the original author.
- The original author is OK with this package.
This package is a quick and dirty way to make EmuLisp available to the NodeJS platform. There is still some issues like:
- it's not the most recent version of EmuLisp,
- the architecture of the package is not optimal/classical regarding good practices for npm packages,
- the version number is not the EmuLisp one since I'm republishing a lot while learning how to package for npm.
Author's note
EmuLisp is a PicoLisp emulator, written in JavaScript. However, in this early version it only covers a tiny subset of PicoLisp. My main motivation for writing this emulator, was that I wanted to learn the PicoLisp basics better.
Version 2
My first version of EmuLisp paid no attention to namespace pollution; there was a very big number of globally declared functions and variables. To make EmuLisp easier to use with JavaScript code from other projects, it has now been re-organized into modules.
The modules
EmuLisp currently consists of three modules:
emulisp_core.js
- the basicsemulisp_js.js
- operations on JavaScript functions and objectsemulisp_cv.js
- Canvas functions
For a simple example on how to use these modules, take a look at the emulisp_console.html
.
The functions exported by emulisp_core.js
are the ones needed in emulisp_js.js
and
emulisp_cv.js
and a few more...
Switching between EmuLisp contexts
Here is an example of how you can work with different contexts, or states, if you should ever have
the need to do so. For simplicity, just use the emulisp-console.html which already has the
EMULISP_CORE
variable ready (from emulisp_core.js
), and do the following in your browser's console:
EMULISP_CORE.eval("(setq L (range 1 5))");
// -> "(1 2 3 4 5)"
s1 = EMULISP_CORE.currentState();
// -> Object
EMULISP_CORE.init();
// -> undefined
EMULISP_CORE.eval("(setq L (range 6 9))");
// -> "(6 7 8 9)"
s2 = EMULISP_CORE.currentState();
// -> Object
EMULISP_CORE.init(s1);
// -> undefined
EMULISP_CORE.eval("L");
// -> "(1 2 3 4 5)"
Some implementation details
Numbers
The Number
data type is simply the JavaScript Number
, which includes floating point numbers.
The /
function thus does floating point division. However, a /t
function is
provided in case you need the division(s) to be truncated. The constants π and e
are available as js:PI
and js:E
.
Function definitions
When you define your own functions, you may currently only use these patterns:
(de foo (X Y ...) <prog>)
, i.e. all arguments evaluated(de foo @ <prog>)
, i.e. a variable number of evaluated arguments(de foo X <prog>)
, i.e. a variable number of unevaluated arguments
Circular lists
Circular lists may be entered using the (a b c .)
notation, and they may also be
printed that way. It is, however, not difficult to include such circular lists into other
structures so that the simple "circular detector" fails to detect. You may know the result.
As long as you stick to "safe circular lists", they shall cause no problem as argument in the
length
function.
Have fun!