|Pliant talk forum
Feature request: each syntax for Set datatype
I find not intuitive to use keyof in many cases.
|Message posted by maybe Boris Reitman on 2008/06/17 11:50:16
|if I declare Set:Int tags, where the value represents the number of times tag
appear, I'd prefer to iterate like this:
each (tag count) tags
console "tag = " tag " appears " count " times"
each count tags
console "tag = " keyof:tag " appears " count " times"
The reason is that the "each count tags" line sets the stage for the interation
int terms of readability, and it is not clean that we are iterating over keyof:tag as the main value,
and count is extra information.
I often use Set:Bool and I really only care about the "exists" relationship,
and I want to iterate over the keys. Then it becomes even less clear. I think
that the Set declaration should have also accept this kind of syntax:
field Set member_ids
each member_id member_ids
console "got member_id: " member_id eol
the each will actually iterate over the string keys rather than values,
because datatype for the value is not declared.
So I am requesting two features: ability to be more explicit about key/value
in "each" for Set:X declarations, and also ability to declare a Set datatype
(a collection) and iterate over its members.
|Message posted by maybe Hubert Tonneau on 2008/06/19 22:28:00
|I don't share your taste here.
If you have:
var List:Str l
then you can still use 'each' to enumerate the values in the list, but no key
is associated with each element.
What an element is associated with really depends on the kind of agregate.
For 'Set' it is a key, for 'List' it is nothing.
'each' provides you each element one after the other and it seems just fine
and natural to me.
In your example, you use a set as an efficient way to count how many elements
you have for each value. The price for your efficient implementation is that
you reversed the semantic. It's a trick.
You could as well have a simple but inefficient coding like this:
field Set:Str tags
method tags count tag -> n
arg (Data Set:Str) tags ; arg Str tag ; arg Int n
n := 0
each t tags
n += 1
|Message posted by maybe Boris Reitman on 2008/06/22 19:41:48
|ok, but List is not supported in the database right now.
So, I have to use Set:Bool instead of List now. Or is it supported already ?
Also, suppose List was a supported database type. What if I want to upgrade
List to Set ? Its a natural upgrade - a set to a multi-set
(every element in Set:X has associated satellite data of type X).