User loginNavigation |
Syntax of Literal Tables (Assocative Collections) and Auto-generated fieldsIn Heron I'm adding literal tables which like literal dictionaries/maps/hashes/tables in many languages (e.g. Python, Ruby, etc.) are intended to provide a convenient syntax for associative collection literals. The syntax looks like this: var animals = table(animal:String, sound:String, legs:Int) { "Dog", "woof", 4; "Cat", "meow", 4; "Human", "hello", 2; }; The first column is used as a key, and the "value" is an anonymous record containing the other columns. So you you can say: Question one: what other languages that have built-in support associative collections with more than two columns? Now obviously this looks a lot like a simple array of objects: but the identity is chosen as the first field. So an interesting application is to construct an object-oriented programming system built from tables alone. It would then be helpful if the first field could be an auto-generated immutable integer id (e.g. the object address, or the database auto-generated key field). So then the question becomes what syntax should I use? I'm thinking of something like: var animals = table(self:Id, animal:String, sound:String, legs:Int) { $, "Dog", "woof", 4; $, "Cat", "meow", 4; $, "Human", "hello", 2; }; Question two: I don't want to invent brand new syntax, what syntax do other languages use for similar features (auto-generated ids)? By cdiggins at 2010-01-20 12:51 | LtU Forum | previous forum topic | next forum topic | other blogs | 10893 reads
|
Browse archives
Active forum topics |
Recent comments
27 weeks 1 day ago
27 weeks 2 days ago
27 weeks 2 days ago
49 weeks 3 days ago
1 year 1 week ago
1 year 3 weeks ago
1 year 3 weeks ago
1 year 5 weeks ago
1 year 10 weeks ago
1 year 10 weeks ago