LiveScript 1.3.0 released - Generators and Yield!

4 Oct 2014 - George Zahariev

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.

1.3.0

LiveScript 1.3.0 fixes many bugs and adds some new features, including generator and yield support!

Generators and Yield

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!

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;

Pipe and Assign Precedence

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

Auto infused IIFE were removed as we have for let now. Change any for ... then let to for let .... then.

Browser version

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.

Option parsing and help

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.

No header option

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.

Use 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

slake and Slakefiles were removed (no need for another build system!), please use make, gulp, grunt, etc.

that in switch

You can use that in the default case of a switch statement, to mean the value you are switching upon.

Thanks

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, .

comments powered by Disqus