LIPS Is Pretty Simple

Summary

LIPS is Simple Lisp in JavaScript

Key features:

Demo

Installation

Node

npm install @jcubic/lips
    

then you code use:


var {exec} = require('@jcubic/lips');
// or
import {exec} from '@jcubic/lips';
    

Browser

When using in browser you need to include the file


<script src="https://unpkg.com/@jcubic/lips"></script>
    

Then you have access to lips object that you can upack with ES6.


var {exec} = lips;
    

You can use lips.exec to evaluate the code:


exec(string).then(function(results) {
     results.forEach(function(result) {
         console.log(result);
     });
});
    

exec function always return a promise event that any of the expressions return promise. The only expression that explicitly return promise is let and let*, so you can use fetch and json or text in one expression.

Or you can split the process using this functions:


var {evaluate, parse, tokenize, exec} = lips;
parse(tokenize(string)).foEach(function(code) {
    evaluate(code);
});
    

with evaluate you need to check the type if it's Promise you need to wait for it.

evaluate function also accept two more arguments:

The result of both exec and evaluate can also be lips.Pair that you can convert to Array using pair.toArray(). If the function return number it will be wrapped with lips.LNumber, the value will be in value property it will be BigInt, bn.js or normal JavaScript number. To get value of the LNumber you can call toString() or valueOf() that will convert to native number but you may lost precision or its bigness.

You can also create dynamic scope if you call evaluate('code', true).

You can also execute LIPS code from script tag, just include code like this


  <script type="text/x-lips">
    (print "hello")
    ;; this will load and evaluate external file
    (load "example.lips")
  <script>
    

You can also use src attribute to link to source file


  <script type="text/x-lips" src="example.lips"><script>