Skip to content

Commit 1015d01

Browse files
committed
examples: Changed the syntax to the latest one
1 parent 1c679a1 commit 1015d01

17 files changed

+161
-118
lines changed

examples/array2.pics

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11

2-
32
import std.io
43
import std.array
54

6-
let numbers = [1,2,3]
5+
numbers := [1,2,3]
76

8-
let mapped = Array.map(numbers, |x| -> x * 2)
7+
mapped := Array::map(numbers, |x| -> x * 2)
98

10-
IO.println(mapped)
11-
IO.println(Array.join(numbers, "::"))
9+
IO::println(mapped)
10+
IO::println(Array::join(numbers, "::"))
1211

13-
function reduce(xs=[], f, acc) =
14-
when xs {
15-
is [] -> acc
16-
is x:rest -> reduce(rest, f, f(acc, x))
17-
}
12+
reduce :: (xs=[], f, acc) =
13+
when xs {
14+
is [] -> acc
15+
is x:rest -> reduce(rest, f, f(acc, x))
16+
}
1817

19-
let result = reduce(mapped, |acc, x| -> acc + x, 0)
18+
result := reduce(mapped, |acc, x| -> acc + x, 0)
2019

21-
IO.println(Array.contains(mapped, 2))
22-
IO.println(Array.indexOf(mapped, 4))
20+
IO::println(Array::contains(mapped, 2))
21+
IO::println(Array::indexOf(mapped, 4))
2322

examples/arrayfilter.pics

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
import std.io
33

4-
function filter(xs=[], pred) =
4+
filter :: (xs=[], pred) =
55
when xs {
66
is [] -> []
77
is x:rest ->
88
if pred(x) { x:filter(rest, pred) }
99
else { filter(rest, pred) }
1010
}
1111

12-
let nums = [1,2,3,4]
12+
nums := [1,2,3,4]
1313

14-
let greater = filter(nums, |num| -> num > 2)
15-
IO.println(greater)
14+
greater := filter(nums, |num| -> num > 2)
15+
IO::println(greater)

examples/arrays.pics

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
import std.array
33
import std.io
44

5-
let numbers = [1,2,3]
6-
let strings = ["A", "B", "C"]
5+
numbers := [1,2,3]
6+
strings := ["A", "B", "C"]
77

8-
let concat = Array.concat(numbers, strings)
8+
concat := Array::concat(numbers, strings)
99

10-
IO.println(concat)
11-
IO.println(concat.len)
10+
IO::println(concat)
11+
IO::println(concat.len)
1212

13-
let collon_sep = Array.join(strings, ":")
13+
collon_sep := Array::join(strings, ":")
1414

15-
IO.println(collon_sep)
15+
IO::println(collon_sep)
1616

17-
let new = collon_sep:concat
18-
IO.println(new)
17+
new := collon_sep:concat
18+
IO::println(new)

examples/arrayzip.pics

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
import std.io
33

4-
function zip(xs=[], ys=[]) =
4+
zip :: (xs=[], ys=[]) =
55
when [xs, ys] {
66
is [[], _] -> []
77
is [_, []] -> []
88
is [x:xs1, y:ys1] -> [ [x, y] ] : zip(xs1, ys1)
99
}
1010

11-
IO.println(zip)
11+
IO::println(zip)
1212

13-
IO.println(zip([1, 2, 3], [4, 5, 6]))
13+
IO::println(zip([1, 2, 3], [4, 5, 6]))

examples/closures.pics

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11

22
import std.io
33

4-
function map(xs=[], f) =
4+
map :: (xs=[], f) =
55
when xs{
66
is [] -> []
77
is x:rest -> f(x) : map(rest, f)
88
}
99

10-
let add = |a, b| -> a + b
10+
add := |a, b| -> a + b
1111

12-
let inc = add(1)
12+
inc := add(1)
1313

14-
let numbers = [1,2,3]
15-
let mapped = map(numbers, inc)
16-
IO.println(mapped)
14+
numbers := [1,2,3]
15+
mapped := map(numbers, inc)
16+
IO::println(mapped)
1717

18-
let mapped = map(numbers, |num| -> num:numbers)
19-
IO.println(mapped)
18+
mapped := map(numbers, |num| -> num:numbers)
19+
IO::println(mapped)
2020

examples/factorial.pics

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
import std.io
33

4-
function factorial(x=1) =
4+
factorial :: (x=1) =
55
if x <= 1 { 1 }
66
else { x * factorial(x - 1) }
77

8-
let result = factorial(5)
9-
IO.println(result)
8+
result := factorial(5)
9+
IO::println(result)
1010

11-
let result = factorial(100)
12-
IO.println(result)
11+
result := factorial(100)
12+
IO::println(result)
1313

examples/fib.pics

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/fizzbuzz.pics

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import std.io
33
import std.array
44
import std.iters
55

6-
let range = Array.fromRange(1, 50)
6+
range := Array::fromRange(1, 50)
77

8-
Iterators.forEach(range, |i| -> do {
8+
Iterators::forEach(range, |i| -> do {
99

1010
when ((i % 3) == 0, (i % 5) == 0) {
11-
is (true, false) -> IO.println("Fizz")
12-
is (false, true) -> IO.println("Buzz")
13-
is (true, true) -> IO.println("FizzBuzz")
14-
else -> IO.println(i)
11+
is (true, false) -> IO::println("Fizz")
12+
is (false, true) -> IO::println("Buzz")
13+
is (true, true) -> IO::println("FizzBuzz")
14+
else -> IO::println(i)
1515
}
1616

1717
})

examples/gcd.pics

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
import std.io
33

4-
function gcd(a, b=0) =
4+
gcd :: (a, b=0) =
55
when (a, b) {
66
is (_, 0) -> a
77
else -> gcd(b, a % b)
88
}
99

10-
let result = gcd(10, 20)
10+
result := gcd(10, 20)
1111

12-
IO.println(result)
12+
IO::println(result)
1313

examples/hello.pics

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
import std.io
33

4-
IO.println("Hello, world")
4+
IO::println("Hello, world")
55

0 commit comments

Comments
 (0)