Macros¶
def¶
Defines an alias for a value.
This value may be data, the result of an expression, or the return value of a shard.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
defshards¶
Defines new shards that can be grouped together and inserted into an existing wire program.
Note
What's a shard
A defshards
shard looks structurally similar to a function (see defn), but unlike a defn
, it can contain multiple shards in its body without needing to use ->
.
During the execution phase, defshards
is replaced by its inner shards wherever it's invoked.
1 2 3 |
|
Just like a function, a defshards
shard can be invoked by name and can process input parameters.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
[info] [2022-05-13 15:31:09.231] [T-4796] [logging.cpp::98] [mywire] My name is
[info] [2022-05-13 15:31:09.232] [T-4796] [logging.cpp::98] [mywire] Shards
(defshards)
can be used in place of a (defn)
(function declaration) plus (->)
(shard-container).
See the last two code examples in (defn)
for a comparison of these use cases.
defwire¶
Defines a new non-looped wire.
1 2 3 4 |
|
Note
What's a wire
?
(defwire <wire-name>)
is actually a shorthand for the more verbose non-looped wire definition: (def <wire-name> (Wire "wire-name"))
.
1 2 3 4 5 |
|
To run a wire you must first schedule it on a mesh. When you run this mesh, all the wires scheduled on it are executed (in the order of scheduling).
A mesh will execute a non-looped wire only once (even though the mesh itself may continue running).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
[info] [2022-03-07 20:45:35.681] [T-9044] [logging.cpp::94] [wire-hello] Hello World!
[info] [2022-03-07 20:45:35.678] [T-9044] [logging.cpp::94] [wire-bye] Goodbye World
defwire
can also parse and save the wire's input into a variable.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
[trace] [2022-05-12 21:25:49.714] [T-17336] [runtime.cpp::1998] wire mainwire starting
[info] [2022-05-12 21:25:49.715] [T-17336] [logging.cpp::53] [mywire] wire input: shards
[debug] [2022-05-12 21:25:49.716] [T-17336] [runtime.cpp::2741] Running cleanup on wire: mainwire users count: 0
defn¶
Defines a new function.
1 2 3 |
|
The function definition consists of the function name followed by its input parameters (fn-params
), in []
.
If there are no input parameters, the []
remains empty. Multiple input parameters may be passed as a sequence.
The processing statements (value/expression/shards) following the []
are the function's body and its evaluation is the function's return value.
A function can be invoked by calling it by name and passing its required parameters.
Function with no input parameters:
1 2 3 4 5 6 7 8 9 10 11 |
|
[info] [2022-05-13 14:04:22.268] [T-1204] [logging.cpp::98] [mywire] I got no parameters
Function with one input parameter:
1 2 3 4 5 6 7 8 9 10 11 |
|
[info] [2022-05-13 14:03:58.125] [T-21336] [logging.cpp::98] [mywire] The only parameter
Function with multiple input parameters:
1 2 3 4 5 6 7 8 9 10 11 |
|
[info] [2022-05-13 14:03:38.570] [T-11468] [logging.cpp::98] [mywire] 2nd parameter
A function cannot return multiple values. So if you need to process multiple shards in the function's body then you'll have to either use (defshards)
instead of (defn)
,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
[info] [2022-05-13 14:44:51.293] [T-16928] [logging.cpp::98] [mywire] name is:
[info] [2022-05-13 14:44:51.294] [T-16928] [logging.cpp::98] [mywire] shards
or use (->)
to group and process the multiple shards inside the (defn)
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
[info] [2022-05-13 14:47:44.543] [T-21048] [logging.cpp::98] [mywire] name is:
[info] [2022-05-13 14:47:44.544] [T-21048] [logging.cpp::98] [mywire] shards
See also
defmesh¶
Defines a new mesh
on which wires can be scheduled and then run.
Note
What's a mesh
?
1 |
|
(defmesh <mesh-name>)
is actually a shorthand for the more verbose mesh definition: (def <mesh-name> (Mesh))
.
1 2 |
|
Here's an example that schedules a looped and a non-looped wire on a mesh.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
[info] [2022-03-07 22:14:51.730] [T-14836] [logging.cpp::94] [wire-hi] Hello World!
[info] [2022-03-07 22:14:51.731] [T-14836] [logging.cpp::94] [wire-bye] Goodbye World
[info] [2022-03-07 22:14:51.760] [T-14836] [logging.cpp::94] [wire-hi] Hello World!
[info] [2022-03-07 22:14:51.776] [T-14836] [logging.cpp::94] [wire-hi] Hello World!
[info] [2022-03-07 22:14:51.791] [T-14836] [logging.cpp::94] [wire-hi] Hello World!
[info] [2022-03-07 22:14:51.823] [T-14836] [logging.cpp::94] [wire-hi] Hello World!
.
.
.
See also
defloop¶
Defines a new looped wire.
1 2 3 4 |
|
Note
What's a wire
?
(defloop <wire-name>)
is a shorthand for the more verbose looped wire definition: (def <wire-name> (Wire <wire-name>))
.
1 2 3 4 5 |
|
For a wire to be executed, it must first be scheduled on a mesh
and then that mesh needs to run.
1 2 3 4 5 6 7 8 |
|
[info] [2022-05-13 09:48:01.692] [T-15068] [logging.cpp::98] [my-loop] Hello World!
[info] [2022-05-13 09:48:01.693] [T-15068] [logging.cpp::98] [my-loop] Hello World!
[info] [2022-05-13 09:48:01.694] [T-15068] [logging.cpp::98] [my-loop] Hello World!
.
.
.
A mesh will continue executing a looped wire till the mesh itself stops running (or the wire execution is stopped via a logic condition).
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
[info] [2022-03-07 22:28:54.682] [T-8432] [logging.cpp::94] [wire-hi] Hello World!
[info] [2022-03-07 22:28:54.682] [T-8432] [logging.cpp::94] [wire-bye] Goodbye World
[info] [2022-03-07 22:28:54.715] [T-8432] [logging.cpp::94] [wire-hi] Hello World!
[info] [2022-03-07 22:28:54.715] [T-8432] [logging.cpp::94] [wire-bye] Goodbye World
[info] [2022-03-07 22:28:54.731] [T-8432] [logging.cpp::94] [wire-hi] Hello World!
[info] [2022-03-07 22:28:54.732] [T-8432] [logging.cpp::94] [wire-bye] Goodbye World
.
.
.