aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-04-10 20:48:41 +0000
committerBobby <[email protected]>2024-04-10 20:48:41 +0000
commit22c0cc7531edc6eba384d6f53f8f64f6a5616296 (patch)
treef9a0903ad3d7e162f918a685f27eed41774450db
parentca46690f9166681e4b32af90e28fb215c12f76c0 (diff)
downloadmana-22c0cc7531edc6eba384d6f53f8f64f6a5616296.tar.xz
mana-22c0cc7531edc6eba384d6f53f8f64f6a5616296.zip
Added `puts`HEADmain
-rw-r--r--README.md18
-rw-r--r--evaluator/builtins.go9
2 files changed, 20 insertions, 7 deletions
diff --git a/README.md b/README.md
index 4128a43..b90452d 100644
--- a/README.md
+++ b/README.md
@@ -73,6 +73,9 @@ let result = if (x < y) {
} else {
subtract(x, y)
}; // result = 15
+
+
+puts(result); // prints the value of result to the console
```
## Types
@@ -137,13 +140,14 @@ fn add(x, y) {
Mana has a number of built-in functions that are available to the programmer. These functions are built into the language and can be used without having to define them. The following is a list of built-in functions that are available in Mana:
-| Function | Description | Parameters | Example | Output |
-| -------- | --------------------------------------------- | --------------------- | ---------------------- | -------------- |
-| `len` | Returns the length of a string or an array | `string` | `len("Hello, World!")` | `13` |
-| `push` | Appends an element to the end of an array | `array`, `expression` | `push([1, 2, 3], 4)` | `[1, 2, 3, 4]` |
-| `first` | Returns the first element of an array | `array` | `first([1, 2, 3])` | `1` |
-| `last` | Returns the last element of an array | `array` | `last([1, 2, 3])` | `3` |
-| `rest` | Returns all but the first element of an array | `array` | `rest([1, 2, 3])` | `[2, 3]` |
+| Function | Description | Parameters | Example | Output |
+| -------- | --------------------------------------------- | --------------------- | ----------------------- | --------------- |
+| `len` | Returns the length of a string or an array | `string` | `len("Hello, World!")` | `13` |
+| `push` | Appends an element to the end of an array | `array`, `expression` | `push([1, 2, 3], 4)` | `[1, 2, 3, 4]` |
+| `first` | Returns the first element of an array | `array` | `first([1, 2, 3])` | `1` |
+| `last` | Returns the last element of an array | `array` | `last([1, 2, 3])` | `3` |
+| `rest` | Returns all but the first element of an array | `array` | `rest([1, 2, 3])` | `[2, 3]` |
+| `puts` | Prints a value to the console | `expression` | `puts("Hello, World!")` | `Hello, World!` |
## Strings
diff --git a/evaluator/builtins.go b/evaluator/builtins.go
index 1c7a312..a37a720 100644
--- a/evaluator/builtins.go
+++ b/evaluator/builtins.go
@@ -108,4 +108,13 @@ var builtins = map[string]*object.Builtin{
return &object.Array{Elements: newElements}
},
},
+ "puts": {
+ Fn: func(args ...object.Object) object.Object {
+ for _, arg := range args {
+ println(arg.Inspect())
+ }
+
+ return NULL
+ },
+ },
}