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
How to iterate over a set? (Read 6315 times)
Pascal D.
Full Member
*
Offline



Posts: 5

How to iterate over a set?
Jul 09th, 2009, 11:52am
 
This might have already been covered but I can't find any references so... here goes...

I just started playing around with Actions and Rules.  I would like to collect notes and then change an attribute of all the notes collected.

So, let's say the names of the collected notes are sent in a set named "notes".

$notes=collect(/x/y/z,$Name)

now I would like to change an attribute for all the collected notes in "notes".

attrX($notes)="foo"

So I wrote a Stamp with the following Action:

$notes=collect(/x/y/z,$Name);attrX($notes)="foo"

I half expected Tinderbox to understand it needed to iterate over every element of the set "notes" and change the attribute attrX to "foo".

So the question is: how do you iterate over a set?  Do I need to write my own loop extracting every element of the set by detecting the ';' char?

Thanks!
Pascal
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: How to iterate over a set?
Reply #1 - Jul 9th, 2009, 12:11pm
 
You don't iterate over a set.

Instead, make an agent that collects the notes you want; its query is the argument you used in collect.  The action you want to perform on each note is the agent's OnAdd action.

Background: we've worked hard in Tinderbox to keep the action language simple, and specifically to avoid loops. Agents embody iteration, and they work nicely with other agents; it's an unusual expedient but it generally works well.

But, we're also interested in extensions in which explicit or implicit collections of notes could serve as designators.

       $Color(children)="red";  <-- hypothetical

would turn all the note's children red.  Conceivably:

      $Color(query(..some query...)="red" <-- hypothetical

could turn all the notes that match some query red.  Getting the syntax right -- and not breaking too much crockery in the process -- is a bit challenging.
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: How to iterate over a set?
Reply #2 - Jul 9th, 2009, 1:09pm
 
@Pascal, in v4.6.0+ syntax:

AgentQuery:  inside(x/y/z)
AgentAction: $attrX="foo"

Once the agent had run you can then delete the agent if the process isn't needed again.
Back to top
 
 

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



Posts: 5

Re: How to iterate over a set?
Reply #3 - Jul 9th, 2009, 2:09pm
 
Quote:
You don't iterate over a set.

Instead, make an agent that collects the notes you want; its query is the argument you used in collect.  The action you want to perform on each note is the agent's OnAdd action.


Yes, a note is a container and can thus be seen as a collection... makes sense.  Thanks for the input!

Quote:
Background: we've worked hard in Tinderbox to keep the action language simple, and specifically to avoid loops. Agents embody iteration, and they work nicely with other agents; it's an unusual expedient but it generally works well.


I like the way it works.  I just need to adapt to it and it is not THAT hard.

Pascal
Back to top
 
 
  IP Logged
peter
Ex Member




Re: How to iterate over a set?
Reply #4 - Aug 15th, 2009, 1:24am
 
this implicit iteration sounds to me like the coders are invoking the paradigm of "functional programming" rather than procedural ?
Peter
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print