Seeing though Nova's eyes
Last time, we talked about the core mechanisms of Nova, rules that work on stacks of facts that are lists of symbols. This time, I want to talk more how Nova machines see the world, how the causes of a rule are matched against the current Nova state.
Sometimes things happen for more than one reason
The causes of a rule can be spread across more than one stack. To specify causes after the first, just type up the another stack label, like so:
|:a: 1 :b: 2| :do: things
As an example, the Nova below won't match any rules, remaining in the || :b: 2
state.
|:a: 1 :b: 2|
:c: 3
|| :b: 2
But this Nova will fire its rule, ending up in the state || :c: 3
.
|:a: 1 :b: 2|
:c: 3
|| :a: 1
:b: 2
Some differences don't matter
Nova can be told to ignore the exact contents of a given symbol in a pattern. In Myte, the $
symbol at the start of a symbol is used for this. As an example:
| :action: draw from deck
:deck: $rank of $suit |
:did: draw a card
Here, we can satisfy the :deck: $rank of $suit
cause with any card represented by a fact of 3 symbols where the middle symbol is of
. The card :deck: Two of Clubs
satisfies the cause just as well as the :deck: Queen of Hearts
card. This ability to use wildcards for symbols and give the wildcard a name is usually refered to as using variables.
Sometimes you need to know two things are the same
If you repeat the same variable name twice in a pattern, that tells Nova that you want the symbols in both slots to have the same value. For example:
| :action: check for suit match
:pile: $rank of $suit
:hand: $otherRank of $suit |
:pile: $rank of $suit
:hand: $otherRank of $suit
This will make sure that the top of the :pile:
stack has the same suit as the top of the :hand:
stack.
Sometimes you want to look at a thing, but put it back
The pattern of looking at facts, and putting them back, shown in the previous example has a shorthand in Myte. Add a ?
at the end of a fact, and it'll get put right back. To rewrite the previous example to use this:
| :action: check for suit match
:pile: $rank of $suit?
:hand: $otherRank of $suit? |
Sometimes you need to see a sequence of facts
The other thing that Nova lets you do is look for a sequence of facts. So, if you wanted to check for the royal flush poker hand:
| :check: for Royal Flush
:sorted hand: Ace of $suit?
:sorted hand: King of $suit?
:sorted hand: Queen of $suit?
:sorted hand: Jack of $suit?
:sorted hand: Ten of $suit? |
:: yes
|:check: for Royal Flush|
:: no
This pattern comes up often enough that Myte has a couple of shorthands for it. The first is that if .
is the first symbol in a given cause or effect, then when .
shows up again, it stops the current fact, and starts a new fact on the same stack. This means you can also write the Royal Flush Check like so:
| :check: for Royal Flush
:sorted hand:
. Ace of $suit?
. King of $suit?
. Queen of $suit?
. Jack of $suit?
. Ten of $suit? |
:: yes
|:check: for Royal Flush|
:: no
Sometime you're looking for things like strings of beads
Nova can look for (and emit) stacks that are a chain one-symbol facts. This can be useful if you're writing a list of short instructions, or a code, for example. Myte does this when facts start with (
and end with )
. For an example:
| :: decode? :beads: ( red blue ) |
:letter: O
| :: decode? :beads: ( red green ) |
:letter: N
| :: decode? :beads: ( green red ) |
:letter: A
| :: decode? :beads: ( red yellow ) |
:letter: I
| :: decode? :beads: ( green blue ) |
:letter: V
| :: decode? :beads: ( yellow red ) |
:letter: !
| :: decode? :beads: ( yellow blue ) |
:letter: H
| :: decode? :beads: ( yellow green )|
:letter: ,
||
:beads: (
yellow blue red yellow
yellow green red green
red blue green blue
green red yellow red
)
:: decode
If you use .
instead of the parenthesis, the Nova would look like this:
| :: decode? :beads: . red . blue |
:letter: O
| :: decode? :beads: . red . green |
:letter: N
| :: decode? :beads: . green . red |
:letter: A
| :: decode? :beads: . red . yellow |
:letter: I
| :: decode? :beads: . green . blue |
:letter: V
| :: decode? :beads: . yellow . red |
:letter: !
| :: decode? :beads: . yellow . blue |
:letter: H
| :: decode? :beads: . yellow . green |
:letter: ,
||
:beads:
. yellow . blue . red . yellow
. yellow . green . red . green
. red . blue . green . blue
. green . red . yellow . red
)
:: decode
Conclusion
Thanks for reading so far! There will be more Nova explainers to come, but hopefully this helped you understand Nova better.