npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

glisp

v0.3.0

Published

A simple lisp interpreter in JS.

Downloads

16

Readme

GLISP - The G LISP Interpreter

Build Status Coverage Status

This is a LISP interpreter, with built-in support for arbitrary precision arithmetic, and immutable data structures.

Usage

const { run } = require('glisp');

run('(+ 1 2)') // 3

Language Features

;; variables
(def one 1)

;; functions
(def id (fn [x] x))

;; let bindings
(let [one 1 two 2]
  (+ one two))  ;; 3

;; quotes
(quote (1 2)) ;; (1 2)

;; unquotes
(let [one 1] (quote (unquote one))) ;; 1

;; do
(do
  (+ 1 2)
  (+ 3 4))  ;; 7

;; conditionals
(if (= 1 1) true false) ;; true

;; macros
(def defn (macro [name args body]
            `(def ~name (fn ~args ~body)))))

(defn double [x] (* x 2))
(double 2)  ;; 4

;; throw errors!
(throw (js/Error "throw up!"))

Data Structures

GLISP uses Immutable.js to power its immutable data structures. GLISP recognizes Immutable.Stack as an executable form.

;; Set
#{1 2 3 4 5}

;; Map
{1 2 3 4}

;; List
[1 2 3 4]

;; Stack
(quote (1 2 3))

JavaScript Interop

Symbols prefixed with js/ will evaluate to the respective property on the global object. Method calls can be made by prefixing the method name with a ..

;; use window.console or global.console
(.log js/console 1 2 3 4 5)

;; push to a List
(.push [1 2 3] 10)

;; set properties on objects
(let [object (.toJS {})]
  (aset object "name" "Ramanpreet Nara")
  (aset object "age" 20)) ;; { name: "Ramanpreet Nara", age: 20 }

;; get properties on objects
(aget (.toJS {"age" 21}) "age") ;; 21

Destructuring

Within let bindings and fn declarations, destructure any collection that conforms to an iteration protocol understood by Iterall.

;; get all args
(def create-seq (fn [& args] args))
(create-seq 1 2 3 4 5)  ;; [1 2 3 4 5]

;; get everything but the first element
(def rest (fn [[x & args]] args))
(rest [1 2 3 4 5])  ;; [2 3 4 5]

;; works in let bindings
(let [[x y] [1 2]]
  (+ x y)) ;; 3

;; ooo... destructure any iterable
(let [[x y] (quote (1 2))]
  [x y]) ;; [1 2]

Numbers

GLISP supports JavaScript's 64 bit floating point numbers, BigNumbers, and Fractions.

;; Floating points!
(+ 0.1 0.2) ;; 0.30000000000000004

;; BigNumbers!
(+ 0.1M 0.2M) ;; 0.3

;; Fractions
(+ 1/3 2/3) ;; 1

;; Compare different number types!
(= 1/1 1 1M) ;; true

;; Beware of floating point errors!
(= (+ 0.1 0.2) 0.3M) ;; throws: Cannot convert a number with >15 significant digits to BigNumber!
(= (+ 0.1 0.2) 3/10) ;; throws: Cannot convert a number with >15 significant digits to Fraction!

Strings

Strings exist and can be created using double quotes.

"Produce side effects!"
"This is a multiline string!
  Yay!"
"You can also \"quote\" within strings!")

Development

# Run tests
> npm test

# Rebuild on file changes
> npm run build:watch

# Launch REPL
> npm run repl