Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

maplescript

jgnewman9MIT0.0.6

A friendlier Lisp over JavaScript

javascript, language, maple, maplescript, compiler, transpiler, functional

readme

MapleScript

A friendlier Lisp over JavaScript.

Build Status

(make (delicious code)
  (maplescript:compile code))

MapleScript is an intuitive, application-focused Lisp dialect that compiles to JavaScript. The language itself contains both a built-in event system and a virtual DOM, as well as a JSX-like syntax for creating virtual nodes, all in about 24kb of minified overhead.

Read the official docs.

Quick Overview

If you're not familiar with the term, Lisps are a family of languages where most things in the language look (like this). Lists enclosed in parentheses are called "s-expressions".

MapleScript is different from ClojureScript (another Lisp over JavaScript) in that it has a much simpler syntax, sticks to JavaScript's native data types, and implements functionalism less rigidly.

The purpose behind MapleScript is to allow you to trade out 100kb+ libraries for a much smaller language that gives you the same core power natively. To illustrate, the MapleScript repository includes an ~8k framework called Syrup that leverages this power to help you build reactive, component-based applications with a redux-like state and lifecycle events.

Here are a few examples of things you can do in MapleScript:

-- Create a factorial calculator

(make (factorial n)
  (if
    (?< n 2)
      1
    (* n (factorial (- n 1)))))

-- Create a factorial calculator with pattern matching!

(make (factorial 0) 1
      (factorial n) (* n (factorial (- n 1))))

-- More easily use Symbols, especially as object keys

(make person {
  :name 'John'
  :eyes 'hazel'
  :hair 'brown'
})

person:name           =>  'John'
person:age?:birthday  =>  undefined

-- Enjoy more accurate type checking

(m:typeof {})     =>  :object
(m:typeof null)   =>  :null
(m:typeof [1 2])  =>  :array

-- Chain context between function calls

(-> (jquery '#my-div')
    (&.addClass 'my-class')
    (&.hide))

(-> (returnPromise)
    (&.then (@ [result] (returnPromise result)))
    (&.then (@ [result] (returnPromise result)))
    (&.then (@ [result] result)))

-- Use the built-in event system

(m:handle :my-event (@ [data] (m:log data)))
(m:signal :my-event 'foo')

-- Generate nodes in a virtual DOM!

(make title
  <h1 {:class 'my-class'}>
    'Hello, world!'
  </h1>
)

-- Turn them into real html nodes!

(make renderedTitle (m:vdom:render title))

-- Inject them into a web page!

(m:vdom:injectNodes renderedTitle '#target-selector')

-- Diff two versions of a virtual DOM!

(make title2
  <h1 {:class 'different-clas'}>
    'Goodbye, world!'
  </h1>
)

(make patches (m:vdom:diff ))

-- Automatically apply changes from a diff!

(m:vdom:patchNodes renderedTitle patches)

Plus, use it with Browserify, Gulp, and Webpack!

Read the official docs.

changelog

v.0.0.6-a

  • Adds 2 new library functions:
    • (m:contains data value) - Determines whether value is contained in data where data is a string or an array. For example, (m:contains ['a' 'b' 'c'] 'b') => true
    • (m:hasKey obj key) - Determines whether an object obj owns a key key. For example (m:hasKey {:foo 'bar'} :foo) => true
  • Removes some unneeded compiler complexity

v.0.0.5-a

  • Fix a string interpolation bug where we got unexpected results when the string began with an interpolation block.
  • Various clarifications in the docs.
  • Docs are now more mobile responsive.
  • Removed some extraneous compile code leftover from old techniques.

v.0.0.4-a

Contains significant syntax changes designed to boos readability and declutter the keyword space.. This version is not compatible with previous versions.

  • # no longer denotes a comment. Use -- instead.
  • ### ... ### no longer denotes a comment. Use --- ... --- instead (like Yaml frontmatter).
  • @ no longer denotes this. Use & instead.
  • fn no longer denotes an anonymous function. Use @ instead. More specifically, (@ [x] (+ x x)).
  • make must take an even number of arguments. If you are defining a function with multiple commands, wrap them up in a do block.
  • make plays into new syntax for polymorphic functions. Every odd numbered argument is a pattern and every even numbered argument is the command the pattern represents. More specifically, rather than (make f (of [x] y) (of [x x] z)), the new syntax is (make (f x) y (f x x) z). As such, the of form has been removed.
  • element special form has been removed. Define a normal function instead.
  • args no longer denotes arguments in the form of an array. Instead, a reference to arguments will return an arrayified version of the arguments object. This avoids adding an extra keyword as well as creating a lot of unnecessary argument arrays. This means expressions such as (arguments.forEach foo) and (m:map arguments foo) will now work.
  • Includes multiple tweaks to boost efficiency and reduce file size.