comp.lang.ada
 help / color / mirror / Atom feed
* ToString?
@ 2002-03-12 13:16 Nazgul
  2002-03-12 13:24 ` ToString? Peter Hermann
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Nazgul @ 2002-03-12 13:16 UTC (permalink / raw)


Is there something like Integer'ToString(xxx) that converts an integer to a
string ?

Thanks.







^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-12 13:16 ToString? Nazgul
@ 2002-03-12 13:24 ` Peter Hermann
  2002-03-12 13:25 ` ToString? Ingo Marks
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 19+ messages in thread
From: Peter Hermann @ 2002-03-12 13:24 UTC (permalink / raw)


Nazgul <darkelf@aim.homelinux.com> wrote:
> Is there something like Integer'ToString(xxx) that converts an integer to a
> string ?
                       with ada.text_io;
                        use ada.text_io;
procedure imagevalue is

  i : integer;
  f : float;

begin null;

  ada.text_io.put_line("starting test program imagevalue");
  i := integer'value("4711");
  f :=   float'value("47.1");

  ada.text_io.put_line(integer'image(i));
  ada.text_io.put_line(  float'image(f));
  
end imagevalue;

-- 
--Peter Hermann(49)0711-685-3611 fax3758 ica2ph@csv.ica.uni-stuttgart.de
--Pfaffenwaldring 27 Raum 114, D-70569 Stuttgart Uni Computeranwendungen
--http://www.csv.ica.uni-stuttgart.de/homes/ph/
--Team Ada: "C'mon people let the world begin" (Paul McCartney)



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-12 13:16 ToString? Nazgul
  2002-03-12 13:24 ` ToString? Peter Hermann
@ 2002-03-12 13:25 ` Ingo Marks
  2002-03-12 13:27 ` ToString? Larry Hazel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 19+ messages in thread
From: Ingo Marks @ 2002-03-12 13:25 UTC (permalink / raw)


Nazgul wrote:

> Is there something like Integer'ToString(xxx) that converts an integer to
> a string ?
> 
> Thanks.

Integer to String: Integer'Image(xxx)
String to Integer: Integer'Value(yyy)




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-12 13:16 ToString? Nazgul
  2002-03-12 13:24 ` ToString? Peter Hermann
  2002-03-12 13:25 ` ToString? Ingo Marks
@ 2002-03-12 13:27 ` Larry Hazel
  2002-03-12 13:30 ` ToString? Martin Dowie
  2002-03-15  4:58 ` Upping the ante (was): ToString? Kent Paul Dolan
  4 siblings, 0 replies; 19+ messages in thread
From: Larry Hazel @ 2002-03-12 13:27 UTC (permalink / raw)


Nazgul wrote:
> 
> Is there something like Integer'ToString(xxx) that converts an integer to a
> string ?
> 
> Thanks.

Integer'Image(xxx)

Larry



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-12 13:16 ToString? Nazgul
                   ` (2 preceding siblings ...)
  2002-03-12 13:27 ` ToString? Larry Hazel
@ 2002-03-12 13:30 ` Martin Dowie
  2002-03-12 16:48   ` ToString? Jeffrey Carter
  2002-03-15  4:58 ` Upping the ante (was): ToString? Kent Paul Dolan
  4 siblings, 1 reply; 19+ messages in thread
From: Martin Dowie @ 2002-03-12 13:30 UTC (permalink / raw)



"Nazgul" <darkelf@aim.homelinux.com> wrote in message
news:a6kv3e$faat1$1@ID-107015.news.dfncis.de...
> Is there something like Integer'ToString(xxx) that converts an integer to
a
> string ?

try 'Image as in:

declare
   My_Integer : Integer := 10;
begin
   Put_Line (Integer'Image (My_Integer));
end;

The string will have a ' ' character at the front if positive.

To get more control about formatting check out package
Ada.Text_IO.Integer_IO (and Ada.Text_IO.Float_IO etc).





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-12 13:30 ` ToString? Martin Dowie
@ 2002-03-12 16:48   ` Jeffrey Carter
  2002-03-13  8:38     ` ToString? Martin Dowie
  0 siblings, 1 reply; 19+ messages in thread
From: Jeffrey Carter @ 2002-03-12 16:48 UTC (permalink / raw)


Martin Dowie wrote:
> 
> try 'Image as in:
> 
> declare
>    My_Integer : Integer := 10;
> begin
>    Put_Line (Integer'Image (My_Integer));
> end;
> 
> The string will have a ' ' character at the front if positive.

More accurately, the string will have a leading space if the value is
not negative.

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-12 16:48   ` ToString? Jeffrey Carter
@ 2002-03-13  8:38     ` Martin Dowie
  2002-03-13 22:18       ` ToString? Jeffrey Carter
  0 siblings, 1 reply; 19+ messages in thread
From: Martin Dowie @ 2002-03-13  8:38 UTC (permalink / raw)


> > The string will have a ' ' character at the front if positive.
>
> More accurately, the string will have a leading space if the value is
> not negative.

Ah, the '0' isn't a positive number thang!





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-13  8:38     ` ToString? Martin Dowie
@ 2002-03-13 22:18       ` Jeffrey Carter
  2002-03-14  0:36         ` ToString? Adrian Knoth
  0 siblings, 1 reply; 19+ messages in thread
From: Jeffrey Carter @ 2002-03-13 22:18 UTC (permalink / raw)


Martin Dowie wrote:
> 
> > > The string will have a ' ' character at the front if positive.
> >
> > More accurately, the string will have a leading space if the value is
> > not negative.
> 
> Ah, the '0' isn't a positive number thang!

It's easy enough to test:

with Ada.Text_IO;
use Ada.Text_IO
procedure Is_Zero_Positive is
   Zero : constant := 0;
begin -- Is_Zero_Positive
   if Zero in Positive then
      Put_Line ("Zero is Positive");
   else
      Put_Line ("Zero is not Positive");
   end if;
end Is_Zero_Positive;

This puts "Zero is not Positive" to the standard output. QED.

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-13 22:18       ` ToString? Jeffrey Carter
@ 2002-03-14  0:36         ` Adrian Knoth
  0 siblings, 0 replies; 19+ messages in thread
From: Adrian Knoth @ 2002-03-14  0:36 UTC (permalink / raw)


Jeffrey Carter <jeffrey.carter@boeing.com> wrote:

>> Ah, the '0' isn't a positive number thang!
> This puts "Zero is not Positive" to the standard output. QED.

That's why the church was against zero: "Zero is devil's stuff. In front
of a digit it minimizes its value by a factor of 10, behind any number
it multiplies by 10."

Of course, "10" has to be rewritten as 'X' :)

-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Treffen sich zwei Hellseher: "Dir gehts gut und wie gehts mir?"



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
@ 2002-03-14  6:05 Christoph Grein
  2002-03-14 16:18 ` ToString? Jeffrey Carter
  0 siblings, 1 reply; 19+ messages in thread
From: Christoph Grein @ 2002-03-14  6:05 UTC (permalink / raw)


From: Jeffrey Carter <jeffrey.carter@boeing.com>

> > Ah, the '0' isn't a positive number thang!
>
> It's easy enough to test:
> 
> with Ada.Text_IO;
> use Ada.Text_IO
> procedure Is_Zero_Positive is
>    Zero : constant := 0;
> begin -- Is_Zero_Positive
>    if Zero in Positive then
>       Put_Line ("Zero is Positive");
>    else
>       Put_Line ("Zero is not Positive");
>    end if;
> end Is_Zero_Positive;
> 
> This puts "Zero is not Positive" to the standard output. QED.

You mean a test or a mathematical proof? For a test, this is OK.

For a proof, you have to prove first that Positive holds only
positive numbers :-)

Perhaps you also have to prove that the symbol 0 you use up there is really a 
representation of what you have in mind when speaking about the mathematical 
object called 0 :-)



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-14  6:05 ToString? Christoph Grein
@ 2002-03-14 16:18 ` Jeffrey Carter
  2002-03-15 14:18   ` ToString? Ted Dennison
  0 siblings, 1 reply; 19+ messages in thread
From: Jeffrey Carter @ 2002-03-14 16:18 UTC (permalink / raw)


Christoph Grein wrote:
> 
> From: Jeffrey Carter <jeffrey.carter@boeing.com>
> 
> > > Ah, the '0' isn't a positive number thang!
> >
> > It's easy enough to test:
> >
> > with Ada.Text_IO;
> > use Ada.Text_IO
> > procedure Is_Zero_Positive is
> >    Zero : constant := 0;
> > begin -- Is_Zero_Positive
> >    if Zero in Positive then
> >       Put_Line ("Zero is Positive");
> >    else
> >       Put_Line ("Zero is not Positive");
> >    end if;
> > end Is_Zero_Positive;
> >
> > This puts "Zero is not Positive" to the standard output. QED.
> 
> You mean a test or a mathematical proof? For a test, this is OK.

I said "test". You are perhaps confused by my use of "QED", which of
course is TED's brother.

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Upping the ante (was): ToString?
  2002-03-12 13:16 ToString? Nazgul
                   ` (3 preceding siblings ...)
  2002-03-12 13:30 ` ToString? Martin Dowie
@ 2002-03-15  4:58 ` Kent Paul Dolan
  2002-03-15  5:22   ` Jim Rogers
  4 siblings, 1 reply; 19+ messages in thread
From: Kent Paul Dolan @ 2002-03-15  4:58 UTC (permalink / raw)


"Nazgul" <darkelf@aim.homelinux.com> wrote in message
news:a6kv3e$faat1$1@ID-107015.news.dfncis.de...

> Is there something like Integer'ToString(xxx) that converts an integer to a
> string ?

More important, is there something like toString(), with the implied
contract that _every_ object will support a parameterless call to it and
do something sensible to return a string representation of the object
usable for debugging, logging, or "not too fancy" data presentation?

To a newbie(*) Java programmer (me) this is one of the more delightful
discoveries about the language.

xanthian.

As an old timer computer language junkie, it is one of the more
delightful discoveries about _any_ language that it supports features
that are usable anywhere and always do what you want without you having
to think very hard about them.  "Good programmers are lazy programmers"
does not usefully imply that "lazy programmers are good programmers" but
the trend is sure in that direction.

*[See http://www.well.com/user/xanthian/java/TravellerDoc.html for
"pretty much everything I know about Java so far. plus a lot I swiped
without understanding it very well", in source code form.  You might
find something worth stealing.]

And actually, it is harder to spell what was requested in Java,
something like

  String result = ( new Integer( someIntValue ) ).toString();

since "Integer"s are first class objects, but "int"s, the usual
counting numbers, are not, one of Java's multitude of
maddening flaws.

[Don't get me started.]


-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Upping the ante (was): ToString?
  2002-03-15  4:58 ` Upping the ante (was): ToString? Kent Paul Dolan
@ 2002-03-15  5:22   ` Jim Rogers
  2002-04-04 23:21     ` Kent Paul Dolan
  0 siblings, 1 reply; 19+ messages in thread
From: Jim Rogers @ 2002-03-15  5:22 UTC (permalink / raw)


Kent Paul Dolan wrote:

> "Nazgul" <darkelf@aim.homelinux.com> wrote in message
> news:a6kv3e$faat1$1@ID-107015.news.dfncis.de...
> 
> 
>>Is there something like Integer'ToString(xxx) that converts an integer to a
>>string ?
>>
> 
> More important, is there something like toString(), with the implied
> contract that _every_ object will support a parameterless call to it and
> do something sensible to return a string representation of the object
> usable for debugging, logging, or "not too fancy" data presentation?
> 


Unfortunately, there is no such implied contract in Java.
Every object (non-primitive type) will have a toString() method.
It may not do anything sensible. If you define your own class
and do NOT override the toString() inherited from the Object
class your output will only be the class name followed by the
output of the hashCode() method for your class.

Jim Rogers




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: ToString?
  2002-03-14 16:18 ` ToString? Jeffrey Carter
@ 2002-03-15 14:18   ` Ted Dennison
  0 siblings, 0 replies; 19+ messages in thread
From: Ted Dennison @ 2002-03-15 14:18 UTC (permalink / raw)


Jeffrey Carter <jeffrey.carter@boeing.com> wrote in message news:<3C90CD5A.438EE1DA@boeing.com>...
> I said "test". You are perhaps confused by my use of "QED", which of
> course is TED's brother.

:-)

Actually, I have no brother. However, my wife is JED, and my kids are
PED and KED. :-)


-- 
T.E.D. 
Home     -  mailto:dennison@telepath.com (Yahoo: Ted_Dennison)
Homepage -  http://www.telepath.com/dennison/Ted/TED.html



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Upping the ante (was): ToString?
  2002-03-15  5:22   ` Jim Rogers
@ 2002-04-04 23:21     ` Kent Paul Dolan
  2002-04-05  5:09       ` Eric G. Miller
  0 siblings, 1 reply; 19+ messages in thread
From: Kent Paul Dolan @ 2002-04-04 23:21 UTC (permalink / raw)


"Jim Rogers" <jimmaureenrogers@worldnet.att.net> wrote:

> Unfortunately, there is no such implied contract in Java.

> Every object (non-primitive type) will have a toString() method.
> It may not do anything sensible. If you define your own class
> and do NOT override the toString() inherited from the Object
> class your output will only be the class name followed by the
> output of the hashCode() method for your class.

But the java SDK API docs recommend exactly that for every class, you
override this behavior inherited from Object, wherever some other
toString() implementation makes more sense for your object, which is why
I consider this to be an implied contract.  If you don't keep the
contract, and go with the default, you deserve the results, it seems to
me.

In any case, such universal meta-programming rules would seem useful for
Ada, beyond just the idea of a style guide.  Do such exist?  Does a
repository of them exist?

xanthian.




-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Upping the ante (was): ToString?
  2002-04-04 23:21     ` Kent Paul Dolan
@ 2002-04-05  5:09       ` Eric G. Miller
  2002-04-05 19:45         ` Kent Paul Dolan
  0 siblings, 1 reply; 19+ messages in thread
From: Eric G. Miller @ 2002-04-05  5:09 UTC (permalink / raw)


In <6e9cd02332705638a4cd86a4a2f521e7.48257@mygate.mailgate.org>, Kent Paul Dolan wrote:

> "Jim Rogers" <jimmaureenrogers@worldnet.att.net> wrote:
> 
>> Unfortunately, there is no such implied contract in Java.
> 
>> Every object (non-primitive type) will have a toString() method.
>> It may not do anything sensible. If you define your own class
>> and do NOT override the toString() inherited from the Object
>> class your output will only be the class name followed by the
>> output of the hashCode() method for your class.
> 
> But the java SDK API docs recommend exactly that for every class, you
> override this behavior inherited from Object, wherever some other
> toString() implementation makes more sense for your object, which is why
> I consider this to be an implied contract.  If you don't keep the
> contract, and go with the default, you deserve the results, it seems to
> me.
> 
> In any case, such universal meta-programming rules would seem useful for
> Ada, beyond just the idea of a style guide.  Do such exist?  Does a
> repository of them exist?

Implied contracts don't hold up in court.  Especially when they only
make recommendations...

Q. "Why didn't you follow your neighbor's recommendation to mow the lawn?"
A. "I like dandelions."

Recommendation:  You should not park junk cars in your front yard.
Result: Neighborhood full of junk cars parked in the front yard.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Upping the ante (was): ToString?
  2002-04-05  5:09       ` Eric G. Miller
@ 2002-04-05 19:45         ` Kent Paul Dolan
  2002-04-06  4:07           ` Eric G. Miller
  0 siblings, 1 reply; 19+ messages in thread
From: Kent Paul Dolan @ 2002-04-05 19:45 UTC (permalink / raw)


"Eric G. Miller" <egm2@jps-nospam.net> wrote:

> Kent Paul Dolan wrote:

> > But the java SDK API docs recommend exactly that for every class, you
> > override this behavior inherited from Object, wherever some other
> > toString() implementation makes more sense for your object, which is why
> > I consider this to be an implied contract.  If you don't keep the
> > contract, and go with the default, you deserve the results, it seems to
> > me.

> Implied contracts don't hold up in court.  Especially when they only
> make recommendations...

An interesting, (and cynical) view, but since the first beneficiary of
overriding *.toString()
is always the programmer himself or herself (toString() is an essential
debugging tool),
this isn't quite the same as the instances you cite.

xanthian.


-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Upping the ante (was): ToString?
  2002-04-05 19:45         ` Kent Paul Dolan
@ 2002-04-06  4:07           ` Eric G. Miller
  2002-04-06 22:23             ` Implied Programming contracts: " Kent Paul Dolan
  0 siblings, 1 reply; 19+ messages in thread
From: Eric G. Miller @ 2002-04-06  4:07 UTC (permalink / raw)


In <5e081eac7f7a97a4b8c0fa173d366970.48257@mygate.mailgate.org>, Kent Paul Dolan wrote:

> "Eric G. Miller" <egm2@jps-nospam.net> wrote:
> 
>> Kent Paul Dolan wrote:
> 
>> > But the java SDK API docs recommend exactly that for every class, you
>> > override this behavior inherited from Object, wherever some other
>> > toString() implementation makes more sense for your object, which is why
>> > I consider this to be an implied contract.  If you don't keep the
>> > contract, and go with the default, you deserve the results, it seems to
>> > me.
> 
>> Implied contracts don't hold up in court.  Especially when they only
>> make recommendations...
> 
> An interesting, (and cynical) view, but since the first beneficiary of
> overriding *.toString()
> is always the programmer himself or herself (toString() is an essential
> debugging tool),
> this isn't quite the same as the instances you cite.

Well, if enlightened self interest will motivate java programmers to define
a toString() method, that's fine.  Basically, the point I was making was,
you still won't be able to rely on others always implementing a toString()
method.  That's the nature of recommendations; they can be ignored.

I'm not sure this is even topical in this newgroup.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Implied Programming contracts: Upping the ante (was): ToString?
  2002-04-06  4:07           ` Eric G. Miller
@ 2002-04-06 22:23             ` Kent Paul Dolan
  0 siblings, 0 replies; 19+ messages in thread
From: Kent Paul Dolan @ 2002-04-06 22:23 UTC (permalink / raw)


"Eric G. Miller" <egm2@jps-nospam.net> wrote:

> I'm not sure this is even topical in this newgroup.


Well, sure it is.  The question of whether a programming language has,
or needs, implied contracts (or explicit ones, like Eiffel's) is always
on topic if the discussion is eventually hauled back from "but look how
much better language Y does it" to some positive proposals for language
X.

xanthian.


-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2002-04-06 22:23 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-12 13:16 ToString? Nazgul
2002-03-12 13:24 ` ToString? Peter Hermann
2002-03-12 13:25 ` ToString? Ingo Marks
2002-03-12 13:27 ` ToString? Larry Hazel
2002-03-12 13:30 ` ToString? Martin Dowie
2002-03-12 16:48   ` ToString? Jeffrey Carter
2002-03-13  8:38     ` ToString? Martin Dowie
2002-03-13 22:18       ` ToString? Jeffrey Carter
2002-03-14  0:36         ` ToString? Adrian Knoth
2002-03-15  4:58 ` Upping the ante (was): ToString? Kent Paul Dolan
2002-03-15  5:22   ` Jim Rogers
2002-04-04 23:21     ` Kent Paul Dolan
2002-04-05  5:09       ` Eric G. Miller
2002-04-05 19:45         ` Kent Paul Dolan
2002-04-06  4:07           ` Eric G. Miller
2002-04-06 22:23             ` Implied Programming contracts: " Kent Paul Dolan
  -- strict thread matches above, loose matches on Subject: below --
2002-03-14  6:05 ToString? Christoph Grein
2002-03-14 16:18 ` ToString? Jeffrey Carter
2002-03-15 14:18   ` ToString? Ted Dennison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox