Skip to content

Commit f5b320d

Browse files
author
sogaiu
committed
Improve consistency of examples
1 parent 8c76285 commit f5b320d

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

examples/defn-.janet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# In a file main.janet
88
(import module)
99

10-
(module/not-exposed-fn 10) # -> Unknown symbol error
10+
(module/not-exposed-fn 10) # -> compile error: unknown symbol module/not-exposed-fn
1111

1212
# Same as
1313
(defn not-exposed-fn

examples/defn.janet

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
[x]
33
(print (+ x 1)))
44

5-
(simple 10) # -> 11
5+
# prints 11
6+
(simple 10) # -> nil
67

78
(defn long-body
89
[y]
@@ -22,7 +23,7 @@
2223
[x y z & more]
2324
[x y z more])
2425

25-
(with-tags 1 2) # raises arity error
26+
(with-tags 1 2) # compile error: <function with-tags> expects at least 3 arguments, got 2
2627
(with-tags 1 2 3) # -> (1 2 3 ())
2728
(with-tags 1 2 3 4) # -> (1 2 3 (4))
2829
(with-tags 1 2 3 4 5) # -> (1 2 3 (4 5))

examples/eval-string.janet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
(eval-string "(+ 1 2 3 4)") # -> 10
2-
(eval-string ")") # -> parse error
3-
(eval-string "(bloop)") # -> compile error
4-
(eval-string "(+ nil nil)") # -> runtime error
2+
(eval-string ")") # -> error: unexpected closing delimiter )
3+
(eval-string "(bloop)") # -> error: unknown symbol bloop
4+
(eval-string "(+ nil nil)") # -> error: could not find method :+ for nil or :r+ for nil

examples/eval.janet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(eval '(+ 1 2 3)) # -> 6
2-
(eval '(error :oops)) # -> raises error :oops
3-
(eval '(+ nil nil)) # -> raises error
2+
(eval '(error :oops)) # -> error :oops
3+
(eval '(+ nil nil)) # -> error: could not find method :+ for nil or :r+ for nil

examples/loop.janet

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,63 @@
1-
# -> prints 0123456789 (not followed by newline)
1+
# prints 0123456789 (not followed by newline)
22
(loop [x :range [0 10]]
3-
(prin x))
3+
(prin x)) # -> nil
44

55
# Cartesian product (nested loops)
66

7-
# -> prints 00010203101112132021222330313233
7+
# prints 00010203101112132021222330313233
88
# Same as (for x 0 4 (for y 0 4 (prin x y)))
99
(loop [x :range [0 4]
1010
y :range [0 4]]
11-
(prin x y))
11+
(prin x y)) # -> nil
1212

13-
# -> prints bytes of "hello, world" as numbers
13+
# prints bytes of "hello, world" as numbers
1414
(loop [character :in "hello, world"]
15-
(print character))
15+
(print character)) # -> nil
1616

17-
# -> prints 1, 2, and 3, in an unspecified order
17+
# prints 1, 2, and 3, in an unspecified order
1818
(loop [value :in {:a 1 :b 2 :c 3}]
19-
(print value))
19+
(print value)) # -> nil
2020

21-
# -> prints 0 to 99 inclusive
21+
# prints 0 to 99 inclusive
2222
(loop [x :in (range 100)]
23-
(print x))
23+
(print x)) # -> nil
2424

2525
# Complex body
2626
(loop [x :in (range 10)]
2727
(print x)
28-
(print (inc c))
29-
(print (+ x 2)))
28+
(print (inc x))
29+
(print (+ x 2))) # -> nil
30+
# prints n, n+1, n+2 (for n = 0 through 9) each time through the loop
31+
# 0
32+
# 1
33+
# 2
34+
# ...
35+
# 9
36+
# 10
37+
# 11
3038

3139
# Iterate over keys
3240
(loop [k :keys {:a 1 :b 2 :c 3}]
33-
(print k))
41+
(print k)) # -> nil
3442
# print a, b, and c in an unspecified order
3543

3644
(loop [index :keys [:a :b :c :d]]
37-
(print index))
38-
# print 0, 1, 2, and 3 in order.
45+
(print index)) # -> nil
46+
# print 0, 1, 2, and 3 in order.
3947

4048
(defn print-pairs
4149
[x]
4250
(loop [[k v] :pairs x]
4351
(printf "[%v]=%v" k v)))
4452

45-
(print-pairs [:a :b :c])
53+
(print-pairs [:a :b :c]) # -> nil
54+
# prints
4655
# [0]=:a
4756
# [1]=:b
4857
# [2]=:c
4958

50-
(print-pairs {:a 1 :b 2 :c 3})
59+
(print-pairs {:a 1 :b 2 :c 3}) # -> nil
60+
# prints
5161
# [:a]=1
5262
# [:b]=2
5363
# [:c]=3
@@ -56,11 +66,11 @@
5666
# of the loop
5767

5868
(loop [x :range [0 100] :when (even? x)]
59-
(print x))
69+
(print x)) # -> nil
6070
# prints even numbers 0, 2, 4, ..., 98
6171

6272
(loop [x :range [1 100] :while (pos? (% x 7))]
63-
(print x))
73+
(print x)) # -> nil
6474
# prints 1, 2, 3, 4, 5, 6
6575

6676
# Consume fibers as generators
@@ -71,15 +81,15 @@
7181
(yield i)))))
7282

7383
(loop [x :in f]
74-
(print x))
84+
(print x)) # -> nil
7585
# print 0, 1, 2, ... 99
7686

7787
# Modifiers in nested loops
78-
7988
(loop [x :range [0 10]
8089
:after (print)
8190
y :range [0 x]]
82-
(prin y " "))
91+
(prin y " ")) # -> nil
92+
# prints
8393
# 0
8494
# 0 1
8595
# 0 1 2
@@ -89,3 +99,4 @@
8999
# 0 1 2 3 4 5 6
90100
# 0 1 2 3 4 5 6 7
91101
# 0 1 2 3 4 5 6 7 8
102+

0 commit comments

Comments
 (0)