Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions common-operation-script/ellipse-dev-language/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ To log an error and let it continue, call `(rethrow)` in the handler. `rethrow`
`with-cleanup` runs cleanup forms when its body ends, also when the body raises an error. It is the `finally` of other languages. See [with-cleanup](language-guide.md#with-cleanup).

`ignore-errors` returns `()` for any error. It hides mistakes, so use `handler-bind` with named conditions where you can.

`try` (elps v1.99.0, substrate v2.261.0 and later) evaluates its forms in order and returns the value of the first form that does not raise an error. The last form is not protected: its error propagates. Use it for a fallback, such as a default when a conversion fails. It catches every error except the ones that stop an evaluation: a step limit, a cancellation and an internal panic. See [try](function-reference.md#try). Keep the protected forms small, so that `try` does not hide a mistake. Inside a `defflow`, `try` may not contain an await.

```lisp
(list (try (to-int "12") 0)
(try (to-int "abc") 0)) ; evaluates to '(12 0)
```
28 changes: 23 additions & 5 deletions common-operation-script/ellipse-dev-language/function-reference.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
description: Every ELPS builtin, macro and library function in elps v1.98.0, from its docstring.
description: Every ELPS builtin, macro and library function in elps v1.100.0, from its docstring.
---

# Function Reference

<!-- Generated by scripts/elps-reference/generate.mjs from elps v1.98.0. Do not edit: change the docstring in luthersystems/elps, or the pin in wasm/elps/go.mod. -->
<!-- Generated by scripts/elps-reference/generate.mjs from elps v1.100.0. Do not edit: change the docstring in luthersystems/elps, or the pin in wasm/elps/go.mod. -->

This page lists every function, macro, special operator and variable of ELPS v1.98.0, the release the examples on this site run. It is generated from the docstrings in [luthersystems/elps](https://github.com/luthersystems/elps/tree/v1.98.0), the same text `elps doc <name>` prints. For examples and guidance, see the [Standard Library](standard-library.md) and the [Language Guide](language-guide.md).
This page lists every function, macro, special operator and variable of ELPS v1.100.0, the release the examples on this site run. It is generated from the docstrings in [luthersystems/elps](https://github.com/luthersystems/elps/tree/v1.100.0), the same text `elps doc <name>` prints. For examples and guidance, see the [Standard Library](standard-library.md) and the [Language Guide](language-guide.md).

Functions of the `lisp` package need no prefix. Call a function of another package with its package name, such as `string:join`.

Expand Down Expand Up @@ -54,7 +54,7 @@ Paths are given as positional ELPS values — one argument per path step, no str
list array slice '(range 1 3), '(range 1)
```

? reads without copying. ?set, ?del and ?nil copy the document's maps, lists and vectors; their "!" forms mutate in place. In-place edits of list elements are refused; use a copying form or a vector instead. An out-of-range integer index leaves the document unchanged on a write (and returns nil on a read). Negative indexes count from the end.
? reads without copying. ?? reads as ? does, but returns nil when a step meets nil. ?set, ?del and ?nil copy the document's maps, lists and vectors; their "!" forms mutate in place. In-place edits of list elements are refused; use a copying form or a vector instead. An out-of-range integer index leaves the document unchanged on a write (and returns nil on a read). Negative indexes count from the end.

Tagged values and quote wrappers are rebuilt recursively by copying writes and traversed by cycle checks, but cannot be indexed into. Other value types are opaque leaves, including symbols, bytes, functions and natives. Reads may return them and writes may store them. A further path step into a leaf raises an error naming its type and location. Copies share opaque leaves by reference; mutation of their storage outside elpspath is visible through both documents. Writes need containers that are acyclic and arrays with exactly one dimension, and check this throughout the document, including off-path containers and the contents of tagged values and quote wrappers, because a write may copy or rebuild any of them. New values pass the same check. A read (?) with a path checks only what that path steps into: it never walks beyond its path or into the value it returns, so a fault elsewhere cannot change its answer, and its cost follows the path rather than the document. A read with no path checks the whole document, as writes do. Function bodies and captured environments remain opaque and shared; they are not walked.

Expand Down Expand Up @@ -84,6 +84,18 @@ Values of any leaf type may be read. Descending into a leaf raises an error nami

Accepts at most 1024 nested iterator steps; deeper traversal raises a depth error.

### `elpspath:??`

*function*: `(elpspath:?? val &rest steps)`

Get value at a path, returning nil when a step meets nil.

The same as ?, except that a step into nil returns nil instead of raising an error. So a missing key, an out-of-range index or a stored () anywhere on the path gives nil. A step into a leaf of the wrong type, such as a number or a string, still raises an error, because that is a fault in the data or the path.

(?? obj "foo" 0 "bar") =&gt; nil when obj has no "foo" (? obj "foo" 0 "bar") =&gt; error: first argument is nil (?? obj "foo" 0) =&gt; error when obj's "foo" is a number (?? obj) =&gt; obj itself (no path steps)

After a '\* step, ? already gives nil for each element whose path fails, so ?? reads the same as ? from there.

### `elpspath:?del`

*function*: `(elpspath:?del val &rest steps)`
Expand Down Expand Up @@ -1179,7 +1191,7 @@ Returns true if expr is a sorted-map, false otherwise.

*function*: `(stable-sort less-predicate list &rest key-fun)`

Sorts list using the binary less-predicate and returns the sorted list. The sort is stable. An optional key-fun extracts comparison keys from elements. Both callbacks must be regular functions; elements and keys are passed as data without evaluation. A mutable list is sorted in place, so sorting a slice view also sorts that region of its source; sort (concat 'list x) when x is a view you do not own. A quoted program literal is never modified: sorting a non-empty literal (or a view sharing its storage) raises the catchable modify-literal-error condition -- sort (copy lit) instead.
Sorts list using the binary less-predicate and returns the sorted list. The sort is stable. An optional key-fun extracts comparison keys from elements. key-fun runs once per element, in list order, before any comparison, and does not run for a list of fewer than two elements. Both callbacks must be regular functions; elements and keys are passed as data without evaluation. A mutable list is sorted in place, so sorting a slice view also sorts that region of its source; sort (concat 'list x) when x is a view you do not own. A quoted program literal is never modified: sorting a non-empty literal (or a view sharing its storage) raises the catchable modify-literal-error condition -- sort (copy lit) instead.

### `string<`

Expand Down Expand Up @@ -1301,6 +1313,12 @@ Evaluates expr, prints the result to stderr prefixed by message (default "TRACE"

Returns true if expr is truthy (not nil and not false), false otherwise. Useful as an explicit boolean conversion.

### `try`

*operator*: `(try &rest exprs)`

Evaluates exprs in order and returns the value of the first one that does not signal an error. When an expr signals, its error is dropped and the next expr is evaluated. The last expr is not guarded: its value is returned and its error propagates, so a program can give a default value or raise its own error last. (try x) is x, and (try) returns (). A result of () or false is a success, unlike (or (ignore-errors x) y). The conditions that stop an evaluation are never caught and always propagate: internal-panic (a Go panic recovered from host code), step-limit-exceeded, step-budget-exceeded and context-cancelled. A fallback must not turn a stop into a value. Side effects of an expr that signals are not undone. Like ignore-errors, blocks tail-call optimization across this form.

### `type`

*function*: `(type value)`
Expand Down
2 changes: 1 addition & 1 deletion common-operation-script/substrate/defflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ A run is in one of three states: `waiting`, `done` or `failed`.
([Destructuring in let](../ellipse-dev-language/let-destructuring.md)),
`match` ([Pattern Matching](../ellipse-dev-language/pattern-matching.md)),
`handler-bind`, `ignore-errors`, `flet` and `labels` work across awaits. An
await inside `dotimes`, `with-cleanup` or a `lambda` (other than an inline
await inside `dotimes`, `with-cleanup`, `try` (substrate v2.261.0 and later) or a `lambda` (other than an inline
`:on-error` handler) is a compile error. Use
`while` for a loop that awaits.

Expand Down
Loading