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.2.0 adds new features, removes deprecated ones, improves compilation, and fixes many bugs.
This is a new addition to our looping constructs, which acts like wrapping the for
loop body with a let
statement. This allows you to create functions inside a loop which use the current (not final) value of loop variables. It also keeps the loop variables from being exposed to the surrounding scope.
functions = for let x in [1 2 3] -> x functions[0]() #=> 1 functions[1]() #=> 2 functions[2]() #=> 3
var functions, res$, i$, len$; res$ = []; for (i$ = 0, len$ = [1, 2, 3].length; i$ < len$; ++i$) { res$.push((fn$.call(this, [1, 2, 3][i$]))); } functions = res$; functions[0](); functions[1](); functions[2](); function fn$(x){ return function(){ return x; }; }
If you end your filename with .json.ls
, the file will automatically be compiled to json with the .json
extension, without having to specify that you are compiling JSON specifically using the -j/--json
option.
For example, lsc -c file.json.ls
produces file.json
You can currently hush functions (which means stopping them from automatically adding return statements) by adding a not !
in front of the entire function definition. For example, !-> ...
or !(x) -> ...
. To make things easier, you can now simply have the !
in front of the arrow. This allows you to add parameters to your function in the future without having to deal with moving the !
.
(x) !-> x (x) !~> x (x) !--> x (x) !~~> x
We now have improved compilation for calls on partially applied functions and the compose operator.
When you call a partially applied function, if there is only one parameter left, then the compilation is optimized.
2 |> pow _, 3 |> mod _, 3 #=> 2
mod(pow(2, 3), 3);
The compose operator no longer uses a helper function, but compiles to exactly what you would write by hand:
h = f . g
var h; h = function(){ return f(g.apply(this, arguments)); };
A comment is now added at the top of the generated JavaScript, showing which version of LiveScript the file was generated with. // Generated by LiveScript 1.2.0
prelude.ls has received a huge update, and is now at version 1.0.3. With the new version, some changes had to be made to the -d/--prelude
flag. The flag now only requires and imports all of prelude.ls if you are using it with the REPL. If you are compiling, it does not add the code to automatically require prelude.ls any more - you must do this yourself, using the new guidelines which recommend only importing what you need.
The REPL is now automatically started without printing the help information with a bare call of lsc
. You can still print the help using the -h/--help
option.
The REPL prompt is now simply ls>
.
$ lsc LiveScript 1.2.0 - use 'lsc --help' for more information ls>
Several deprecated features have been removed.
The inexistence operator !?
was removed because it caused inconsistencies with using the existence operator on a bang !
call. Please use the negation of the existence operator instead - change x!?
to not x?
.
The long concatenation operator +++
has been replaced with ++
as it is shorter. Please use it instead - change xs +++ ys
to xs ++ ys
. Note that you must either doubly space as the preceding example, or not space at all: xs++ys
. Having one space on one side of the operator, and no space on the other, not only looks terrible, but denotes use of the increment operator, eg. f ++x
calls f
with x
incremented.
undefined
as an alias to void
has been removed - the alias was unnecessary. Please change undefined
to void
.
The where
statement has been removed. It could not be implemented in the way desired - it may come back in the future if it can be implemented properly. Please use a let
statement or local variables instead. Please change
x = y + z where y = 1, z = 2
to
x = let y = 1, z = 2 y + z
Single line cascades were removed as well. They were not that useful, and created ambiguities with the multiline cascade syntax. Change obj..name = 2
to obj <<< name: 2
.
Thank you to Nami-Doc for his numerous contributions to this release! Also thanks to satyr (through coco), killdream, clkao, viclib, dtinth, and racklin for their contributions to this release 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