lambdascript
v0.0.0
Published
Compile to javascript with syntaxic sugar for lambdas and other functional goodness
Downloads
1
Maintainers
Readme
node-lambdascript
Compile to javascript with syntaxic sugar for lambdas and other functional goodness
Motivation
The reasons for this (additional) compile to javascript language are:
- Fun! I too want to make my own language
- Getting rid of anonymous functions boilerplate for really short callbacks
- Have a go at simple lambda syntax for asynchronous callbacks
- Other stuff that I find useful when dealing with functional javascript
Lambdascript syntax
First of all, any valid javascript is valid also lambdascript.
lambdas
[1, 2, 3, 4]
.map( x -> 2 * x )
.reduce((r, x) -> {
if (r < x) x+r
else r-x
}, 0)
Under the hood, lambdascript only replaces the lambda with an anonymous function
Installation
npm install --save lambdascript
Usage
the most simple usage is
lambdascript my-script.λs -o my-script.js
This will compile my-script.λs
to my-script.js
.
It is also possible to pipe something in and get the compiled script out
cat my-script.λs | lambdascript | tee my-script.js
this should fit nicely in a transformation pipeline
Of course, you can also make a scripted use of lambdascript
var lambdascript = require('lambdascript');
var input = fs.readFileSync('./my-script.λs');
lambdascript(input, function (err, output) {
fs.writeFileSync('./my-script.js', output);
});
Or you can use the streaming version of it
var lambdascript = require('lambdascript');
fs.createReadStream('./my-script.λs')
.pipe(lambdascript())
.pipe(fs.createWriteStream('./my-script.js'))
Test
Tests are written with mocha and covered with istanbul
You can run the tests with npm test
.
Contributing
Anyone is welcome to submit issues and pull requests
License
Copyright (c) 2014 Florent Jaby
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.