Livescript is Updated

This commit is contained in:
descientist 2015-10-19 19:31:43 +05:30
parent b86ea4d51d
commit 9f609e23e6

View File

@ -22,7 +22,8 @@ Feedback is always welcome, so feel free to reach me over at
[@kurisuwhyte](https://twitter.com/kurisuwhyte) :)
```coffeescript
coffeescript
------------
# Just like its CoffeeScript cousin, LiveScript uses number symbols for
# single-line comments.
@ -30,8 +31,9 @@ Feedback is always welcome, so feel free to reach me over at
Multi-line comments are written C-style. Use them if you want comments
to be preserved in the JavaScript output.
*/
```
```coffeescript
coffeescript
------------
# As far as syntax goes, LiveScript uses indentation to delimit blocks,
# rather than curly braces, and whitespace to apply functions, rather
# than parenthesis.
@ -42,12 +44,11 @@ Feedback is always welcome, so feel free to reach me over at
########################################################################
# Lack of value is defined by the keyword `void` instead of `undefined`
void # same as `undefined` but safer (can't be overridden)
void ,same as `undefined` but safer (can't be overridden)
# No valid value is represented by Null.
null
# The most basic actual value is the logical type:
true
false
@ -56,10 +57,9 @@ false
on; off
yes; no
# Then you get numbers. These are double-precision floats like in JS.
10
0.4 # Note that the leading `0` is required
0.4,Note that the leading `0` is required
# For readability, you may use underscores and letter suffixes in a
# number, and these will be ignored by the compiler.
@ -67,7 +67,7 @@ yes; no
# Strings are immutable sequences of characters, like in JS:
"Christina" # apostrophes are okay too!
"Christina", apostrophes are okay too!
"""Multi-line
strings
are
@ -134,7 +134,6 @@ funRE = //
4 / 2 # => 2
3 % 2 # => 1
# Comparisons are mostly the same too, except that `==` is the same as
# JS's `===`, where JS's `==` in LiveScript is `~=`, and `===` enables
# object and array comparisons, and also stricter comparisons:
@ -185,7 +184,6 @@ two!
# The `:=` operator is available to *reuse* a name from the parent
# scope.
# You can destructure arguments of a function to quickly get to
# interesting values inside a complex data structure:
tail = ([head, ...rest]) -> rest
@ -205,7 +203,6 @@ a = { a: 1 }
copy a, { b: 2 } # => { a: 1, b: 2 }
a # => { a: 1 }
# A function may be curried by using a long arrow rather than a short
# one:
add = (left, right) --> left + right
@ -222,7 +219,6 @@ identity 1 # => 1
divide-by-two = (/ 2)
[2, 4, 8, 16].map(divide-by-two) .reduce (+)
# Not only of function application lives LiveScript, as in any good
# functional language you get facilities for composing them:
double-minus-one = (- 1) . (* 2)
@ -233,7 +229,6 @@ double-minus-one = (- 1) . (* 2)
double-minus-one = (* 2) >> (- 1)
double-minus-one = (- 1) << (* 2)
# And talking about flow of value, LiveScript gets the `|>` and `<|`
# operators that apply a value to a function:
map = (f, xs) --> xs.map f
@ -251,7 +246,6 @@ div = (left, right) -> left / right
div-by-two = div _, 2
div-by-two 4 # => 2
# Last, but not least, LiveScript has back-calls, which might help
# with some callback-based code (though you should try more functional
# approaches, like Promises):
@ -263,7 +257,6 @@ console.log a + b
# Same as:
readFile 'foo', (a) -> readFile 'bar', (b) -> console.log a + b
########################################################################
## 4. Patterns, guards and control-flow
########################################################################
@ -290,7 +283,6 @@ take = (n, [x, ...xs]) -->
| n == 0 => []
| _ => [x] ++ take (n - 1), xs
########################################################################
## 5. Comprehensions
########################################################################
@ -309,7 +301,6 @@ evens = [x for x in oneToTwenty when x % 2 == 0]
# back an object rather than an Array:
copy = { [k, v] for k, v of source }
########################################################################
## 4. OOP
########################################################################