Skip to content

Commit ce7e2a2

Browse files
committed
chore: update tutorial with links to detailled docs for builtins
1 parent cd14efd commit ce7e2a2

File tree

1 file changed

+7
-56
lines changed

1 file changed

+7
-56
lines changed

content/docs/tutorials/language.md

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -318,62 +318,13 @@ Closures can also be compared, the same way you would want to compare structs in
318318
## VM builtins
319319

320320
Some primitives are directly implemented in the VM, and are often referred to as *operators*. Those are the following:
321-
- Arithmetic operators: `+`, `-`, `*`, `/`, `mod`
322-
- Comparison operators: `=`, `!=`, `<`, `<=`, `>`, `>=`
323-
- Condition operators: `and`, `or`, `not`
324-
- List operators: `len`, `empty?`, `tail`, `head`, `nil?`, `@`, `@@`, `append`, `append!`, `concat`, `concat!`, `pop`, `pop!`, `@=`, `@@=`
325-
- Conversion operators: `toNumber`, `toString`
326-
- Test operator: `assert`
327-
- Type operators: `type`, `hasField`
328-
329-
Here we'll explain the non-obvious ones:
330-
331-
### List operators
332-
333-
**`(tail a-list)`** will return the last elements of a list as a new list:
334-
- `[] -> []`,
335-
- `[1] -> []`,
336-
- `[1 2 3] -> [2 3]`.
337-
338-
**`(head a-list)`** will return the first element of a list, or `nil` if the list is empty:
339-
- `[] -> nil`,
340-
- `[1] -> 1`,
341-
- `[1 2 3] -> 1`.
342-
343-
**`(empty? a-list)`** returns true if the list (or string) is empty (or the value is `nil`), false otherwise.
344-
345-
**`(nil? a-list)`** will always return false as a list isn't nil (which is the void value, returned by `head`).
346-
347-
**`(@ a-list index)`** gets the element at `index` inside the list. Negative indices are supported, with `-1` being the last element.
348-
349-
**`(@@ a-2d-list i j)`** is equivalent to `a-2d-list[i][j]` in Python: it gets the element at position `j` in the sublist `(@ a-2d-list i)`. It's a shortcut for `(@ (@ a-2d-list i) j)`.
350-
351-
**`(append a-list 5)`** returns a new list with 5 added at the end,
352-
**`(append! a-list 5)`** will add 5 in-place to a-list, without returning a new list.
353-
354-
**`(concat a-list [5 6])`** returns a new list with 5 and 6 added at the end,
355-
**`(concat! a-list [5 6])`** will add 5 and 6 in-place to a-list, without returning a new list.
356-
357-
**`(pop a-list index)`** returns a new list without the element at `index` (supports negative indices, -1 being the end),
358-
**`(pop! a-list index)`** will remove the element at `index` in-place, without returning a new list.
359-
360-
**`(@= a-list index value)`** updates `a-list` in-place by replacing the element at `index` by `value` (supports negative indices, -1 being the end).
361-
362-
Akin to `@=`, `@@=` can update lists in-place, but this version works on 2D list (list of lists, or list of strings). Eg **`(@@= a-2d-list i j value)`** will replace the element at `a-2d-list[i][j]` by `value`. If the sublist is a string, `value` needs to be a single char, eg `(@@= a-list-of-strings i j "b")`.
363-
364-
---
365-
366-
### Test operator
367-
368-
**`(assert condition message)`** will interrupt the execution if `condition` is false, and display the given message.
369-
370-
---
371-
372-
### Type operators
373-
374-
**`(type value)`** returns the type of the given value (or variable) as a string: `"List"`, `"Number"`, `"String"`, `"Function"`, `"CProc"`, `"Closure"`, `"UserType"`, `"Nil"`, `"Bool"`, `"Undefined"`.
375-
376-
**`(hasField closure "a")`** returns true if the given closure has a field named `a`, false otherwise.
321+
- Arithmetic operators: `+`, `-`, `*`, `/`, `mod`, see [std.Math]({{< ref "/docs/std/Math.md" >}})
322+
- Comparison operators: `=`, `!=`, `<`, `<=`, `>`, `>=`, see [std.Builtins]({{< ref "/docs/std/Builtins.md" >}})
323+
- Condition operators: `and`, `or`, `not`, see [std.Builtins]({{< ref "/docs/std/Builtins.md" >}})
324+
- List operators: `len`, `empty?`, `tail`, `head`, `nil?`, `@`, `@@`, `append`, `append!`, `concat`, `concat!`, `pop`, `pop!`, `@=`, `@@=`, see [std.List]({{< ref "/docs/std/List.md" >}}) and [std.String]({{< ref "/docs/std/String.md" >}})
325+
- Conversion operators: `toNumber`, `toString`, see [std.Builtins]({{< ref "/docs/std/Builtins.md" >}})
326+
- Test operator: `assert`, see [std.Builtins]({{< ref "/docs/std/Builtins.md" >}})
327+
- Type operators: `type`, `hasField`, see [std.Builtins]({{< ref "/docs/std/Builtins.md" >}})
377328

378329
## Importing code
379330

0 commit comments

Comments
 (0)