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
Need a while-loop workaround (Read 3375 times)
Rob Forsyth
Full Member
*
Offline



Posts: 63

Need a while-loop workaround
Jan 02nd, 2014, 4:47pm
 
Dear TBXers

Struggling to achieve something that would be trivial with a do…while type looping construct and hoping someone can show me how to achieve the equivalent with the existing toolbox

The details of the specific application I have are rather involved but what I'm trying to achieve is:

1. I have a collection of sibling notes sharing a running total attribute which contains the sum of $x + $x(prevSibling). They also have an unrelated attribute $y set individually for each note.
2. In another part of the outline structure I have a note with attribute $z. In this note I want to return the value of $y for the first of the above collection of notes for which $z < $x

Hope that makes sense

Thanks as ever

Rob


Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Need a while-loop workaround
Reply #1 - Jan 2nd, 2014, 5:15pm
 
1: Make an agent that finds all notes with $z<$x.
2: Sort the agent by outline order
3: The first child of the agent is the note you want

You could also use find() to build the list of notes, picking off the first element in the list to get the path of the note of interest.
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Need a while-loop workaround
Reply #2 - Jan 3rd, 2014, 3:39am
 
To build out Mark's find() suggestion…

Rob says in bullet 1 that the target notes are all siblings. For this exercise I'll call the container "AA" as all target notes have a common parent and it helps if we scope the query as tight as possible.

find(query) returns a list of $Path values:

  find(inside("AA")&($z<$x))

To ensure the first list item is the first query-valid child of AA the list must be sorted on $OutlineOrder:

  find(inside("AA")&($z<$x)).sort($OutlineOrder)

The list is now sorted and .at(0) gives the first item. Thus:

  find(inside("AA")&($z<$x)).sort($OutlineOrder).at(0)

Now that returns the (unique) $Path of a single note - for which you want the value of $y. So, the find() can be used as the reference in $attribute(offset_reference) form, i.e. $y(PathToNote):

  $MyAttr = $y(find(inside("AA")&($z<$x)).sort($OutlineOrder).at(0))

I've deliberately written this in iterative form so newer users can see how to build the complex end code by starting with a find() and adding extra filters. When first experimenting with this sort of task also consider using other attributes to store the inner parts of the process, e.g. the list from the basic find(), so that if the overall result is wrong it can help to show which stage is wrong.

Outline column view is also useful. Here the code is being tested in the $Rule of container "Content" whose $y is being set to the output of the code. It correctly reports 'ddd' (where notes 'dog' and 'fly' are the only two where $z < $x):

Back to top
 
« Last Edit: Jan 3rd, 2014, 9:01am by Mark Anderson »  

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



Posts: 63

Re: Need a while-loop workaround
Reply #3 - Jan 3rd, 2014, 9:50am
 
Thanks both, as ever

Mark's approach has worked for me but thanks for the example of the new dot syntax which I need to get up to speed with!

Rob

Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Need a while-loop workaround
Reply #4 - Jan 3rd, 2014, 10:11am
 
Sure, the expansion was more of a general mini-demo for later readers.  Smiley
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