Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Off The Wall: Feature Ideas >> Vector attribute type
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1322656281

Message started by Alastair on Nov 30th, 2011, 7:31am

Title: Vector attribute type
Post by Alastair on 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.

Title: Re: Vector attribute type
Post by Mark Anderson on 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".

Title: Re: Vector attribute type
Post by Alastair on 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.


Title: Re: Vector attribute type
Post by Mark Bernstein on 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.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.