-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.boi
103 lines (81 loc) · 2.7 KB
/
demo.boi
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
-- any line beginning with two dashes is a comment.
-- this is anothier comment.
-- let's say hello to the world.
boi, "Hello, World!" boi
-- next, a spin on the classic
-- let's set a variable for the subject being greeted.
boi: subject Boi! boi
boi, "Hello, " boi:subject boi
-- There are two things to note here which may be helpful:
-- * Note 1: We could have put out subject, "Boi!", in quotes
-- * Note 2: To refer to a variable, we use boi:variablename
-- now let's define a function
oh funcy boi
boi, "I am in a function!" boi
BOI
-- and let's call the function
boi! funcy boi
-- a function can return a value by setting its "exit" variable
oh returny boi
boi, "I was called" boi
boi: exit "this is my return" boi
BOI
-- to use this return value, we can pass the function as a token for
-- any function. This is done using square brackets as follows:
boi, [returny] boi
boi: tmp [returny] boi
boi, "tmp is: " boi:tmp boi
-- next, let's look at some built-in functions
boi, [nyan a b c boi:tmp] boi
boi: myInteger [int 42] boi
boi, "myInteger as a char: " boi:myInteger boi
boi, "myInteger as a number: " [dec boi:myInteger] boi
boi, "Should say HELLO: " [int 72] [int 69] [int 76] [int 76] [int 79] boi
boi, "Should say D: " [+ A [int 3]] boi
-- the IsEven function gives us a probability from
-- 1 to 100 that a number is even.
-- Probabilistic programming is fun :D
boi, "There is a " [dec [IsEven myInteger]] "% chance that " [dec myInteger] " is an even number" boi
-- arguments are available to functions as numerated variables
-- beginning with the prefix "arg."
oh echoing boi
boi, "this function was called" boi
boi, boi:arg.0 boi
boi, boi:arg.1 boi
boi, boi:arg.2 boi
BOI
boi! echoing first second third boi
-- we can use + - / * for math
-- note that polish math notation is used, so the
-- operator appears before its operands
boi! set a [int 1] boi
boi! set b [int 2] boi
boi, "1 + 2 = " [dec [+ boi:a boi:b]] boi
-- we can access the "exit" value returned by a
-- function using "ret:exit"
boi! nyan one two three boi
boi, ret:exit boi
-- conditionals are a thing. The things "true"
-- and "false" are the standard boolean values.
boi? nyan true boi
boi, "this will appear" boi
BOI
boi? nyan false boi
boi, "this will not appear" boi
BOI
-- variable declarations can be used to avoid naming
-- conflicts with the parent scope. Simply use the
-- syntax "ONE varname BOI". Note that declaring a
-- variable will explicitly set it to a random value.
ONE CHANGEY BOI
boi? nyan true boi
ONE CHANGEY BOI
boi, "value is " boi:CHANGEY boi
BOI
boi, "value is " boi:CHANGEY boi
-- finally, LOOPS!
boi: inc [int 0] boi
bloop < boi:inc [int 10] boi
boi, "inc is " [dec boi:inc] boi
boi: inc [+ boi:inc [int 1]] boi
BOI