Tango output formatting (was: This is SO crazy. D has variable template args!)
kris
foo at bar.com
Thu Jul 12 11:43:35 PDT 2007
Craig Black wrote:
> // Tango yuck
> Stdout("x is ")(x).newline;
It not at all clear why some folks have latched onto the above syntax as
some kind of figurehead :)
This is Tango formatting:
# Stdout.formatln ("x is {}, y is {}, z is {}", x, y, z);
along with this variation for handling I18N argument indexing:
# Stdout.formatln ("x is {2}, y is {0}, z is {1}", y, z, x);
Yes, there are optional formatting specifiers within the {} also. It
just so happens that Tango /also/ supports non-formatted output using
the same entity:
# Stdout (x);
And, for those who just need to output some values quickly, sans
formatting, the same call handles more than one argument:
# Stdout (x, y, z);
Notice the lack of formatting text in the above? Instead it simply emits
", " between the arguments, since that is how it is written in the call.
It just so happens that Stdout also returns itself, which can be used
for chaining purposes. Hence, you /can/ use it in the following manner:
Stdout (x) (y) (z);
Tango has an idiom of returning a chaining instance when there's nothing
much else of value to return. The above is just a continuation of that
general pattern, and does not imply some kind of usage requirement.
I hope this helps to clarify somewhat?
More information about the Digitalmars-d-learn
mailing list