The key is the designator ‘that’ (described here)†. In plain English, insofar as is possible the two query terms mean:
find all notes (or aliases of notes) that are direct children of the container at the path ‘/Reference’
the title ($Name) of a tested note/alias exactly matches the value of $Source in the note calling the find
As the two terms us an AND query join (i.e. the ‘&
’ character ) to match, both terms must evaluate true. As a side note, only notes matching the first query are tested for the second. Why? Because both must evaluate to true
for if the first evaluates false
the outcome of the second test would be irrelevant.
The reason for the that
designator is it is the only way you can tell the query the you want to access an attribute value outside the find()
and specifically from the note running the query. If you understand the ‘agent’ designator’s behaviour, this is an analogous scenario.
I only have and early proofing draft of the book (page numbers differ) but it has slightly different code for the rule:
$MyList|=find( inside(/References) & $Name==$Source(that) );
$Author|=$Author($MyList.at(0))
$BookTitle|=$BookTitle($MyList.at(0))
(Note how your version lacks the value in the .at()
calls)
This version makes more sense but has a typo that is likely causing the typo. The rule contains 3 expressions (discrete actions) as listed one per line. But if an expression is followed by another within an overall action (e.g. here, a rule) it must have a ;
semicolon terminator. A source code line break is ignored by the code parser. The last expression does not require a terminator, but it’s a good habit to acquire. Professional coders resent extra keystrokes, but for the rest of use for whom software function is near-magical, consistency helps. So, cleaned up, we get:
$MyList|=find( inside(/References) & $Name==$Source(that) );
$Author|=$Author($MyList.at(0));
$BookTitle|=$BookTitle($MyList.at(0));
Sure enough, if I run my first example without the semicolon, I get an author name but no book title. We the semi-colon, I get both:
In my test, I added $MyList to the ‘Reading Note’ prototype’s Displayed Attributes so we can check the find()
works.
Here, you source is ‘JHF’, and the rule results in a single-item list (as in the grab above). So if $MyList holds /References/JHF
then $Author($MyList.at(0))
expands to:
$Author("/References/JHF".at(0))
i.e.
$Author("/References/JHF")
which has a value “Franklin, John Hope”. Same proves applies for the book title.
So two problems detected:
- An error in the book’s code (missing semi-colon(s). NOTE: this assumes my early proof version’s code wasn’t corrected before publication (error #2 below suggests it was not corrected)
- Copy/paste, or transcription, error by you turning a
0
in ()
.
Here is may test doc for the above:
book-ref.tbx (94.6 KB)
Note: I added a colour and badge to the prototypes just to make it clearer where they were used. Also added $MyList as a Displayed Attributes for reasons above. As I don’t have the book in question I can’t be 100% certain I’ve followed process, but I think I answered your problem
†. (Having read further) In fairness, the book’s copy does explain what 'that
means.