Jump to page: 1 28  
Page
Thread overview
formatted output trial balloon
Nov 06, 2003
Walter
Nov 06, 2003
Walter
Nov 06, 2003
Kazuhiro Inaba
Nov 06, 2003
Walter
Nov 06, 2003
Russ Lewis
Nov 07, 2003
Walter
Nov 07, 2003
Jan-Eric Duden
Nov 07, 2003
Russ Lewis
Nov 08, 2003
Walter
Nov 10, 2003
Russ Lewis
Nov 06, 2003
Charles Sanders
Nov 06, 2003
Ben Hinkle
Nov 06, 2003
J Anderson
Nov 06, 2003
Sean L. Palmer
Nov 06, 2003
Charles Sanders
Nov 06, 2003
Andy Friesen
Nov 06, 2003
Charles Sanders
Nov 06, 2003
Andy Friesen
Nov 06, 2003
J Anderson
Nov 06, 2003
Roberto Mariottini
Nov 06, 2003
Matthew Wilson
Nov 10, 2003
Sean L. Palmer
Nov 10, 2003
Matthew Wilson
Nov 06, 2003
Dario
Nov 06, 2003
Dario
Nov 06, 2003
Matthew Wilson
Nov 06, 2003
Dario
Nov 06, 2003
Jonathan Andrew
Nov 06, 2003
Walter
Nov 06, 2003
Helmut Leitner
Nov 06, 2003
Sean L. Palmer
Nov 08, 2003
Walter
Nov 08, 2003
Walter
Nov 10, 2003
Sean L. Palmer
Nov 06, 2003
Matthew Wilson
Nov 08, 2003
Walter
Nov 06, 2003
Andy Friesen
Nov 06, 2003
J Anderson
Nov 06, 2003
Matthew Wilson
Nov 06, 2003
Andy Friesen
Nov 06, 2003
Hauke Duden
Nov 06, 2003
Sean L. Palmer
Nov 06, 2003
Matthew Wilson
Nov 10, 2003
Sean L. Palmer
Nov 06, 2003
Sean L. Palmer
Nov 06, 2003
Matthew Wilson
Nov 07, 2003
Ilya Minkov
Nov 08, 2003
Jeandré du Toit
Nov 06, 2003
Roberto Mariottini
Nov 06, 2003
Hauke Duden
Nov 06, 2003
Roberto Mariottini
Nov 06, 2003
Jan-Eric Duden
Nov 06, 2003
Ilya Minkov
Feb 21, 2004
Walter
Feb 21, 2004
Vathix
Feb 21, 2004
Ben Hinkle
Nov 07, 2003
Roberto Mariottini
Nov 06, 2003
Ben Hinkle
Nov 06, 2003
Matthew Wilson
Nov 06, 2003
Russ Lewis
Nov 06, 2003
Matthew Wilson
Nov 06, 2003
Russ Lewis
Nov 07, 2003
Ilya Minkov
Nov 07, 2003
Hauke Duden
Nov 06, 2003
Ben Hinkle
Nov 10, 2003
Sean L. Palmer
Nov 06, 2003
Patrick Down
Nov 10, 2003
Sean L. Palmer
Nov 16, 2003
Matthias Becker
Nov 16, 2003
Jan Knepper
November 06, 2003
Since with () overloading class objects can now look like functions, I've been toying with the idea of using this for formatted I/O. Here's a trial mockup of what it might look like:

-----------------------------------------------
import std.string;
import std.c.stdio;
import std.c.stdlib;

class Stdout
{
    Stdout opCall(int i)
    {
 printf("%d", i);
 return this;
    }

    Stdout opCall(char[] format, ...)
    {
 va_list ap;
 ap = cast(va_list)&format;
 ap += format.size;
 vprintf(format, ap);
 return this;
    }

    Stdout nl()
    {
 printf("\n");
 return this;
    }
}

void main()
{  Stdout stdout = new Stdout();
    stdout("hello")(" world")(47).nl()("bar")("%06i\n", 62);
}
-------------------------------------------

(Note that it retains the power of printf!) The issue here is how the syntax
stdout("foo")("bar") looks. In C++ it would look like stdout<<"foo"<<"bar"
which I don't find appealing.


November 06, 2003
Andy Friesen also had very close to this idea earlier. -Walter

http://www.digitalmars.com/drn-bin/wwwnews?D/17402


November 06, 2003
I like it!  Im not a fan of the .nl() though it looks inconsistent, not sure how else to handle it though.

C

"Walter" <walter@digitalmars.com> wrote in message news:boc9me$1g2b$1@digitaldaemon.com...
> Since with () overloading class objects can now look like functions, I've been toying with the idea of using this for formatted I/O. Here's a trial mockup of what it might look like:
>
> -----------------------------------------------
> import std.string;
> import std.c.stdio;
> import std.c.stdlib;
>
> class Stdout
> {
>     Stdout opCall(int i)
>     {
>  printf("%d", i);
>  return this;
>     }
>
>     Stdout opCall(char[] format, ...)
>     {
>  va_list ap;
>  ap = cast(va_list)&format;
>  ap += format.size;
>  vprintf(format, ap);
>  return this;
>     }
>
>     Stdout nl()
>     {
>  printf("\n");
>  return this;
>     }
> }
>
> void main()
> {  Stdout stdout = new Stdout();
>     stdout("hello")(" world")(47).nl()("bar")("%06i\n", 62);
> }
> -------------------------------------------
>
> (Note that it retains the power of printf!) The issue here is how the
syntax
> stdout("foo")("bar") looks. In C++ it would look like stdout<<"foo"<<"bar"
> which I don't find appealing.
>
>


November 06, 2003
Note .nl() is the same as ("\n") if that's any better.

-Ben

"Charles Sanders" <sanders-consulting@comcast.net> wrote in message news:bocf1q$1o62$1@digitaldaemon.com...
> I like it!  Im not a fan of the .nl() though it looks inconsistent, not
sure
> how else to handle it though.
>
> C
>
> "Walter" <walter@digitalmars.com> wrote in message news:boc9me$1g2b$1@digitaldaemon.com...
> > Since with () overloading class objects can now look like functions,
I've
> > been toying with the idea of using this for formatted I/O. Here's a
trial
> > mockup of what it might look like:
> >
> > -----------------------------------------------
> > import std.string;
> > import std.c.stdio;
> > import std.c.stdlib;
> >
> > class Stdout
> > {
> >     Stdout opCall(int i)
> >     {
> >  printf("%d", i);
> >  return this;
> >     }
> >
> >     Stdout opCall(char[] format, ...)
> >     {
> >  va_list ap;
> >  ap = cast(va_list)&format;
> >  ap += format.size;
> >  vprintf(format, ap);
> >  return this;
> >     }
> >
> >     Stdout nl()
> >     {
> >  printf("\n");
> >  return this;
> >     }
> > }
> >
> > void main()
> > {  Stdout stdout = new Stdout();
> >     stdout("hello")(" world")(47).nl()("bar")("%06i\n", 62);
> > }
> > -------------------------------------------
> >
> > (Note that it retains the power of printf!) The issue here is how the
> syntax
> > stdout("foo")("bar") looks. In C++ it would look like
stdout<<"foo"<<"bar"
> > which I don't find appealing.
> >
> >
>
>


November 06, 2003
Charles Sanders wrote:

>I like it!  Im not a fan of the .nl() though it looks inconsistent, not sure
>how else to handle it though.
>
>C
>  
>
Instead of nl you could have a constant, ie endl

stdout("hello")(" world")(47)(endl)("bar")("%06i\n", 62);


November 06, 2003
"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bocj2a$1tns$2@digitaldaemon.com...
> Charles Sanders wrote:
>
> >I like it!  Im not a fan of the .nl() though it looks inconsistent, not
sure
> >how else to handle it though.
>
> Instead of nl you could have a constant, ie endl

Yah.

> stdout("hello")(" world")(47)(endl)("bar")("%06i\n", 62);

Why on earth would you go to all the trouble to replace printf, and end up supporting the same bad technique anyway in all its untype-safe glory?  That last bit should be some kind of integer formatting function or object.

Sean


November 06, 2003
In article <bocf1q$1o62$1@digitaldaemon.com>, Charles Sanders says...
>
>I like it!  Im not a fan of the .nl() though it looks inconsistent, not sure how else to handle it though.
>
>C

I agree. ("\n") seems a little cleaner to me. Also, would it make sense to
declare Stdout
static in stdio so you don't need to instantiate it each time?

-Jon
>
>"Walter" <walter@digitalmars.com> wrote in message news:boc9me$1g2b$1@digitaldaemon.com...
>> Since with () overloading class objects can now look like functions, I've been toying with the idea of using this for formatted I/O. Here's a trial mockup of what it might look like:
>>
>> -----------------------------------------------
>> import std.string;
>> import std.c.stdio;
>> import std.c.stdlib;
>>
>> class Stdout
>> {
>>     Stdout opCall(int i)
>>     {
>>  printf("%d", i);
>>  return this;
>>     }
>>
>>     Stdout opCall(char[] format, ...)
>>     {
>>  va_list ap;
>>  ap = cast(va_list)&format;
>>  ap += format.size;
>>  vprintf(format, ap);
>>  return this;
>>     }
>>
>>     Stdout nl()
>>     {
>>  printf("\n");
>>  return this;
>>     }
>> }
>>
>> void main()
>> {  Stdout stdout = new Stdout();
>>     stdout("hello")(" world")(47).nl()("bar")("%06i\n", 62);
>> }
>> -------------------------------------------
>>
>> (Note that it retains the power of printf!) The issue here is how the
>syntax
>> stdout("foo")("bar") looks. In C++ it would look like stdout<<"foo"<<"bar"
>> which I don't find appealing.
>>
>>
>
>


November 06, 2003
But what would endl be defined as, an arbitrary number ?  How would it know i didnt actually want to output that specific number ?

C
"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message
news:bocj2a$1tns$2@digitaldaemon.com...
> Charles Sanders wrote:
>
> >I like it!  Im not a fan of the .nl() though it looks inconsistent, not
sure
> >how else to handle it though.
> >
> >C
> >
> >
> Instead of nl you could have a constant, ie endl
>
> stdout("hello")(" world")(47)(endl)("bar")("%06i\n", 62);
>
>


November 06, 2003
Walter wrote:

> Since with () overloading class objects can now look like functions, I've
> been toying with the idea of using this for formatted I/O. Here's a trial
> mockup of what it might look like:
> 
> [...]

> (Note that it retains the power of printf!) The issue here is how the syntax
> stdout("foo")("bar") looks. In C++ it would look like stdout<<"foo"<<"bar"
> which I don't find appealing.

I think () is a bit too busy.  '~' may be better, since it's a lot less hoggish in terms of eyeball-space.  Plus, D already uses it to indicate concatenation.

stdout ~ "Hello " ~ "world" ~ 47 ~ endl ~ "bar" ~ format("%06i\n", 62);

 -- andy

November 06, 2003
Charles Sanders wrote:

> But what would endl be defined as, an arbitrary number ?  How would it know
> i didnt actually want to output that specific number ?
> 
> C

A typedeffed value.  Or some sort of unique mutator object.

 -- andy

« First   ‹ Prev
1 2 3 4 5 6 7 8