Dipl.-Inf. (FH) Marco Emrich
Oct 2014 @ XP-Days
„I don't think of myself as a guru ...“Source: http://www.yuiblog.com
„...he had 10 days to create and produce a [...] programming language ...“www.computer.org/csdl/mags/co/2012/02/mco2012020007.pdf
„YES!“
Oct. 4: LiveScript 1.3
Screenshot from Oct. 10
gulp --require LiveScript
console.log \HelloWorld
if 2 + 2 == 4
console.log \Heyho
x = if 2 + 2 == 4
then 10
else 0
hours-per-day = 8
if hours-per-day?
that * 5
add = (x, y) -> x + y
console.log add 2, 3
console.log add 2 3
console.log 3 `add` 4
$ \div .find \a .html!
add = (x = 4, y = 3) -> x + y
add 2
sayHello = -> \Hallo
#alert(sayHello)
sayHello()
sayHello!
sayHello().length
sayHello!length
#[1 2 3].reverse!slice 1
l 64_000km
l 2~1000
l 6~12
l 16~ff
l on, off
l yes, no
l "The answer is #{2 + 2}"
variable = "world"
l "Hello #variable"
l 'string can be multiline
and go on and on
beginning whitespace is
ignored'
l '''
string can be multiline
with newlines
and go on and on
beginning whitespace is
ignored
'''
person =
age: 23
eye-color: 'green'
height: 180cm
oneline = color: 'blue', heat: 4
x = 1
y = 2
obj = {x: x, y: y}
obj = {x, y}
{+debug, -live}
[1 2 3 true \word 'hello world']
my-list =
32 + 1
$ \body .width!
'beautiful'
tree =
* 1
* 2
3
4
* 5
6
* 7
8
9
<[list of words]>
l [1 to 5]
l [1 to 11 by 2]
l [4 to 1]
l [to 5]
l [\A to \D]
list = [\a to \d]
l list[1, 3]
l list[1 to 3]
l list[*-2]
l [1 til 3]
list = [\a to \d]
list[1 til 3] = [7 8]
l list
2 + 4 == 6
/^e(.*)/ == 'enter'
\boom is 'boom'
2 + 2 is not 4
0 + 1 isnt 1
# hello should startWith h
'hello' `startsWith` 'h'
l 1 < 2 < 4
l 4 <? 8
l 2 in [1 2 3 4 5]
l \id of id: 23, name: \rogers
d <[ one two three ]> * \-
d <[a b]> ++ <[c d]>
d "Hello World" * 3
d 'say yeah' - /e/
d 'say-yeah-ho' / \-
l typeof /^/
#l typeof! /^/
for x in [1 to 5]
l x
result = for i in [1 to 5]
i * 2
result = for i in [1 to 5] | i % 2 == 0
i * 2
result = for let x, i in [\a to \f]
"#i: #x"
result = for k, v of {a: 1, b: 2}
"#k#v"
d [x * 2 for x to 10]
object = a: 1, b: 2, c: 3
d ["#k: #v" for k, v of object]
d [.. + 1 for [1 2 3]]
list-of-obj =
* name: 'Alice'
age: 23
* name: 'Betty'
age: 26
d [..name for list-of-obj]
f = (p) ->
| p.length < 3 => "too small"
| p.length < 7 => p.length
| otherwise => p.slice 3
f "Hello World"
fact = ->
| it == 0 => 1
| otherwise => it * fact(it - 1)
#l fact 170
isPrime = function(n) {
var div;
return (function(){
var i, to, results = [];
for (i = 2, to = n / 2; i <= to; ++i) {
results.push(i);
}
return results$;
}()).every(function(){
return n % div !== 0;
});
};
isPrime = (n) -> false
[i for i from 1 to 20 | isPrime i] * ' ' == "1 2 3 5 7 9 11 13 15 17 19"
class A
(@x) ->
property: 1
method: (y) ->
@x + @property + y
a = new A 3
a.x #=> 3
a.property #=> 1
a.method 6 #=> 10
...autobinding with ~>
constructor and statics with @@
inheritance with extends
mixins with implements
super ...
and super!
Object.defineProperty with ~
clone and cloneport with ^^
, <<<<
and with
times = (x, y) --> x * y
times 2, 3
#double = (x) -> times 2, x
#double = times 2
#double 5
[first, second] = [1, 2]
l first
l second
[head, ...tail] = [1 to 5]
l head
l tail
[first, ...middle, last] = [1 to 5]
l first
l middle
l last
{name, age} =
weight: 110
name: 'emma'
age: 20
set-cords = ({x, y}) -> "#x,#y"
set-cords y: 2, x: 3
set-cords =
({x = 1, y = 3} = {}) -> "#x,#y"
set-cords y: 5
#set-cords!
'Hallo'.length
(.length)('Hallo')
require! 'prelude-ls'
require! <[ fs path ]>
require! {
fs
path
lib: foo
}
{map} = require 'prelude-ls'
data = [{name: 'alice', age: 19},
{name: 'tessa', age: 17}]
map (.name), data
{map} = require 'prelude-ls'
map (.toUpperCase!), ['hi', 'there']
#map (.join '-'), [[1, 2, 3], [4, 5]]
{map} = require 'prelude-ls'
map (* 2), [1 2 3]
{filter, even} = require 'prelude-ls'
filter even, [1 to 6]
{filter} = require 'prelude-ls'
data = [{name: 'alice', age: 19},
{name: 'tessa', age: 17}]
filter (.age > 18), data
{map, sum, fold1} = require 'prelude-ls'
sum [1 2 3]
#fold1 (+), [1 2 3]
{minimum, fold1} = require 'prelude-ls'
minimum [14 35 -7 46 98]
#fold1 (<?), [14 35 -7 46 98]
{partition} = require 'prelude-ls'
scores = [49 58 76 43 88 77 90]
[passed, failed] = partition (> 60), scores
d passed
even = -> it % 2 == 0
invert = -> not it
odd = invert << even
#odd = even >> invert
odd 4
{filter, even, sum, map} = require 'prelude-ls'
sum(map((* 2), filter(even, [1 to 5])))
[1 to 5] |> filter even |>
map (* 2) |> sum
const x = 10
#if false then x = 3
<- setTimeout _, 500
<- setTimeout _, 500
l (new Date).getSeconds()
1 ... 100
/ 3: Fizz
/ 5: Buzz
/ 7: Bazz
1,2,Fizz,4,Buzz,
Fizz,Bazz,8,Fizz,Buzz,
11,Fizz,13,Bazz,FizzBuzz,16
[1 to 100].map (number) ->
[k for k, v of {
Fizz: 3, Buzz: 5, Bazz: 7
} when number % v == 0] * '' or
number
[1 to 100]map ->
[k+\zz for k,v of {
Fi:3,Bu:5,Ba:7
}|it%v<1]*''||it
64 characters
calc = -> null
d calc("") == 0
d calc("3") == 3
d calc("1,2,3") == 6
d calc("1,1000,2,3") == 6
d calc("//*1*1000*2*3") == 6
d calc("//:2:2:9999:2345:5") == 9
0 characters