-
Notifications
You must be signed in to change notification settings - Fork 459
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
+172
−1
Merged
Add BUILTINS.MD #492
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
10a81bb
test builtins first version
Sipher 386fe93
vmao v como ficou
Sipher aa0dbf7
woops
Sipher 935e4bc
why is that even like that grr
Sipher 0921577
and another try
Sipher 93843b5
aaaaa
Sipher 38e3eba
Add 0.0.1 builtins.md
Sipher 6bed0cc
edit footer of readme with built ins
Sipher d9a8982
edit readme
Sipher f6fd67e
add builtins redirect
Sipher 05fac86
Update builtins.md
Sipher fae1e40
Rename builtins.md to BUILTINS.md
Sipher 9db60e4
test builtins first version
Sipher 440b405
vmao v como ficou
Sipher 33c3b97
woops
Sipher 415a2a1
why is that even like that grr
Sipher 226d32a
and another try
Sipher 0427873
aaaaa
Sipher 24cd3be
Add 0.0.1 builtins.md
Sipher 096e147
edit
Sipher 8b3578a
edit readme
Sipher 61bb11f
add builtins redirect
Sipher 097f409
Update builtins.md
Sipher 16598b2
Rename builtins.md to BUILTINS.md
Sipher 90102d0
Merge branch 'main' of https://github.com/Sipher/Bend
Sipher 9448daf
remove .com
Sipher b84e51c
Merge branch 'HigherOrderCO:main' into main
Sipher b83f23d
changed BUILTINS.ms
Sipher b0201ec
Merge branch 'main' of https://github.com/Sipher/Bend
Sipher 28eb877
Merge branch 'HigherOrderCO:main' into main
Sipher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
>this is a WIP based on [Builtins.bend](https://github.com/HigherOrderCO/Bend/blob/main/src/fun/builtins.bend). | ||
|
||
# Built-in Types and Functions | ||
**Bend** built-in types and functions, this document serves as a reference guide. Read more at [FEATURES.md](https://github.com/HigherOrderCO/Bend/blob/main/FEATURES.md). | ||
|
||
## String | ||
```python | ||
data String = (Cons head ~tail) | (Nil) | ||
``` | ||
|
||
|
||
- **Nil**: Represents an empty string. | ||
- **Cons head ~tail**: Represents a string with a `head` character and a `tail` string. | ||
|
||
### Syntax | ||
A String literal is surrounded with `"`. Accepts the same values as characters literals. | ||
``` | ||
"Hello, World!" | ||
``` | ||
|
||
|
||
|
||
|
||
## List | ||
```python | ||
data List = (Cons head ~tail) | (Nil) | ||
``` | ||
|
||
- **Nil**: Represents an empty list. | ||
- **Cons head ~tail**: Represents a list with a `head` element and a `tail` list. | ||
|
||
### Syntax | ||
A List of values can be written using `[ ]`, it can have multiple values inside, using `,` you can divide its value in a list of multiple elements. | ||
|
||
``` | ||
["This", "List", "Has", "Multiple", "Values"] | ||
``` | ||
|
||
|
||
|
||
|
||
## Nat | ||
```python | ||
data Nat = (Succ ~pred) | (Zero) | ||
``` | ||
- **Succ ~pred**: Represents a natural number successor. | ||
- **Zero**: Represents the natural number zero. | ||
|
||
### Syntax | ||
A Natural Number can be written with literals with a `#` before the literal number. | ||
|
||
``` | ||
#1337 | ||
``` | ||
|
||
|
||
|
||
## Result | ||
```python | ||
data Result = (Ok val) | (Err val) | ||
``` | ||
|
||
- **Ok val**: Represents a successful result with value `val`. | ||
- **Err val**: Represents an error with value `val`. | ||
|
||
## Map | ||
```python | ||
data Map = (Node value ~left ~right) | (Leaf) | ||
``` | ||
|
||
- **Node value ~left ~right**: Represents a map node with a `value` and `left` and `right` subtrees. | ||
- **Leaf**: Represents an empty map. | ||
|
||
#### Syntax | ||
**Bend** has a built-in binary tree map data structure where the key is a `u24`, meaning you can use numbers, characters, and symbols as keys. | ||
```python | ||
{ 0: 4, `hi`: "bye", 'c': 2 + 3 } | ||
``` | ||
|
||
|
||
### Map/empty | ||
Initializes an empty map. | ||
```python | ||
Map/empty = Map/Leaf | ||
``` | ||
|
||
### Map/get | ||
Retrieves a `value` from the `map` based on the `key`. | ||
```rust | ||
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) | ||
} | ||
} | ||
``` | ||
|
||
|
||
#### Syntax | ||
Considering the following tree | ||
```python | ||
{ 0: "hello", 1: "bye", 2: "maybe", 3: "yes"} | ||
``` | ||
The `get` function can be written as | ||
``` | ||
return x[0] # Gets the value of the key 0 | ||
``` | ||
And the value resultant from the get function would be: | ||
``` | ||
"hello" | ||
``` | ||
|
||
### Map/set | ||
Sets a `value` in the `map` at the specified `key`. | ||
```rust | ||
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) | ||
} | ||
} | ||
``` | ||
#### Syntax | ||
Considering the following tree | ||
```python | ||
{ 0: "hello", 1: "bye", 2: "maybe", 3: "yes"} | ||
``` | ||
The `set` function can be written as | ||
``` | ||
x[0] = "swapped" # Assigns the key 0 to the value "swapped" | ||
``` | ||
And the value resultant from the get function would be: | ||
``` | ||
{ 0: "swapped", 1: "bye", 2: "maybe", 3: "yes"} | ||
``` | ||
If there's no matching `key` in the tree, it would add a new branch to that tree with the value `set` | ||
|
||
``` | ||
x[4] = "added" # Assigns the key 4 to the value "added" | ||
``` | ||
The new tree | ||
``` | ||
{ 0: "swapped", 1: "bye", 2: "maybe", 3: "yes", 4: "added"} | ||
``` | ||
|
||
## IO | ||
IO Functions are in the **next milestone**! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mention that we have syntax for these types, maybe explain it here or maybe point to the syntax reference.