July 12, 2007
Reply to Craig,

> I agree with most that the use of << and >> or other forms of operator
> overloading are inappropriate to process variable number of arguments.
> D has variable template args built in to the freakin language.  It's
> typesafe, elegant, and straightforward.
> 
> // C++ yuck
> cout << "x is " << x << endl;
> // Tango yuck
> Stdout("x is ")(x).newline;
> // Would be best and very easy to implement
> write("x is ", x, newline);
> -Craig
> 

how about:

alias Teritef!("this is the format %B %xL %eR\n") myWrite; // args == (bool, long, real) output = (T/F, hex, exponent)

My only issue is that it needs to be some sort of wrapper or huge code bloat will be a problem.


July 12, 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?










July 12, 2007
Oh OK.  Tango is now redeemed.

"kris" <foo@bar.com> wrote in message news:f75sn0$187s$1@digitalmars.com...
> 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?
>
>
>
>
>
>
>
>
>
> 


July 12, 2007
Craig Black Wrote:

> // Tango yuck
> Stdout("x is ")(x).newline;

Like anything else, it's a matter of taste. I dind the massive quantities of parentheses good visual separation.
July 12, 2007
More power to ya!

"Robert Fraser" <fraserofthenight@gmail.com> wrote in message news:f762u9$1l5l$1@digitalmars.com...
> Craig Black Wrote:
>
>> // Tango yuck
>> Stdout("x is ")(x).newline;
>
> Like anything else, it's a matter of taste. I dind the massive quantities of parentheses good visual separation.


July 12, 2007
kris wrote:
> 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 :)

I think its a factor of a few things.

1) Remembrance of the "whisper" syntax's debut in DSC/Mango.  (I can't actually remember if it was present in DSC before the name change...)

2) The fact that it did somehow end up the common way of using Stdout for some while (although I personally use .format() more often anymore).

3) A certain long and elaborate discussion about the reliability of call chaining, where "whisper" became the central case study.

4) The mysteries of human nature.  :)

-- Chris Nicholson-Sauls
July 13, 2007
Craig Black wrote:
> Oh OK.  Tango is now redeemed.

Thank goodness :-)


> 
> "kris" <foo@bar.com> wrote in message news:f75sn0$187s$1@digitalmars.com...
>> 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?
July 13, 2007
Chris Nicholson-Sauls wrote:
> I think its a factor of a few things.
> 
> 1) Remembrance of the "whisper" syntax's debut in DSC/Mango.  (I can't actually remember if it was present in DSC before the name change...)

You remember that far back? :)
July 13, 2007
kris wrote:
> Chris Nicholson-Sauls wrote:
>> I think its a factor of a few things.
>>
>> 1) Remembrance of the "whisper" syntax's debut in DSC/Mango.  (I can't actually remember if it was present in DSC before the name change...)
> 
> You remember that far back? :)

The dsc.io package was a life (ok, time) saver for me then.  Heck yeah I remember it.  ;)

-- Chris Nicholson-Sauls
July 19, 2007
Bill Baxter wrote:
> Carlos Santander wrote:
>> Bruce Adams escribió:
>>>
>>> and type safe compared to:
>>>
>>> stdout.writefln("%s%s%i", foo,bar,2);
>>>
>>
>> D has typesafe variadics, so you can just say:
>>
>> dout.writefln("%s%s%s", foo,bar,2);
> 
> Or just dout.writefln(foo,bar,2); in this case.
> 
> 
>> %s doesn't mean "pretend it's a string," but rather "write its string representation."
> 
> I agree that compile time type-checked format parameters would be nice.
> 
>   writefln("%d", someObject);
> 
>   >> ERROR: someObject is not an integer
> 
> Would be nice.  A couple of people were trying to get this to work using compile time string processing.  Maybe they'll pipe in here at some point...
> 
> --bb
It's still waiting for macros.
mixin(Writefln(`"%d", someObject`));
will work perfectly (including error messages pointing to the line of the user's code), but it's just too ugly.

The nice thing about it is, there's no template bloat, and no use of RTTI.

It is also already possible to do:
Writefln!("%d")(someObject);
also a bit ugly, and with code bloat.

All we need is a tiny bit of syntax sugar.
Next ›   Last »
1 2 3
Top | Discussion index | About this forum | D home