LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
For more information, check out the LiveScript site.
LiveScript 1.3.0 fixes many bugs and adds some new features, including generator and yield support!
You can now use generators and yield in your LiveScript code! A brief rundown:
function* f yield "foo" g = ->* yield from f! yield "bar" h = g! h.next!.value + h.next!.value #=> "foobar"
var g, h; function* f(){ yield "foo"; } g = function*(){ yield* f(); yield "bar"; }; h = g(); h.next().value + h.next().value;
You can create generators by either appending a star *
to the function
keyword, or appending it to LiveScript's arrow notation. This works with the variety of arrows we have.
yield
is simply the same as in JavaScript, and yield from
is JavaScript's yield*
.
To run code using generators and yield using node 0.11, use the --harmony
flag. If running directly with lsc
, use lsc file.ls --nodejs --harmony
to pass the harmony flag to node.
vim-ls has been updated to highlight yield
and also has many other improvements.
require! has been changed around to be more straightforward to use:
require! {a: b}
has been changed to mean b = require('a')
, and
you can now destructure, eg:
require! { fs: filesystem 'prelude-ls': {map, id} path: {join, resolve}:p }
var filesystem, ref$, map, id, p, join, resolve; filesystem = require('fs'); ref$ = require('prelude-ls'), map = ref$.map, id = ref$.id; p = require('path'), join = p.join, resolve = p.resolve;
One bug whose fix may break some code is the precedence of the pipe operator and assign. Assign now has a lower precedence than all pipes, so
result1 = 'hello' |> reverse |> upCase 'OLLEH' == result1 result2 = upCase <| reverse <| \hello 'OLLEH' == result2
Auto infused IIFE were removed as we have for let
now. Change any for ... then let
to for let .... then
.
The browser versions of LiveScript (browser/livescript.js
and browser/livescript-min.js
) are now packaged with browserify. To use the browser version, include the file you want, and then do:
var LiveScript = require("LiveScript");
For example:
<script src="livescript.js"></script> <script type="text/ls"> console.log "boom #{window.location}" </script> <script> var LiveScript = require("LiveScript"); LiveScript.go(); </script>
LiveScript.go()
finds any script tags with type="text/ls"
, compiles them, and executes them.
Optionator is now used for option parsing and help text generation, instead of a custom solution. The --require
option was removed as it was useless.
You can use the --no-header
option to not output the header when compiling. This option is also available when using LiveScript as a library through the header: false
option.
lsc
, not livescript
livescript
was removed from the bin, please use lsc
on the command line now. It is the exact same, but shorter to type!
slake
and Slakefile
s were removed (no need for another build system!), please use make, gulp, grunt, etc.
that
in switchYou can use that
in the default case of a switch statement, to mean the value you are switching upon.
Thank you to Nami-Doc for his numerous contributions, and also Haspacker, Rack Lin (racklin), appedemic, piotrklibert, and Ryan Hendrickson (rhendric) for their contributions as well!
For more information on LiveScript, check out the LiveScript site.
For more on LiveScript and prelude.ls, follow @gkzahariev.
comments powered by Disqus