D - puts(), toString method for primitives?
- Jonathan Andrew (18/18) Feb 19 2003 Hello everyone,
- Walter (13/30) Mar 01 2003 be
- Marcelo Fontenele S Santos (23/31) Mar 11 2003 In Ruby there is a way of extending an existing class or maybe even a
- Bill Cox (5/47) Mar 12 2003 There are no plans I'm aware of. However, I'd be for it, and I'm a very...
Hello everyone, I noticed that to use puts() in D, the input had to be a null-terminated C string, requiring toStringz(). I'm guessing that a full D version will be present as phobos matures. I think puts (or the D equivalent) could replace printf altogether and make D a lot easier for newbies like myself if primitive types had a built in toString method, so to print out strings you could just call puts(mystring ~ someint.toString ~ somefloat.toString ...etc.), instead of messing around with printf and worrying about %*.s and all that. The toString() function in phobos is only implemented for a few types right now, unless I am missing something, so even if a D puts() was made part of the standard library, it would still depend on itoa-like functions (which are frustratingly never around!). Just a bit of nitpicking I suppose. Also, is there a way to define new "pseudo-methods" for primitive types? That way if nobody else wanted a .toString method for floats or whatever I could always just define it for my own code. I tried looking in the spec, but couldn't find any mention of it. Thanks, Jon
Feb 19 2003
"Jonathan Andrew" <Jonathan_member pathlink.com> wrote in message news:b31rlh$1fpv$1 digitaldaemon.com...Hello everyone, I noticed that to use puts() in D, the input had to be a null-terminated C string, requiring toStringz(). I'm guessing that a full D version willbepresent as phobos matures. I think puts (or the D equivalent) couldreplaceprintf altogether and make D a lot easier for newbies like myself ifprimitivetypes had a built in toString method, so to print out strings you couldjustcall puts(mystring ~ someint.toString ~ somefloat.toString ...etc.),instead ofmessing around with printf and worrying about %*.s and all that. The toString() function in phobos is only implemented for a few types rightnow,unless I am missing something, so even if a D puts() was made part of the standard library, it would still depend on itoa-like functions (which are frustratingly never around!). Just a bit of nitpicking I suppose.You're right, that needs to be done.Also, is there a way to define new "pseudo-methods" for primitive types? That way ifnobodyelse wanted a .toString method for floats or whatever I could always justdefineit for my own code. I tried looking in the spec, but couldn't find anymentionof it.No, there isn't a way to do that.
Mar 01 2003
Walter wrote:"Jonathan Andrew" <Jonathan_member pathlink.com> wrote in message news:b31rlh$1fpv$1 digitaldaemon.com...In Ruby there is a way of extending an existing class or maybe even a primitive type but I'm not sure. I think you can have multiple declarations for a class and then ruby will add the methods into the class interface. class SomeClass def someMethod end end anObject = SomeClass.new anObject.someMethod class SomeClass def anotherMethod end end anotherObject = SomeClass.new anotherObject.someMethod anotherObject.anotherMethod Are there any plans for something like it? -- Marcelo Fontenele S Santos <msantos pobox.com>Also, is there a way to define new "pseudo-methods" for primitive types? That way if nobody else wanted a .toString method for floats or whatever I could always just defineit for my own code. I tried looking in the spec, but couldn't find any mention of it.No, there isn't a way to do that.
Mar 11 2003
Marcelo Fontenele S Santos wrote:Walter wrote:There are no plans I'm aware of. However, I'd be for it, and I'm a very much a minimalist. However, I'd want any class extensions to be done at compile time. D isn't a good language for run-time dynamic stuff. Bill"Jonathan Andrew" <Jonathan_member pathlink.com> wrote in message news:b31rlh$1fpv$1 digitaldaemon.com...>> That way if nobody else wanted a .toString method for floats or >> whatever I could always just defineit for my own code. >> I tried looking in the spec, but couldn't find any mention of it.Also, is there a way to define new "pseudo-methods" for primitive types?No, there isn't a way to do that.In Ruby there is a way of extending an existing class or maybe even a primitive type but I'm not sure. I think you can have multiple declarations for a class and then ruby will add the methods into the class interface. class SomeClass def someMethod end end anObject = SomeClass.new anObject.someMethod class SomeClass def anotherMethod end end anotherObject = SomeClass.new anotherObject.someMethod anotherObject.anotherMethod Are there any plans for something like it?
Mar 12 2003