Ela lanuage: more fun

ela>select _ [] = []; select fnk (x::xs) = fnk x :: select fnk xs  
ela>dbl x = x*2  
ela>select dbl [1,2,3]  
[2,4,6]
ela>select (\x -> x*2) [1,2,3]  
[2,4,6]
ela>select (*2) [1,2,3]  
[2,4,6]
ela>min (x::xs) = min' x xs where min' cur_min (x::xs) = if cur_min < x then min' cur_min xs else min' x xs; min' cur_min [] = cur_min  
ela>min [44,2,45,6]  
2  
ela>min [44,2,45,6,1]  
1  
ela>inf x = & x :: inf (x+1)  
ela>open list  
ela>take 10 (inf 1)  
[1,2,3,4,5,6,7,8,9,10]
ela>fib = fib' 1 1 where fib' x y = & x :: fib' y (x + y)  
ela>take 10 <| fib  
[1,1,2,3,5,8,13,21,34,55]

Ela language: lists

ela>x=[1,2,3,4]  
ela>x  
[1,2,3,4]
ela>y=5::x  
[5,1,2,3,4]
ela>6::y  
[6,5,1,2,3,4]
ela>1 :: [2,3,4]  
[1,2,3,4]
ela>1 :: 2 :: [3,4]  
[1,2,3,4]
ela>4::3::2::[1]  
[4,3,2,1]
ela>4::3::2::1::[]  
[4,3,2,1]
ela>[x,y,z]=[1,2,3]  
ela>x  
1  
ela>y  
2  
ela>x+y+z  
6
ela>(x :: [y,z]) = [4,5,6]  
ela>x  
4  
ela>y  
5  
ela>z  
6
ela>(x:yz)=[1,2,3]  
ela>x  
1  
ela>yz  
[2,3]
ela>(first :: second :: rest) = [5,4,3,2,1]  
ela>first  
5  
ela>second  
4  
ela>rest  
[3,2,1]
ela>x=[1,2,3]  
ela>x:1  
2  
ela>x:0  
1  
ela>y=[5,6]  
ela>z=x++y  
ela>z  
[1,2,3,4,5,6]
ela>[1,2]++[3,4]  
[1,2,3,4]
ela>head [1,2,3,4]  
1  
ela>tail [1,2,3,4]  
[2,3,4]
ela>tail (tail [1,2,3,4])  
[3,4]
ela>tail [3,4]  
[4]
ela>tail [4]  
[]
ela>tail []  
Error: Empty list.  
ela>isnil []  
true
ela>sum lst = (head lst) + sum (tail lst)  
ela>sum [1,2]  
Error: Empty list.
ela>sum lst = if isnil lst then 0 else (head lst) + sum(tail lst)  
ela>sum [1,2]  
3
ela>sum (x::xs) = x + sum(xs)  
ela>sum [1,2]  
Error: Matched failed.
ela>x=1;y=2  
ela>x  
1  
ela>y  
2
ela>sum [] = 0; sum (x::xs) = x + sum(xs)  
ela>sum [1,2]  
3

Ela language: tuples

ela>x=(21,44)  
ela>x  
(21,44)
ela>y=(1,2,"three")  
ela>y  
(1,2,"three")
ela>length y  
3  
ela>y:2  
"three"  
ela>y:0  
1
ela>a=(666,)  
ela>a  
(666,)
ela>(1,2)==(1,2)  
true  
ela>(1,2)==(2,1)  
false
ela>(1,2)++("three", "four")  
(1,2,"three","four")
ela>sum2 (x1, y1) (x2, y2) = (x1+x2, y1+y2)  
ela>sum2 (1,1) (2,2)  
(3,3)
ela>sum_and_diff x y = (x+y, x-y)  
ela>sum_and diff 5,6  
(11, -1)
ela>(x,y)=(5,6)  
ela>x  
5  
ela>y  
6

Ela language: conditions

ela>x=1  
ela>x==1  
true  
ela>x==2  
false  
ela>if x==1 then "ok" else "wtf?"  
"ok"  
ela>y=(if x==2 then "ok" else "wtf?")  
ela>y  
"wtf?"
ela>5%2  
1  
ela>10%2  
0  
ela>even? x = if x%2 == 0 then "even" else "odd"  
ela>even? 44  
"even"  
ela>even? 11  
"odd"
ela>even x = x%2 == 0  
ela>even 33  
false  
ela>even 2  
true

Ela language: functions

Download at http://elalang.net and run elac.exe:

ela>1  
1

ela>2+2  
4

ela>2+2*2  
6
ela>x=1  
ela>x  
1  
ela>x=2  
Error ELA324: A conflicting definition of 'x'. Shadowing of names in the same lexical scope is not allowed.  
ela>y=2  
ela>x+y  
3
ela>"Hello World"  
"Hello World"
ela>f(x)=x+1  
ela>f(1)  
2  
ela>f(2)  
3
ela>f x = x+1  
ela>f 5  
6
ela>(\x -> x+1) 55  
56
ela>f=(\x -> x+1)  
ela>f 55  
56
ela>f=(\x -> (\y -> y + x))  
ela>f 1  
<f>:*->*
ela>f' = f 1  
ela>f' 55  
56  
ela>f'' = f 2  
ela>f'' 55  
57  
ela>(f 1) 2  
3  
ela>f 1 2  
3
ela>f x = \y -> y+x  
ela>f 1  
<f>:*->*
ela>f 1 2  
3
ela>f(x)= f' where f'(y)= x + y  
ela>f 1 2  
3
ela>f x y = x + y  
ela>f 1 2  
3