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
Vector attribute type (Read 4345 times)
Alastair
Full Member
*
Offline



Posts: 42
Christchurch, UK
Vector attribute type
Nov 30th, 2011, 7:31am
 
(I apologise in advance if I'm not using the correct terminology here, I'm neither a programmer nor a statistician)

I'd find a vector-type attribute useful: ie. a single directional array of numbers/strings, such that $MyNumber(n) that holds the nth value of $MyNumber for each note.

It's quite possible that this can be done already; in fact I'm sure that it could be achieved with lists in some way, but as far as I can tell lists have to be written sequentially.  Also, a dedicated attribute type would have the advantage of retaining its structure if data were accidentally deleted.
Back to top
 
« Last Edit: Nov 30th, 2011, 7:31am by Alastair »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Vector attribute type
Reply #1 - Nov 30th, 2011, 8:24am
 
Isn't this what List/Set.at() does? The .at() operator is zero-based, i.e. $MyList.at(1) returns the value of the second item in list $MyList. It can be used with literal lists:

$MyString = "ant;bee;cow;dog".at(1) --> $MyString is "bee"

$MyList = "ant;bee;cow;dog";
$MyString = $MyList.at(3);
--> $MyString is "dog"

As .at() gets but can't set a value the operator might better be thought of as a read-only property of TB lists or sets.

TB doesn't have arrays. All 'arrays' are lists which are strings with TB. The value returned from a list is always a string but by passing it into an attribute of the right type a data type is set. TB will coerce data accordingly.

$MyString = "30/11/2011";  --> "30/11/2011"
$MyNum = "30/11/2011" --> 30  (first number found in the string)
$MyDate = "30/11/2011" --> date of 30 Nov 2011
but
$MyNum = eval("30/11/2011") --> 0.00135618 i.e. (30/11)/2011

For anyone on a month/day order system, you might want to try the above with "11/30/2001".
Back to top
 
« Last Edit: Nov 30th, 2011, 8:35am by Mark Anderson »  

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



Posts: 42
Christchurch, UK
Re: Vector attribute type
Reply #2 - Nov 30th, 2011, 10:42am
 
"As .at() gets but can't set a value the operator might better be thought of as a read-only property of TB lists or sets."


So is there a simple way to write to the nth item in $MyList, where the list in question may have >300 items on it?

I can see that there is a close similarity with list.at, and can usually use that to the same effect; what I'm suggesting is really a more structured subset of lists - with the ability to write directly to any point on that list.

I'm currently analysing some sports results across a twenty year period (50,000 fixtures and counting..)  I can use agents to collect running totals for goals, points, etc for each club, then use those lists to calculate league position and therefore track the progress of each club. List.at(n) works perfectly for this.

I suppose I'm slightly nervous that one tweak to an agent might result in 'misaligned' data, where some lists have fewer items then others and the comparisons are no longer valid - an array type attribute initially comprising a defined number of <empty> items might make it easier to be certain.

Back to top
 
« Last Edit: Nov 30th, 2011, 10:43am by Alastair »  
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Vector attribute type
Reply #3 - Nov 30th, 2011, 11:18am
 
In most applications, rather than having long vectors

    $Goals.at(231)
    $Penalties.at(231)

I expect people would have a container with notes for each entry, so the 231st child of /Seasons has scalar values for $Goals, $Penalties, etc.

We don't currently have a really good primitive for picking out the nth child in a container, as one is usually more interested in the edge cases -- first, last -- and summary values like max, min, any, every, and sum.  When needed, of course, you can use find() to get the nth child, though this isn't very efficient.  I'd welcome a use case argument (to info@eastgate.com) if you think nthChild would be widely used.
Back to top
 
 
WWW   IP Logged
Pages: 1
Send Topic Print