Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Getting the first child of a specific note... (Read 1781 times)
Pat Maddox
Full Member
*
Offline



Posts: 66

Getting the first child of a specific note...
Jan 8th, 2016, 12:01am
 
I have a top-level note called "days", so its path is "/days". I want an agent which finds the first child, and then its children.

Code:
first("/days") // gives me the first child 



Now I'm trying to find that thing's children:

Code:
inside(first("/days")) // this isn't it...  



update: I think I got it to work. We'll see if it holds up under use...

Code:
eval(parent, first("/days")) 



To be honest, I just lucked my way into this. I don't understand the documentation for eval at all.
Back to top
 
« Last Edit: Jan 08th, 2016, 2:04am by Pat Maddox »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Getting the first child of a specific note...
Reply #1 - Jan 8th, 2016, 5:27am
 
Functions like first() test each note (path) for a match and return a positive/negative. They don't return a set of paths of matched items. Thus if you nest inside(first()), all inside sees is 'true' or false' - which it can't use.

Here we know inside() want's a single target container, and we know the first child is a singular object (be it a note or a container). So we make this our agent query:

inside($Path(child("/days")))

inside() wants a note title or path. We'll go for caution and use path as it's less ambiguous. The designator child("/days") returns a reference to the first child note of '/days' and we use that as an offset reference for the $Path attribute. This being a path, inside() can use it. Sorry for the long explanation but the way this stacks up is more obvious after the fact - it can be hard to guess.

Also, if we have a String attribute $Target and set the agent's $Target value to "/days" (without quotes) and set that as a key attribute for the agent, you can then make the agent re-useable just be altering $Target with this query:

inside($Path(child($Target(agent))))

If $Target is a key attribute for the agent it's easier to edit that then open the Inspector or agent pop-up and edit a hard-coded note name in the query.

The above was tested in v6.4.0.
Back to top
 
« Last Edit: Apr 2nd, 2016, 12:40pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pat Maddox
Full Member
*
Offline



Posts: 66

Re: Getting the first child of a specific note...
Reply #2 - Jan 8th, 2016, 11:31am
 
Thanks! Yeah I never would have guessed that Smiley Primarily because the documentation says:

Quote:
Designators don't allow offset references as with attributes. Thus $Name("Some note") works but child("Some note") doesn't. If an offset designator is needed use find() instead.


I think I understand your code though. But how do I reconcile it with the above-quoted documentation? I'm clearly misunderstanding that part.
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Getting the first child of a specific note...
Reply #3 - Jan 8th, 2016, 11:47am
 
I think you're quoting above from aTbRef, and while aTbRef is amazingly accurate and up-to-date, even Mark Anderson nods at times.

Problem: compose a query that is true if a note is a child of the first child of /days.

Solution:  The function inside() is true for notes which are children of that note.  For example, inside(/days) would find all the children of the top-level container named "days".

Now, how can we describe the container we're interested in?  That container is the first child of /days.  So

    inside(child(/days))

should give us the result we want.  I've tried this on a sample file and it appears to behave as Id expect.

- - -
Exercises for the reader

1. Find the notes inside the last child of /days, not the first.
2. Find the notes inside the ''second'' child of /days.
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Getting the first child of a specific note...
Reply #4 - Jan 9th, 2016, 10:31am
 
@Pat, if you find something in aTbRef that you think is wrong (including doesn't work as described) or out of date, or ambiguous etc, do please drop me line. aTbRef is a public document written /maintained by me and not a formal Eastgate document. If I know them, most errors can be fixed pretty instantly. Also, reading by a fresh pair of eyes often shows up hitherto unseen ambiguity in the writing.

As regards designators it transpires the comment there re offset references is out of date. It's not clear when. It was true when I wrote it, but undocumentent changes around the time of 5.12.x likely made the info obsolete. I'll be removing it in a forthcoming update.

I repeat, for anyone reading this, that I do welcome reports of errors/typos/etc.!  Smiley
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Getting the first child of a specific note...
Reply #5 - Jan 9th, 2016, 11:37am
 
I've updated all the online aTbRef pages on designators to remove the out of date info (as revealed by discussion above).
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print