Skip to content

Commit c9d7a26

Browse files
committed
examples: Fix formatting and add the syntax changes to some examples
1 parent 8be0a56 commit c9d7a26

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

examples/array2.pics

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ IO::println(Array::join(numbers, "::"))
1111

1212
reduce :: (xs=[], f, acc) =
1313
when xs {
14-
is [] -> acc
15-
is x:rest -> reduce(rest, f, f(acc, x))
16-
}
14+
is [] -> acc
15+
is x:rest -> reduce(rest, f, f(acc, x))
16+
}
1717

1818
result := reduce(mapped, |acc, x| -> acc + x, 0)
1919

examples/church.pics

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
IO :: import std.io
3+
Error :: import std.errors
4+
Array :: import std.array
5+
6+
zero :: (f, x) = x
7+
succ :: (n, f, x) = f(n(f, x))
8+
9+
one := succ(zero)
10+
two := succ(one)
11+
three := succ(two)
12+
13+
add :: (m, n, f, x) = m(f, n(f, x))
14+
mul :: (m, n, f, x) = m(n(f), x)
15+
16+
toInt :: (n) = n(|x| -> x + 1, 0)
17+
18+
four := add(two, two)
19+
nine := mul(three, three)
20+
eight := add(four, four)
21+
22+
IO::println(toInt(four))
23+
IO::println(toInt(nine))
24+
IO::println(toInt(eight))
25+
26+

examples/gcd.pics

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

22
import std.io
33

4-
gcd :: (a, b=0) =
5-
when (a, b) {
6-
is (_, 0) -> a
7-
else -> gcd(b, a % b)
8-
}
4+
gcd :: (a, 0) = a
5+
gcd :: (a, b) = gcd(b, a % b)
96

107
result := gcd(10, 20)
118

examples/rt-checks.pics

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import std.type
44
import std.result { Result }
55

66
saferDiv :: (x, y) =
7-
when (Type::isNumber(x), Type::isNumber(y), x, y) {
8-
is (false, false, _, _) -> Result::err("both arguments are not numbers")
9-
is (false, _, _, _) -> Result::err("1st argument is not a number")
10-
is (_, false, _, _) -> Result::err("2nd argument is not a number")
11-
is (_, _, _, 0) -> Result::err("Divide by zero error")
12-
else -> Result::ok(x / y)
13-
}
7+
when (Type::isNumber(x), Type::isNumber(y), x, y) {
8+
is (false, false, _, _) -> Result::err("both arguments are not numbers")
9+
is (false, _, _, _) -> Result::err("1st argument is not a number")
10+
is (_, false, _, _) -> Result::err("2nd argument is not a number")
11+
is (_, _, _, 0) -> Result::err("Divide by zero error")
12+
else -> Result::ok(x / y)
13+
}
1414

1515
res := saferDiv(50, 2)
1616
error := saferDiv(50, [1])

0 commit comments

Comments
 (0)