-
Notifications
You must be signed in to change notification settings - Fork 7
/
io.sheet
106 lines (71 loc) · 1.43 KB
/
io.sheet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Basic Math
Io> 1+1
==> 2
Io> 2 sin
==> 0.909297
Io> 2 sqrt
==> 1.414214
Variables
Io> a := 1
==> 1
Io> a
==> 1
Io> b := 2 * 3
==> 6
Io> a + b
==> 7
Conditions
Io> a := 2
Io> if(a == 1) then(writeln("a is one")) else(writeln("a is not one"))
a is not one
Io> if(a == 1, writeln("a is one"), writeln("a is not one"))
a is not one
Lists
Io> d := List clone append(30, 10, 5, 20)
==> list(30, 10, 5, 20)
Io> d size
==> 4
Io> d print
==> list(30, 10, 5, 20)
Io> d := d sort
==> list(5, 10, 20, 30)
Io> d first
==> 5
Io> d last
==> 30
Io> d at(2)
==> 20
Io> d remove(30)
==> list(5, 10, 20)
Io> d atPut(1, 123)
==> list(5, 123, 20)
Loops
Io> for(i, 1, 10, write(i, " "))
1 2 3 4 5 6 7 8 9 10
Io> d foreach(i, v, writeln(i, ": ", v))
0: 5
1: 123
3: 20
Strings
Io> a := "foo"
==> "foo"
Io> b := "bar"
==> "bar"
Io> c := a .. b
==> "foobar"
Io> c at(0)
==> 102
Io> c at(0) asCharacter
==> "f"
Io> s := "this is a test"
==> "this is a test"
Io> words := s split(" ", "\t") print
"this", "is", "a", "test"
Io> s findSeq("is")
==> 2
Io> s findSeq("test")
==> 10
Io> s slice(10)
==> "test"
Io> s slice(2, 10)
==> "is is a "