HadesLang Doc
Search…
Basic Syntax

Hello world

1
with console from std:io
2
console.out("Hello world")
Copied!

Pipelines

1
with list fixed from std:collections
2
with console from std:io
3
4
var fruits = list.of({"Apple", "Banana", "Mango", "Kiwi", "Avocado"})
5
6
fruits
7
|> map(??, {x => x.toLower()})
8
|> filter({x => x.startsWith("a")})
9
//if ?? is not in the parameters, the method is inserted as the first parameter
10
|> forEach(??, {x => console.out(x)})
Copied!

Function guards

1
with console fixed from std:io
2
3
func myFunction(a int) requires a < 10
4
console.out("a is smaller than 10")
5
end
6
7
func myFunction(a int) requires a > 10
8
console.out("a is greater than 10")
9
end
10
11
myFunction(5) // a is smaller than 10
12
myFunction(17) // a is greater than 10
Copied!

Actors

1
with msg from std:io
2
with sleep from std:time
3
4
func ping()
5
receive(m)
6
{:ping, data} => {_ =>
7
sleep.seconds(1)
8
send(data, :pong)
9
}
10
end
11
ping()
12
end
13
14
func pong()
15
receive(m)
16
{:pong, data} => {_ =>
17
sleep.seconds(1)
18
send(data, :ping)
19
}
20
end
21
pong()
22
end
23
24
var pingPid = spawn({_ => ping()}
25
var pongPid = spawn({_ => pong()}
26
27
send(pingPid, {:ping, pongPid})
Copied!

Fibonacci sequence

1
with console from std:io
2
3
func fib(n)
4
if((n is 0) or (n is 1))
5
put n
6
end
7
8
put fib(n-1) + fib(n-2)
9
end
10
11
fib(10) |> console.out
Copied!
Last modified 1yr ago