You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jazzy currently only supports expressions with number and boolean literals. To execute a jazzy expression, either type it out in the REPL and press enter:
33
-
```bash
34
-
=^..^= 1 + 1
34
+
jazzy currently only supports collections of variable assignments and expressions on integers, floating-point numbers, and booleans. To execute a jazzy program, either type it out in the REPL one line at a time:
35
+
36
+
```
37
+
=^..^= let x := 1;
38
+
=^..^= x + 1
35
39
2
36
40
37
41
=^..^=
@@ -42,237 +46,64 @@ or create a `.jzy` file with a single expression in it:
42
46
1 < 3 and 99 >= 100
43
47
```
44
48
and invoke the compiler on it:
45
-
```bash
46
-
$ jazzy expression.jzy
47
-
false
48
-
```
49
-
50
-
### Operators
51
-
#### Addition (`+`)
52
-
| Left Operand | Right Operand | Output |
53
-
|:------------:|:-------------:|:-------:|
54
-
| Integer | Integer | Integer |
55
-
| Float | Float | Float |
56
-
57
-
The addition operator takes two numbers and adds them together:
58
-
```
59
-
=^..^= 1 + 2
60
-
3
61
-
```
62
-
63
-
#### Subtraction (`-`)
64
-
| Left Operand | Right Operand | Output |
65
-
|:------------:|:-------------:|:-------:|
66
-
| Integer | Integer | Integer |
67
-
| Float | Float | Float |
68
-
69
-
The subtraction operator takes two numbers and subtracts them:
70
-
```
71
-
=^..^= 1 - 2
72
-
-1
73
-
```
74
-
75
-
#### Multiplication (`*`)
76
-
| Left Operand | Right Operand | Output |
77
-
|:------------:|:-------------:|:-------:|
78
-
| Integer | Integer | Integer |
79
-
| Float | Float | Float |
80
-
81
-
The multiplication operator takes two numbers and multiplies them together:
82
-
```
83
-
=^..^= 1 * 2
84
-
2
85
-
```
86
-
87
-
#### Division (`/`)
88
-
| Left Operand | Right Operand | Output |
89
-
|:------------:|:-------------:|:-------:|
90
-
| Integer | Integer | Integer |
91
-
| Float | Float | Float |
92
-
93
-
The division operator takes two numbers, divides them, and returns the quotient:
94
-
```
95
-
=^..^= 1 / 2
96
-
0
97
-
```
98
-
NOTE: The output of the division operator depends on the type of its operands. If the operands are integers, the division operator performs integer division, which truncates the decimal quotient towards zero in order to return an integer. If the operands are floating-point numbers, the division operator does not alter the decimal quotient:
99
-
```
100
-
=^..^= 1.0 / 2.0
101
-
0.5
102
-
```
103
-
104
-
#### Remainder (`%`)
105
-
| Left Operand | Right Operand | Output |
106
-
|:------------:|:-------------:|:-------:|
107
-
| Integer | Integer | Integer |
108
-
| Float | Float | Float |
109
-
110
-
The remainder operator takes two numbers, divides them, and returns the remainder:
111
-
```
112
-
=^..^= 1 % 2
113
-
1
114
-
115
-
=^..^= 4 % 2
116
-
0
117
-
```
118
-
119
-
#### Boolean AND (`and`)
120
-
| Left Operand | Right Operand | Output |
121
-
|:------------:|:-------------:|:-------:|
122
-
|`bool`|`bool`|`bool`|
123
-
124
-
The boolean AND operator takes two booleans and produces a boolean representing whether both operands are `true`:
125
-
| Left Operand | Right Operand | Output |
126
-
|:------------:|:-------------:|:-------:|
127
-
|`true`|`true`|`true`|
128
-
|`true`|`false`|`false`|
129
-
|`false`|`true`|`false`|
130
-
|`false`|`false`|`false`|
131
-
132
49
```
133
-
=^..^= true and true
134
-
true
135
-
```
136
-
137
-
#### Boolean OR (`or`)
138
-
| Left Operand | Right Operand | Output |
139
-
|:------------:|:-------------:|:-------:|
140
-
|`bool`|`bool`|`bool`|
141
-
142
-
The boolean OR operator takes two booleans and produces a boolean representing whether either or both operands are `true`:
143
-
| Left Operand | Right Operand | Output |
144
-
|:------------:|:-------------:|:-------:|
145
-
|`true`|`true`|`true`|
146
-
|`true`|`false`|`true`|
147
-
|`false`|`true`|`true`|
148
-
|`false`|`false`|`false`|
149
-
150
-
```
151
-
=^..^= true or false
152
-
true
153
-
```
154
-
155
-
#### Less Than (`<`)
156
-
| Left Operand | Right Operand | Output |
157
-
|:------------:|:-------------:|:-------:|
158
-
| Integer | Integer |`bool`|
159
-
| Float | Float |`bool`|
160
-
161
-
The less than operator takes two numbers and returns a boolean representing whether the first operand was less than the second:
162
-
```
163
-
=^..^= 1 < 2
164
-
true
165
-
166
-
=^..^= 1 < 1
50
+
$ jazzy expression.jzy
167
51
false
168
52
```
169
53
170
-
#### Less Than Or Equal To (`<=`)
171
-
| Left Operand | Right Operand | Output |
172
-
|:------------:|:-------------:|:-------:|
173
-
| Integer | Integer |`bool`|
174
-
| Float | Float |`bool`|
175
-
176
-
The less than or equal to operator takes two numbers and returns a boolean representing whether the first operand was less than or equal to the second:
177
-
```
178
-
=^..^= 1 <= 2
179
-
true
180
-
181
-
=^..^= 1 <= 1
182
-
true
54
+
### Variables
55
+
Variables can be declared as such:
183
56
```
184
-
185
-
#### Greater Than (`>`)
186
-
| Left Operand | Right Operand | Output |
187
-
|:------------:|:-------------:|:-------:|
188
-
| Integer | Integer |`bool`|
189
-
| Float | Float |`bool`|
190
-
191
-
The greater than operator takes two numbers and returns a boolean representing whether the first operand was greater than the second:
192
-
```
193
-
=^..^= 2 > 1
194
-
true
195
-
196
-
=^..^= 1 > 1
197
-
false
57
+
let x := 1;
198
58
```
199
59
200
-
#### Greater Than Or Equal To (`>=`)
201
-
| Left Operand | Right Operand | Output |
202
-
|:------------:|:-------------:|:-------:|
203
-
| Integer | Integer |`bool`|
204
-
| Float | Float |`bool`|
205
-
206
-
The greater than or equal to operator takes two numbers and returns a boolean representing whether the first operand was greater than or equal to the second:
60
+
The name of your variable is called an "identifier". The idiomatic style for jazzy variable identifiers is not snake case or camel case, like in a lot of common programming languages, but what many people call "kebab case":
207
61
```
208
-
=^..^= 2 >= 1
209
-
true
210
-
211
-
=^..^= 1 >= 1
212
-
true
62
+
let some-variable := 3.14;
213
63
```
214
64
215
-
#### Equal To (`==`)
216
-
| Left Operand | Right Operand | Output |
217
-
|:------------:|:-------------:|:-------:|
218
-
| A | A |`bool`|
65
+
An interesting consequence of this decision is that all of our binary operators (think +, -, etc) need to be surrounded by whitespace. Otherwise, we wouldn't know the difference between subtracting a variable `b` from a variable `a` and referencing a variable `a-b`!
219
66
220
-
The equal to operator takes two values **of the same type** and returns a boolean representing whether they have the same value:
221
-
```
222
-
=^..^= 1 == 1
223
-
true
67
+
Variables are immutable by default, meaning once you declare them, you cannot assign them a new value.
224
68
225
-
=^..^= 1 == 2
226
-
false
227
-
```
228
-
229
-
#### Not Equal To (`!=`)
230
-
| Left Operand | Right Operand | Output |
231
-
|:------------:|:-------------:|:-------:|
232
-
| A | A |`bool`|
69
+

233
70
234
-
The not equal to operator takes two values **of the same type** and returns a boolean representing whether they do not have the same value:
71
+
To declare a variable as mutable, allowing you to assign it a new value later, simply add a `mut` after the `let`:
235
72
```
236
-
=^..^= 1 != 1
237
-
false
238
-
239
-
=^..^= 1 != 2
240
-
true
73
+
let mut x := 1;
74
+
x := 2;
241
75
```
242
76
243
-
#### Unary Minus (`-`)
244
-
| Operand | Output |
245
-
|:-------:|:-------:|
246
-
| Integer | Integer |
247
-
| Float | Float |
248
-
249
-
The unary minus operator takes a single number and returns the negated value of that number:
77
+
There are lots of situations where the jazzy compiler can figure out what the type of your variable is by itself. However, if you run into a situation where it can't (or you just want to explicitly set it for readability), you can add a type hint:
250
78
```
251
-
=^..^= -1
252
-
-1
253
-
254
-
=^..^= --1
255
-
1
79
+
let x (i64) := 1;
256
80
```
257
81
258
-
#### Unary Boolean NOT (`not`)
259
-
| Operand | Output |
260
-
|:-------:|:-------:|
261
-
|`bool`|`bool`|
82
+
### Types
262
83
263
-
The unary boolean NOT operator takes a single boolean and returns the negated value of that boolean:
264
-
```
265
-
=^..^= not true
266
-
false
84
+
Speaking of types, jazzy currently has three categories of them: booleans, integers, and floating-point numbers.
267
85
268
-
=^..^= not not true
269
-
true
270
-
```
86
+
#### Booleans
87
+
| Type | Description |
88
+
|:----:|:-----------:|
89
+
| bool | Boolean |
271
90
272
-
### Literals
273
-
There are four kinds of literal values you can use in jazzy expressions:
91
+
There are two boolean literals: `true` and `false`.
274
92
275
93
#### Integers
94
+
| Type | Description |
95
+
|:----:|:------------------------:|
96
+
| i8 | Signed 8-bit integer |
97
+
| i16 | Signed 16-bit integer |
98
+
| i32 | Signed 32-bit integer |
99
+
| i64 | Signed 64-bit integer |
100
+
| i128 | Signed 128-bit integer |
101
+
| u8 | Unsigned 8-bit integer |
102
+
| u16 | Unsigned 16-bit integer |
103
+
| u32 | Unsigned 32-bit integer |
104
+
| u64 | Unsigned 64-bit integer |
105
+
| u128 | Unsigned 128-bit integer |
106
+
276
107
Integer literal values can be represented in three bases:
277
108
```c
278
109
// Base 10 (decimal)
@@ -292,7 +123,12 @@ Underscores can also be placed anywhere within the integer literal value (except
292
123
1
293
124
```
294
125
295
-
#### Floating-Point Numbers
126
+
#### Floating point numbers
127
+
| Type | Description |
128
+
|:----:|:------------:|
129
+
| f32 | 32-bit float |
130
+
| f64 | 64-bit float |
131
+
296
132
Floating-point literal values can be represented in two ways:
297
133
```c
298
134
// Traditional
@@ -311,9 +147,6 @@ Underscores can also be placed anywhere within the floating-point literal value
311
147
31400000000
312
148
```
313
149
314
-
#### Boolean
315
-
There are two boolean literal values, `true` and `false`.
316
-
317
150
### Comments
318
151
Comments can be used to explain your code, and are ignored by the compiler, so they have no effect on how your code runs. There are two types of comments:
0 commit comments