LiveScript (programming Language)
   HOME

TheInfoList



OR:

LiveScript is a functional
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
that transpiles to
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
. It was created by
Jeremy Ashkenas Jeremy Ashkenas is a computer programmer known for the creation and co-creation of the CoffeeScript and LiveScript programming languages respectively, the Backbone.js JavaScript framework and the Underscore.js JavaScript library. While worki ...
, the creator of
CoffeeScript CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python, and Haskell in an effort to enhance JavaScript's brevity and readability. Some added features include list comprehension an ...
, along with Satoshi Muramaki, George Zahariev, and many others. (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.)


Syntax

LiveScript is an indirect descendant of
CoffeeScript CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python, and Haskell in an effort to enhance JavaScript's brevity and readability. Some added features include list comprehension an ...
. The following
"Hello, World!" program A "Hello, World!" program is usually a simple computer program that emits (or displays) to the screen (often the Console application, console) a message similar to "Hello, World!". A small piece of code in most general-purpose programming languag ...
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:


Name mangling

At compile time, the LiveScript parser implicitly converts kebab case (dashed variables and function names) to
camel case The writing format camel case (sometimes stylized autological, autologically as camelCase or CamelCase, also known as camel caps or more formally as medial capitals) is the practice of writing phrases without spaces or punctuation and with cap ...
. 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 using snake case. Dashed naming is however, common in idiomatic LiveScript


Pipes

A pipe 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 as F# and
Elixir An elixir is a sweet liquid used for medical purposes, to be taken orally and intended to cure one's illness. When used as a dosage form, pharmaceutical preparation, an elixir contains at least one active ingredient designed to be taken orall ...
; the argument passed in F# is the last one, but in Elixir is the first one. "hello!" , > capitalize , > console.log # > Hello!


Operators as functions

When parenthesized, operators such as not or + can be included in pipelines or called as if they are functions. 111 , > (+) 222 # > 333 (+) 1 2 # > 3


References


External links

* {{JavaScript JavaScript programming language family Software using the MIT license Articles with example code