How Nova makes complicated decisions
Last time, we talked about how Nova sees the world through patterns. This time, we're going to talk about how to use combinations of patterns to make complicated decisions.
Rules OR decisions AND patterns
The first thing is that if you have a number of conditions that all result in the same outcome, you can list them out, one after the other:
|:decide: do I go to work
:am I: sick?|
:: no
|:decide: do I go to work
:today is: a work holiday |
:: no
|:decide: do I go to work
:today is: a weekend day |
:: no
If you've done boolean logic, this is similar to OR. In plain language: If I am sick, or it's a work holiday, or it's a weekend day, then I don't go to work.
If you need multiple conditions to be true at the same time, the most basic way to do that is to list all of them in a single rule's causes
|:decide: do I go to work
:am I: healthy?
:today is: a weekday |
:: yes
And this gets you basic boolean AND logic.
Checking for things that do NOT exist
Nova has a number of patterns that are harder to guess, and checking that something is not true is often one of the first that trips people up.
In Nova, there's no pattern that directly asks if something does not exist. Instead, the approach is to check if something does exist, and then, the check doesn't succeed, the next rule can know that it doesn't exist. For example, to check if a stack is empty:
|:check: are my pockets empty
:pockets: $things?|
:: no
|:check: are my pockets empty|
:: yes
This rule only works properly if the :pockets:
stack only have has single-symbol facts, but it can be extended to deal with multiple arities in a straightforward, if slightly repetitive manner:
|:NOTE: Continue as needed |
|:check: are my pockets empty
:pockets: $a $b $c?|
:: no
|:check: are my pockets empty
:pockets: $a $b?|
:: no
|:check: are my pockets empty
:pockets: $a?|
:: no
|:check: are my pockets empty|
:: yes
Waiting for things to happen
Another, slightly more involved pattern for AND-ing conditions together, especially if they will be on a single stack, is to use multiple rules, each catching a specific condition, and then setting a specific stack for that condition. The example below illustrates that.
||
:: get beads for pattern
:bag:
. green shell
. blue plastic
. red wood
. red iron
. red quartz
. blue brass
. red metal
. green wood
. red gem
| :: get beads for pattern |
:search bag:
:need red:
:need green:
:need blue:
| :search: bag?
:need red:
:bag: red $type |
:has red: $type
| :search: bag?
:need green:
:bag: green $type |
:has green: $type
| :search: bag?
:need blue:
:bag: blue $type |
:has blue: $type
| :search: bag?
:bag: $color $type |
:bowl: $color $type
| :search: bag |
| :bowl: $color $type |
:bag: $color $type
| :has red: $r
:has green: $g
:has blue: $b |
:thread: ( $r $g $b )
That's all for now!