Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BUILTINS.MD #492

Merged
merged 30 commits into from
May 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
10a81bb
test builtins first version
Sipher May 24, 2024
386fe93
vmao v como ficou
Sipher May 24, 2024
aa0dbf7
woops
Sipher May 24, 2024
935e4bc
why is that even like that grr
Sipher May 24, 2024
0921577
and another try
Sipher May 24, 2024
93843b5
aaaaa
Sipher May 24, 2024
38e3eba
Add 0.0.1 builtins.md
Sipher May 24, 2024
6bed0cc
edit footer of readme with built ins
Sipher May 24, 2024
d9a8982
edit readme
Sipher May 24, 2024
f6fd67e
add builtins redirect
Sipher May 24, 2024
05fac86
Update builtins.md
Sipher May 24, 2024
fae1e40
Rename builtins.md to BUILTINS.md
Sipher May 24, 2024
9db60e4
test builtins first version
Sipher May 24, 2024
440b405
vmao v como ficou
Sipher May 24, 2024
33c3b97
woops
Sipher May 24, 2024
415a2a1
why is that even like that grr
Sipher May 24, 2024
226d32a
and another try
Sipher May 24, 2024
0427873
aaaaa
Sipher May 24, 2024
24cd3be
Add 0.0.1 builtins.md
Sipher May 24, 2024
096e147
edit
Sipher May 24, 2024
8b3578a
edit readme
Sipher May 24, 2024
61bb11f
add builtins redirect
Sipher May 24, 2024
097f409
Update builtins.md
Sipher May 24, 2024
16598b2
Rename builtins.md to BUILTINS.md
Sipher May 24, 2024
90102d0
Merge branch 'main' of https://github.com/Sipher/Bend
Sipher May 24, 2024
9448daf
remove .com
Sipher May 24, 2024
b84e51c
Merge branch 'HigherOrderCO:main' into main
Sipher May 24, 2024
b83f23d
changed BUILTINS.ms
Sipher May 27, 2024
b0201ec
Merge branch 'main' of https://github.com/Sipher/Bend
Sipher May 27, 2024
28eb877
Merge branch 'HigherOrderCO:main' into main
Sipher May 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
vmao v como ficou
Sipher committed May 24, 2024
commit 386fe9379fc8a8f9b3c04f761826f716caba0d60
81 changes: 81 additions & 0 deletions builtins.md
Original file line number Diff line number Diff line change
@@ -75,3 +75,84 @@ Calls an IO function with an argument.
### print
Prints text to the console.
```print text = (IO/Call IO/MAGIC "PUT_TEXT" text @x (IO/Done IO/MAGIC x))```

# Usage Examples

## Map

### Map/get
The `get` function retrieves the value associated with a key from the map. If the key is found, it returns the value and the updated map. If not, it returns a placeholder value and the map.

```Map/get map key =
match map {
Map/Leaf: (*, map)
Map/Node:
switch _ = (== 0 key) {
0: switch _ = (% key 2) {
0:
let (got, rest) = (Map/get map.left (/ key 2))
(got, (Map/Node map.value rest map.right))
_:
let (got, rest) = (Map/get map.right (/ key 2))
(got, (Map/Node map.value map.left rest))
}
_: (map.value, map)
}
}```


### Map/set
The `set` function replaces the `current value` found in the same `key value` in
the tree, if it has no value, creates a new branch and sets the value in the
`node`.

```Map/set map key value =
match map {
Map/Node:
switch _ = (== 0 key) {
0: switch _ = (% key 2) {
0: (Map/Node map.value (Map/set map.left (/ key 2) value) map.right)
_: (Map/Node map.value map.left (Map/set map.right (/ key 2) value))
}
_: (Map/Node value map.left map.right)
}
Map/Leaf:
switch _ = (== 0 key) {
0: switch _ = (% key 2) {
0: (Map/Node * (Map/set Map/Leaf (/ key 2) value) Map/Leaf)
_: (Map/Node * Map/Leaf (Map/set Map/Leaf (/ key 2) value))
}
_: (Map/Node value Map/Leaf Map/Leaf)
}
}```

### Map/empty
Creates an empty tree, containing only a leaf without any value
Map/empty = Map/Leaf


## IO

#IO Impl

STRING_NIL_TAG = 0
STRING_CONS_TAG = 1

IO_DONE_TAG = 0
IO_PUT_TEXT_TAG = 1
IO_GET_TEXT_TAG = 2
IO_WRITE_FILE_TAG = 3
IO_READ_FILE_TAG = 4
IO_GET_TIME_TAG = 5
IO_SLEEP_TAG = 6
IO_DRAW_IMAGE_TAG = 7

data IO
= (Done term)
| (PutText text cont)
| (GetText cont)
| (WriteFile file data cont)
| (ReadFile file cont)
| (GetTime cont)
| (Sleep time cont)
| (DrawImage tree cont)