baby-racket

2.0.3 • Public • Published

npm version

baby-racket

A subset of Racket created entirely in Javascript without external dependencies. The goal of this project is to create a suitable substitute language for Racket's Student Languages.

Currently implemented:

  • Numbers & Arithmetic
  • Structs
  • Vectors
  • Strings
  • Symbols
  • Booleans
  • Proper lists
  • Recursion
  • Lambdas
  • Local definitions
  • Conditional branching (cond, if)
  • check-expect / check-equal?

Link to In-Browser IDE

NOTE:

  • this project no longer supports the "mykanren" implementation of minikanren as of version 2.0.0
  • check-expect actually functions more like check-equal? and both refer to the same function under the hood
import {prettyEvaluate, evaluate, prettify, STANDARD_ENV} from 'baby-racket';

prettyEvaluate("'((+ 1 1) (* 4 4))") // -> '(2 16)

evaluate("'((+ 1 1) (\* 4 4))") // -> [2, 16]
prettify(evaluate("'((+ 1 1) (\* 4 4))")) // -> '(2 16) : equivalent to prettyEvaluate

// custom env
let myEnv = STANDARD_ENV.clone()

... do things with myEnv ...

// with custom environment and minikanren mode on
evaluate("'((+ 1 1) (\* 4 4))" , {env: myEnv})

// if you want to evaluate an entire file instead of a single expression, use evaluateFile
// you will get an array of each expression in the file in order of appearance
evaluateFile("(+ 1 1) (+ 1 1)", {env: myEnv}) // -> [2, 2]

Package Sidebar

Install

npm i baby-racket

Weekly Downloads

5

Version

2.0.3

License

ISC

Unpacked Size

25.3 kB

Total Files

12

Last publish

Collaborators

  • rymaju