aboutsummaryrefslogtreecommitdiffstats
path: root/docs/reference
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2022-01-27 13:28:07 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commit3a8d30dbd116eb6a6239a6c0411ad26de9614527 (patch)
treed93abe76ac71e36e3a80b7d674db6ae38d68c66f /docs/reference
parentdocs: update extension guide (PureOp) (diff)
downloadalive-3a8d30dbd116eb6a6239a6c0411ad26de9614527.tar.gz
alive-3a8d30dbd116eb6a6239a6c0411ad26de9614527.zip
docs: show output samples on dark background
Diffstat (limited to 'docs/reference')
-rw-r--r--docs/reference/03-1_symbol-resolution.md11
-rw-r--r--docs/reference/03-2_conditionals.md8
-rw-r--r--docs/reference/03-3_functions.md13
-rw-r--r--docs/reference/03-4_dynamic-symbols.md10
-rw-r--r--docs/reference/03-6_modules-and-loading.md28
-rw-r--r--docs/reference/04-1_result-kinds.md16
-rw-r--r--docs/reference/04-2_pure-operators.md33
-rw-r--r--docs/reference/05-1_arrays.md5
-rw-r--r--docs/reference/05-2_structs.md5
9 files changed, 79 insertions, 50 deletions
diff --git a/docs/reference/03-1_symbol-resolution.md b/docs/reference/03-1_symbol-resolution.md
index 87568ef..2054155 100644
--- a/docs/reference/03-1_symbol-resolution.md
+++ b/docs/reference/03-1_symbol-resolution.md
@@ -69,12 +69,11 @@ scope and evaluate some expressions in it:
(def a 3)
(trace (.. "second: " a " " b))
(trace (.. "third: " a " " b))
-
-This example prints the following:
-
- trace (.. "first: " a " " b): <Value str: first: 1 2>
- trace (.. "second: " a " " b): <Value str: second: 3 2>
- trace (.. "third: " a " " b): <Value str: third: 1 2>
+```output
+trace (.. "first: " a " " b): <Value str: first: 1 2>
+trace (.. "second: " a " " b): <Value str: second: 3 2>
+trace (.. "third: " a " " b): <Value str: third: 1 2>
+```
As you can see, within a nested scope it is possible to overwrite a definition
from the parent scope. Symbols that are not explicitly redefined in a nested
diff --git a/docs/reference/03-2_conditionals.md b/docs/reference/03-2_conditionals.md
index 59cac7f..80b16d1 100644
--- a/docs/reference/03-2_conditionals.md
+++ b/docs/reference/03-2_conditionals.md
@@ -12,6 +12,9 @@ it is not needed.
#(prints nothing)
(if false
(print "Another message"))
+```output
+(empty)
+```
If multiple expressions (with side effects) need to be switched, [when][] can
be used instead: it evaluates all arguments as a block, only if the condition
@@ -23,6 +26,11 @@ is truthy:
(print "the things are enabled.")
(print "they should happen soon.")
(print "thank you for enabling them."))
+```output
+the things are enabled.
+they should happen soon.
+thank you for enabling them.
+```
This is equivalent to using a [do][] block inside the [if][] expression:
diff --git a/docs/reference/03-3_functions.md b/docs/reference/03-3_functions.md
index 917b8d4..6715eb7 100644
--- a/docs/reference/03-3_functions.md
+++ b/docs/reference/03-3_functions.md
@@ -11,6 +11,10 @@ code, amongst other things:
(add-and-trace 1 2)
(add-and-trace 3 4)
+```output
+trace (+ a b): <num= 3>
+trace (+ a b): <num= 7>
+```
Here a *function* `add-and-trace` is defined. When defining a function, first
the names of the parameters have to be given. The function defined here takes
@@ -38,11 +42,10 @@ example is equivalent to the following:
(let a 3
b 4)
(trace (+ a b)))
-
-and the output of both is:
-
- trace (+ a b): <num= 3>
- trace (+ a b): <num= 7>
+```output
+trace (+ a b): <num= 3>
+trace (+ a b): <num= 7>
+```
In `alv`, functions are first-class values and can be passed around just like
numbers, strings, etc. However it is very common to define a function with a
diff --git a/docs/reference/03-4_dynamic-symbols.md b/docs/reference/03-4_dynamic-symbols.md
index d642984..eb12a41 100644
--- a/docs/reference/03-4_dynamic-symbols.md
+++ b/docs/reference/03-4_dynamic-symbols.md
@@ -12,7 +12,10 @@ message"` is found:
(do
(def hello "overwritten message")
- (print-hello)) #(-> prints "original message")
+ (print-hello))
+```output
+original message
+```
On the other hand, there are also *dynamic symbols*. Dynamic symbols are
symbols whose name starts and ends with an asterisk, like `*clock*` and
@@ -25,6 +28,9 @@ the *function call site*:
(do
(def *hello* "overwritten message")
- (print-hello)) #(-> prints "overwritten message")
+ (print-hello))
+```output
+overwritten message
+```
This allows symbols to be *dynamically overwritten*.
diff --git a/docs/reference/03-6_modules-and-loading.md b/docs/reference/03-6_modules-and-loading.md
index 4735d60..cb53cc1 100644
--- a/docs/reference/03-6_modules-and-loading.md
+++ b/docs/reference/03-6_modules-and-loading.md
@@ -36,10 +36,11 @@ inside it:
(import* string)
(print (str "my-module's value is " (require "my-module")))
-
- #(output:
- loading my-module...
- my-module's value is 4)
+
+```output
+loading my-module...
+my-module's value is 4
+```
Often it is useful to export multiple values from a file, for example when
writing a library containing multiple functions. There are two operators to
@@ -65,10 +66,11 @@ rather the newly created scope. It can therefore be combined with [def][],
(print (str "my-module/a-value is " my-module/a-value))
(my-module/print-doubled 4)
-
- #(output:
- my-module/a-value is 7
- 4 doubled is 8)
+
+```output
+my-module/a-value is 7
+4 doubled is 8
+```
[export*][] on the other hand operates on the containing scope rather than
creating a new one. When Used without any arguments, it returns the containing
@@ -92,9 +94,9 @@ mentioned are exported:
(print (str "a is " a))
(print (str "b is " b))
(print (str "c is " c))
-
- #(output:
- a is 1
- b is 2
- reference error: undefined symbol 'c')
+```output
+a is 1
+b is 2
+reference error: undefined symbol 'c'
+```
diff --git a/docs/reference/04-1_result-kinds.md b/docs/reference/04-1_result-kinds.md
index 9f1f935..664c613 100644
--- a/docs/reference/04-1_result-kinds.md
+++ b/docs/reference/04-1_result-kinds.md
@@ -11,7 +11,9 @@ Constants are denoted using the equals symbol (`=`) in documentation and
traces, e.g:
(trace 4)
- #(trace 4: <num= 4>)
+```output
+trace 4: <num= 4>
+```
where `<num= 4>` denotes a constant of the type `num` with a value of `4`.
@@ -30,8 +32,10 @@ e.g.:
(import* time)
(trace (lfo 2))
- #(trace (lfo 2): <num~ 0.0>
- trace (lfo 2): <num~ 0.0016211131633209>)
+```output
+trace (lfo 2): <num~ 0.0>
+trace (lfo 2): <num~ 0.0016211131633209>
+```
where `<num~ 1.0>` denotes a signal-stream of the type `num` with a current
value of `1.0`.
@@ -54,8 +58,10 @@ traces, e.g.:
(import* time)
(trace (every 2))
- #(trace (lfo 2): <bang! true>
- trace (lfo 2): <bang! true>)
+```output
+trace (lfo 2): <bang! true>
+trace (lfo 2): <bang! true>
+```
where `<bang! true>` denotes an event-stream of the type `bang` that fired with a
value of `true`.
diff --git a/docs/reference/04-2_pure-operators.md b/docs/reference/04-2_pure-operators.md
index d2dc4c5..4d07920 100644
--- a/docs/reference/04-2_pure-operators.md
+++ b/docs/reference/04-2_pure-operators.md
@@ -24,23 +24,22 @@ As an example, let's consider [math/+][]:
(trace (+ 1 2 (lfo 2)))
(trace (+ 1 2 (every 1 3)))
(trace (+ 1 (lfo 2) (every 1 3)))
-
-<div />
-
- (+ num= num= num=) -> num=
- trace (+ 1 2 3): <num= 6>
-
- (+ num= num= num~) -> num~
- trace (+ 1 2 (lfo 2)): <num~ 4.0>
- trace (+ 1 2 (lfo 2)): <num~ 3.9882585630406>
-
- (+ num= num= num!) -> num!
- trace (+ 1 2 (every 2 3)): <num! 6>
- trace (+ 1 2 (every 2 3)): <num! 6>
-
- (+ num= num~ num!) -> num!
- trace (+ 1 (lfo 2) (every 2 3)): <num! 4.9950529446967>
- trace (+ 1 (lfo 2) (every 2 3)): <num! 4.9950529446967>
+```output
+(+ num= num= num=) -> num=
+trace (+ 1 2 3): <num= 6>
+
+(+ num= num= num~) -> num~
+trace (+ 1 2 (lfo 2)): <num~ 4.0>
+trace (+ 1 2 (lfo 2)): <num~ 3.9882585630406>
+
+(+ num= num= num!) -> num!
+trace (+ 1 2 (every 2 3)): <num! 6>
+trace (+ 1 2 (every 2 3)): <num! 6>
+
+(+ num= num~ num!) -> num!
+trace (+ 1 (lfo 2) (every 2 3)): <num! 4.9950529446967>
+trace (+ 1 (lfo 2) (every 2 3)): <num! 4.9950529446967>
+```
Sometimes a *Pure Op* will require additional constraints on the *kinds* of
some of its inputs. These will be specified in the documentation.
diff --git a/docs/reference/05-1_arrays.md b/docs/reference/05-1_arrays.md
index 7522da7..fdd26ff 100644
--- a/docs/reference/05-1_arrays.md
+++ b/docs/reference/05-1_arrays.md
@@ -3,7 +3,10 @@ type. Arrays values can be created using the [`(array …)`][:array:] builtin,
which uses [Pure Op](04-2_pure-operators.html) semantics to construct an array
from its parameters, all of which have to be of the same type.
- (trace (array 1 2 3)) #(<num[3]= [1 2 3]>)
+ (trace (array 1 2 3))
+```output
+<num[3]= [1 2 3]>
+```
The type notation `num[3]` designates an array of three numbers, whereas the
value notation `[1 2 3]` is used to show the array contents.
diff --git a/docs/reference/05-2_structs.md b/docs/reference/05-2_structs.md
index 11ec7ed..d3074c9 100644
--- a/docs/reference/05-2_structs.md
+++ b/docs/reference/05-2_structs.md
@@ -6,7 +6,10 @@ Struct values can be created using the the [`(struct …)`][:struct:] builtin,
which uses [Pure Op](04-2_pure-operators.html) semantics to construct a struct
from its parameters. The keys have to be constants.
- (trace (struct "a" 1 "b" 'hello world')) <{a: num b: str}= {a: 1 b: "hello world"}>
+ (trace (struct "a" 1 "b" 'hello world'))
+```output
+<{a: num b: str}= {a: 1 b: "hello world"}>
+```
The type notation `{a: num b: str}` designates a struct type with the key `a`
mapping to a value of type `num` and the key `b` mapping to a value of type