Skip to content
/ lips Public
forked from jcubic/lips

Scheme based powerful lisp interpreter written in JavaScript

License

Notifications You must be signed in to change notification settings

ElonVolo/lips

 
 

Repository files navigation

LIPS - Scheme Based Powerful Lisp Language

npm 1.0.0 Complete travis Coverage Status Join Gitter Chat GitHub license GitHub stars Tweet NPM Download Count JSDelivr Download count

Matomo trakcing piksel LIPS at Product Hunt

LIPS is a powerful Scheme-based, Lisp language written in JavaScript. It is based on the Scheme dialect and the R5RS/R7RS specifications. It has extensions to make it easier to interact with JavaScript. It work both in the browser and with Node.js.

The name is a recursive acronym which stands for LIPS Is Pretty Simple.

Demo

Demo

1.0 Beta demo

Features

  • Literal regular expression.
  • Asynchronous execution.
  • Possibility to add new syntax (similar to vectors and object).
  • Powerful introspection.
  • Great integration with JavaScript.
  • Auto formatting lisp of code (pretty print)
  • Lisp and hygienic Scheme macros and macroexpand.
  • Builtin help system.

Installation

To install you can use npm (or yarn):

npm install @jcubic/lips

or yarn:

yarn add @jcubic/lips

To install 1.0.0 beta version use:

npm install @jcubic/lips@beta

then include the file in the script tag. You can grab the version from unpkg.com

https://unpkg.com/@jcubic/lips

or from jsdelivery

https://cdn.jsdelivr.net/npm/@jcubic/lips/dist/lips.min.js

and beta version

https://cdn.jsdelivr.net/npm/@jcubic/lips@beta/dist/lips.min.js

Bookmarklet REPL

You can also run the REPL on any page while you learn Scheme using the bookmarklet:

https://github.com/jcubic/lips/blob/master/lib/js/bookmark.js

Create any link in your bookmarks, edit it and copy paste the content of that file. Affter you click on the link it will create the REPL at the bottom of the page. (NOTE: It may not work on every page because of content security policy; e.g. google.com or gihub.com)

If you have trouble with creating the bookmarklet you can open LISP Scheme home page where you can find a link that you can drag to your bookmarks.

Usage

The simplest way is to include the lips code in the script tag:

<script type="text/x-scheme" bootstrap>
(let ((what "world")
      (greet "hello"))
   (display (string-append "hello" " " what)))
</script>

or use the src attribute:

<script type="text/x-scheme" bootstrap src="example.scm"></script>

Boostraping Scheme system

Big part of LIPS is written in LIPS itself, but to use full power of LIPS you need to load those additional Scheme files. The easiest way is to add bootstrap attribute on first script tag with text/x-scheme type. By default it will use CDN from jsdelivr. To load each file using builtin load function (that will fetch the file using ajax and evaluate it).

Second option (before beta.10 it was the only option) you can bootstrap LIPS yourself.

You can call this Scheme code:

(let ((e lips.env.__parent__))
    (load "./lib/bootstrap.scm" e)
    (load "./lib/R5RS.scm" e)
    (load "./lib/R7RS.scm" e))

you need to use path to lib files, you can host them yourself or use CDN.

(let ((e lips.env.__parent__)
      (path "https://cdn.jsdelivr.net/gh/jcubic/lips@devel/lib/"))
  (load (concat path "bootstrap.scm") e)
  (load (concat path "R5RS.scm") e)
  (load (concat path "R7RS.scm" e)))

The last option is to create one big file by concatenation of LIPS files and your own code:

cat ./node_modules/@jcubic/lips/lib/*.scm app.scm > all.scm

and load that in script tag:

<script src="all.scm" type="text/x-scheme"></script>

This is not ideal because if your project have multiple files you will not be able to use load.

Solution may be to process the file like Webpack and create a one bundle, (replace load calls with the code itself).

Running LIPS programmatically

var {exec} = require('@jcubic/lips'); // node
// or
var {exec} = lips; // browser

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

When running exec you will also need to bootstrap the language and loaded files from /lib/ directory.

More documentation about stable version in Getting Started Guide and in docs page.

Documentation about beta version can be found in v1.0 draft document.

Standalone executable

NOTE: Executable don't require bootstrapping lib files.

If you install lips globally with:

npm install -g @jcubic/lips

you can run the interpreter from the terminal:

LIPS: Scheme interactive terminal

You can also run code in a string with:

lips -c '(let ((what "World")) (display (string-append "Hello " what)))'

and you can run a file using:

cat > foo.scm <<EOF
(let ((what "World"))
  (display (string-append "Hello " what))
  (newline))
EOF

lips foo.scm

You can also write executable files that use lips using shebang (SRFI-22)

cat foo.scm
#!/usr/bin/env lips

(let ((what "World"))
  (display (string-append "Hello " what))
  (newline))

chmod a+x foo.scm
./foo.scm

Executables also return a S-Expression according to SRFI-176 use lips --version or lips -V.

Credits

License

Released under MIT license
Copyright (c) 2018-2020 Jakub T. Jankiewicz

About

Scheme based powerful lisp interpreter written in JavaScript

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 66.4%
  • Scheme 32.0%
  • Other 1.6%