Hi all,
A while ago, Daniel implemented alternative syntax for tuples in
extra/tuple-syntax. Instead of listing the slot values in order, you provide
a series of name/value pairs; any names omitted are assumed to have a value
of f. This syntax is more readable for tuples with a lot of slots, or when
you only want to set a number of slots. It is also more robust in the face
of refactoring and changes to slot order, as well as addition of new slots.
I'd like to put this in the core, and have '.' use it when printing tuples,
because in most cases I find the current pretty printed output for tuples
useless, and I always end up using 'describe' instead. While 'describe' is
useful in its own right, making the prettyprinter more versatile is nice.
In a private communication, Ed indicated he liked the idea but made a case
that the current 'boa' tuple syntax is useful in some cases as well. For
example, if you only have 3 slots, or if you have a series of literal tuples
in your code that you'd like to line up in a grid for readability.
There is also the issue of updating existing code for the new syntax; there
are about a thousand literal tuples in the source tree, and without some
kind of automated tool to convert one syntax to another, I'd go insane
updating it.
So it seems that the best way forward is to support both syntaxes.
Ed suggested having two parsing words; eg, T{ -v- TUPLE{.
Here's another approach. It is kind of hackish, but I like it!
Right now, most literal tuples have a delegate of f. So most look like T{
some-class-name f ... }
Well, delegates are going away soon. Suppose all code is converted to not
use delegation, but delegation is still in the core. Then *all* literal
tuples would look like T{ some-class-name f ... }.
What we can do now is misappropriate the 'f' to mean 'boa syntax', instead
of its current meaning of 'no delegate set'. If the sequence begins with
'f', it is a series of slot values. Otherwise, it is a series of name/value
pairs:
T{ color { "red" 123 } { "green" 100 } { "blue" 0 } }
T{ color f 123 100 0 }
Printing a literal tuple using '.' or 'pprint' would always use the named
slot syntax. However the 'boa' syntax could be used in source files.
This is completely backwards compatible with all existing code, and I can
implement this as soon as delegation is out.
What do you guys think?
Slava
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk