Variables in Zet

Variables in Zet

This page aims to outline how variables in zetwork.

Variables are entries in Zet that have mutable state and can be addressed by a keyword. A variable is attached to a particular UUID item.

If necessary, create a new weewiki in the current directory.

$ weewiki create

Create a "hello world" message using rawsay. It will return the UUID.

$ weewiki zet rawsay "hello world"

All commands maintaining variables are done with the subcommand var. From now on, a command like new will mean weewiki zet var new.

Create a new variable that is tied to the newly created zet entry fc2a56 and call it foo. This is done with new

$ weewiki zet var new fc2a56 foo

By default, it is set to be empty. One can set it to be a message with set.

$ weewiki zet var set fc2a56 bar

Using get will return the current value. (This currently hasn't been implemented yet, but will be soon).

$ weewiki zet var get fc2a56 bar

Variables can also be set to be addresses of other items, which proves to be extremly helpful. They are the foundational building block for zetdo, a TODO app written on top of zet.

To explore this, first create two new groups "alpha" and "beta" using the zet mkgroup command. Also, make a new message again using rawsay.

$ weewiki zet mkgroup alpha
$ weewiki zet mkgroup beta
$ weewiki zet rawsay "here is another message"

Create a state variable for entries 5cca6 and fc2a5, and use the (var) link command to set them both to the alpha group. Appending "@" tells the zet that it is a group, and will try to resolve it to find the UUID associated with it.

$ weewiki zet var new 5cca6 state
$ weewiki zet var link 5cca6 state @alpha
$ weewiki zet var new fc2a5 state
$ weewiki zet var link fc2a5 state @alpha

Using the lists command, one list all the zet entries associated with a particular variable set to a particular value.

To see the messages just created, look for all items with a variable state set to be @alpha.

$ weewiki zet var list state @alpha
2021-01-27 13:56:56     fc2a5658-a598-4de6-abe8-cb8b9b0de505    >hello world
2021-01-27 14:14:48     fc2a5658-a598-4de6-abe8-cb8b9b0de505    $foo:>bar
2021-01-27 14:27:51     5cca6d4e-0994-4473-a447-0d1209d120e7    >here is another message
2021-01-27 14:30:54     5cca6d4e-0994-4473-a447-0d1209d120e7    $state:#3a17096d-3091-4baf-811d-943095d9982e
2021-01-27 14:32:08     fc2a5658-a598-4de6-abe8-cb8b9b0de505    $state:#3a17096d-3091-4baf-811d-943095d9982e

But whoah, that's a lot of stuff! awk can be used to filter out some of the results

$ weewiki zet var list state @alpha | \
> awk -F "\t" '$3 ~ "^>" {print $1, substr($2, 1, 8), substr($3, 2)}'
2021-01-27 13:56:56 fc2a5658 hello world
2021-01-27 14:27:51 5cca6d4e here is another message

Setting the item fc2a5 state to be @beta removes it from this list, and puts it on a similar beta command.

$ weewiki var link fc2a5 state @beta
$ weewiki zet var list state @beta | \
> awk -F "\t" '$3 ~ "^>" {print $1, substr($2, 1, 8), substr($3, 2)}'
2021-01-27 13:56:56 fc2a5658 hello world

In practice, it's best to write these one-liners as shell scripts. This is basically how zetdo was born.

home | index