reorganized build-ins and implement a circular queue as an example

This commit is contained in:
cozis
2022-08-18 19:01:26 +02:00
parent b5b3a3e315
commit 782985e8b7
36 changed files with 486 additions and 259 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ A Noja program is a sequence of statements separated by semi-colons (with some e
* expressions
* function definitions
* if-else branches
* while loops
* while loops
* do-while loops
* compound statements
* `break` jumps
+7
View File
@@ -142,6 +142,13 @@ ls[0 + 2]; # OK!
ls[true or false]; # Runtime error!!
```
To append a value to a list, increasing it's size, you can just insert the new value at the first unused position (which will have index equal to the current list size). As we'll see in the built-in chapter, to get the size of a list one can use the `count` function. Which means appending to a list can be done like this:
```py
ls = [1, 2, 3];
ls[count(ls)] = 4;
# Now ls is [1, 2, 3, 4]
```
## Maps
Maps are defined as a list of key-value pairs:
```py
+44
View File
@@ -0,0 +1,44 @@
# Built-Ins
int
bool
float
String
print
import
unicode
type
unicode
chr
count
input
assert
error
string.cat
buffer.new
buffer.sliceUp
buffer.toString
math.PI
math.E
math.floor
math.ceil
math.cos
math.sin
math.tan
math.acos
math.asin
math.atan
math.atan2
math.exp
math.log
math.log10
math.pow
math.sqrt
files.READ
files.WRITE
files.APPEND
files.openFile
files.openDir
files.nextDirItem
files.read
files.write