This articlerelies excessively onreferences toprimary sources. Please improve this article by addingsecondary or tertiary sources. Find sources: "LiveScript" programming language – news ·newspapers ·books ·scholar ·JSTOR(May 2015) (Learn how and when to remove this message) |
LiveScript | |
---|---|
Paradigms | multi-paradigm,functional,object-oriented |
Designed by | Jeremy Ashkenas, Satoshi Murakami, George Zahariev |
Developers | (same) |
First appeared | 2011; 14 years ago (2011) |
Stable release | |
Typing discipline | dynamic,weak |
Scope | Lexical |
OS | Cross-platform |
License | MIT |
Filename extensions | .ls |
Website | livescript |
Influenced by | |
JavaScript,Haskell,CoffeeScript,F# |
LiveScript is afunctionalprogramming language thattranspiles toJavaScript. It was created byJeremy Ashkenas, the creator ofCoffeeScript, along with Satoshi Muramaki, George Zahariev, and many others.[2] (The name may be a homage to the beta name of JavaScript; for a few months in 1995, it was called LiveScript before the official release.[3])
LiveScript is an indirect descendant ofCoffeeScript.[4] The following"Hello, World!" program is written in LiveScript, but is also compatible with CoffeeScript:
hello=->console.log'hello, world!'
While calling a function can be done with empty parens,hello()
, LiveScript treats the exclamation mark as a single-character shorthand for function calls with zero arguments:hello!
LiveScript introduces a number of other incompatible idioms:
At compile time, the LiveScript parser implicitly convertskebab case (dashed variables and function names) tocamel case.
hello-world=->console.log'Hello, World!'
With this definition, both the following calls are valid. However, calling using the same dashed syntax is recommended.
hello-world!helloWorld!
This does not preclude developers from using camel case explicitly or usingsnake case. Dashed naming is however, common in idiomatic LiveScript[5]
Apipe operator|>
passes the result of an expression on the left of the operator as an argument to the expression on the right of it. LiveScript supports these, as do some other functional languages such asF# andElixir; the argument passed in F# is the last one, but in Elixir is the first one.
"hello!"|>capitalize|>console.log# > Hello!
When parenthesized, operators such asnot
or+
can be included in pipelines or called as if they are functions.
111|>(+)222# > 333(+)12# > 3