printself("hello there")
Assignment
x,y,z = 1,2,3
list = 0:0.1:10
a,b = 3,2
a,b = b,a
q, w = (if false 1 else 21), 43
Arithmetric
x = 3
x *= 8
x /= 4
x += 9
x -= 7
x **= 3
value = (-1*2) + (10**2)/2
Comparisions
1 <= 3 < 7
4 >= 4 < 7
4 == 4 < 7
10 == 10 != 7
(1,2) == (1,2)
(1,2) != (1,2,3)
not ((1,2,4) == (1,2,3))
not ((1,2) == (1,3))
(not false == 5 > 2 ) == false
(not false == (5 > 2) ) == true
For loop
for x1,y1 = 0,50; x1<10; x1++
print((x1,y1,))
Conditional expression
a, b, c = if false
if true 2,3,1
else 3,4,3
else 5,6,"hello"
k = if 123 > 8 == 8 > 2 >= 4*-1
"Y"
else
"N"
print(k)
Comments
// Line comment
/*
multiline
comment
here
*/
String interpolation
text0 = "hello
${4*12-23} there
"
text1 = "" +
"${ "hello" }" +
"there ${1}"
Conditional statements
a = 2+3
if( a < 10)
a = 100
printself(a == 100)
Function, composition, recursion and scope rules
kep = 10
fun fran(){ kep = 100}
fran()
print(kep == 10)
serra = 1000
fun camel()
{
return do { serra = 234}
tunez = 213
serra = 234
}
camel()
printself(serra == 1000)
pipa = 1000
fun pepe()
{
pipa = 234
return
tunez = 213
}
pepe()
printself(pipa == 1000)
fun brand(a)
{
printself(a == 10)
fun brands()
{
return a-231 + 1
}
return brands()
}
printself(brand(10) == -220)
fun factorial(b)
{
if (b > 1)
factorial(b-1)*b
else 1
}
printself(factorial(1) == 1)
printself(factorial(3) == 6)
printself(factorial(4) == 24)
printself(factorial(-1) == 1)
fun ham() {
fun ham() {
fun ham() {
1
}
1 + ham()
}
1 + ham()
}
ham() == 3
Function pipes, anonymous functions
fun bee(a,b){ return a+2,2 }
foo = {
boo = fun { a,b -> return b*2*a, 1 }
mix = fun { b,a -> b*2*a+1 }
}
fun buu(a){ return a }
(100,1 | bee | foo.boo | { x,y -> x+y }) == 409
Pipe assignation, implicit parameters
t,y = "ssd",2 | { a,b ->
a == "ssd"
b == 2
arguments[0] == "ssd"
arguments[1] == 2
arguments[2] == undefined
a,b,a+b
} | { a,b,c ->
c == "ssd2"
arguments[2] == "ssd2"
a,b+c
} | { it,it }
t == "ssd" and y == "ssd"
x = 3
v = x | {
printself(it == x)
it+2,it
}
Do expression
a = do { 2+3-1 }
Primitives
// all data is immutable
value_number = 102.43
value_string = "hello there"
value_bool = true
value_list = (1,2,3),((4,5),6)
value_dict = {
hello = "there"
there = "h", "i"
so = {
uncivilized = true
}
}
value_undefined = undefined
value_null = null
printself(value_dict)
List access
a = (((10,2),2),3,4)
b0 = a[0]
b1 = a[1]
b2 = a[2]
printself( a[-1] == 4)
printself( a[3] == undefined)
printself( b0[0][0] == 10)
printself( b0[0][1] == 2)
printself( a[1] == 3)
q,w,e = a
r,t = q
y,u = r
printself( y == 10)
printself( u == 2)
i = (3,)
printself(i[0] == 3)
list = 1,2,3,4,4,5,6,7,8
list[1,4]
list[-4,-1]
Dict access
a = {
a = 2,2,3
d = {}
b = 3
2 ="d"
3 = 2
g = 3
k = {
4= 2,3, { 4= 2,3 }
5= 2
}
r = 4
callme = fun { a,b ->
}
itcall = fun {
it+it2+it3
}
arguemntsCall = fun {
return arguments
}
}
assert(a.a[0] == 2 )
assert(a.2 == "d" )
assert(a.k.4[2].4[1] == 3 )
assert(a.callme(1,2) == undefined )
assert(a.itcall(1,23023,2,3) == 6 )
Pipe map, filter special operations
s = 0,2,3,4
(s | filter { it > 2 } )?size == 2
(s | map { it*2 } ) == (0,4,6,8)
(s | filter { it > 2 } | map { it*2 } ) == (6,8)
(s | map { it*2 } | filter { it > 2 } ) == (4,6,8)
(s | map { it*2 } | ?sum ) == 18
Range operations
0:0.4:1 == (0,0.4,0.8)
0:-0.4:1 == (0,0.4,0.8)
1:0.5:0 == (1,0.5,0)
1:-0.5:0 == (1,0.5,0)
1:0 == (1,0)
0:5 == (0,1,2,3,4,5)
Pipe accessors
x = 0:0.25:10 |
map { it?floor, it } |
?group?toList |
map { k,v -> v?sum } |
?first
x == 1.5
Built-in methods: list
list = (3,2),(4,1),(2,6)
list?toString
list?toDict.4 == 1
list?size == 3
list?reverse[0] == (2,6)
list?flat[0,3] == (3,2,4)
list?is == "list"
list?first == (3,2)
list?last == (2,6)
list?lastIndex == 2
list?isEmpty == false
list?isNotEmpty == true
list = (1,2,3),(4,5,6)
list?zip[1] == (2,5)
list = 5,3,2,1,2
list?sort == (1,2,2,3,5)
list?sum == 13
list?max == 5
list?min == 1
list?average == 13/list?size
list?dropFirst == (3,2,1,2)
list?dropLast == (5,3,2,1)
Built-in methods: dict
dict = {
a = 1,2
b = "hello"
c = {}
2 = false
}
dict?toString
dict?toList
dict?size == 4
dict?keys == (2,"a","b","c")
dict?values?first == false
dict?is == "dict"
dict?isEmpty == false
dict?isNotEmpty == true
Built-in methods: string
string = " hello "
multiline = "hello
world"
string?toString == string
string?toList
"23"?toNumber == 23
string?size == 7
"hEllo"?toLowerCase == "hello"
"hello"?toUpperCase == "HELLO"
string?trim == "hello"
string?trimEnd == " hello"
string?trimStart == "hello "
"hello"?capitalize == "Hello"
string?is == "string"
multiline?lines?size == 2
string?isEmpty == false
string?isNotEmpty == true
string?isBlank == false
string?isNotBlank == true
string?first == " "
string?last == " "
string?hashCode == 1409378734
Built-in methods: number
number = 3.4
number?toString == "3.4"
number?toBool == true
number?toList == (0,1,2)
number?trunc == 3
number?round == 3
number?ceil == 4
number?floor == 3
number?abs == 3.4
number?sign == 1
number?cos
number?sin
number?tan
number?cosh
number?sinh
number?tanh
number?negative == -3.4
-3.4?negative == 3.4
number?is == "number"
0 <= 10?random <= 10
0 <= 6?randomInt <= 6
value = 6?randomSign
value == 6 or value == -6
Built-in methods: bool
value = true
value?toString == "true"
value?toNumber == 1
value?flip == 0
value?is == "bool"
Built-in methods: undefined
value = undefined
value?toString == "undefined"
value?is == "undefined"
Built-in methods: null
value = null
value?toString == "null"
value?is == "null"