comp.lang.ada
 help / color / mirror / Atom feed
* Type Conversion
@ 1997-12-08  0:00 Nick Davies
  1997-12-08  0:00 ` John English
  1997-12-09  0:00 ` Stephen Leake
  0 siblings, 2 replies; 30+ messages in thread
From: Nick Davies @ 1997-12-08  0:00 UTC (permalink / raw)




	Hi guys,
	
		Can you help? I'm trying to do this

Token_Temp := Token_Temp & String(Current_Character); --Type Conversion
needed

	Using:-

	      Token_Temp : String (1..20) := (others => ' '); 
              Current_Character : Character;

	and I keep getting the error message:-

		scanner_main.adb:64:44: illegal operand for array conversion
		gnatmake: "scanner_main.adb" compilation error

		Thanks in advance,

			Nick

    ************************************
                Nick Davies
             2nd Year Comp.Sci
	
      e-mail : ndavies@comp.brad.ac.uk
    ************************************





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

* Re: Type Conversion
  1997-12-08  0:00 Nick Davies
@ 1997-12-08  0:00 ` John English
  1997-12-09  0:00 ` Stephen Leake
  1 sibling, 0 replies; 30+ messages in thread
From: John English @ 1997-12-08  0:00 UTC (permalink / raw)



Nick Davies (ndavies@comp.brad.ac.uk) wrote:
: 		Can you help? I'm trying to do this

: Token_Temp := Token_Temp & String(Current_Character); --Type Conversion
: needed

: 	Using:-

: 	      Token_Temp : String (1..20) := (others => ' '); 
:               Current_Character : Character;

The type conversion *shouldn't* be needed -- but what you're trying
to do in the code above is to assign a 21-character string (20 chars
in Token_Temp + 1 more char in Current_Character) to a 20-character
string (Token_Temp).  This *definitely* won't work.

I don't know what you're trying to achieve, but it might be worth
looking into the standard packages Ada.Strings.Bounded (RM95[A.4.4])
or possibly Ada.Strings.Unbounded (RM95[A.4.5]), since there are
facilities there to deal with variable-length strings.

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.comp.it.bton.ac.uk/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: Type Conversion
  1997-12-08  0:00 Nick Davies
  1997-12-08  0:00 ` John English
@ 1997-12-09  0:00 ` Stephen Leake
  1 sibling, 0 replies; 30+ messages in thread
From: Stephen Leake @ 1997-12-09  0:00 UTC (permalink / raw)



Nick Davies wrote:
> 
>         Hi guys,
> 
>                 Can you help? I'm trying to do this
> 
> Token_Temp := Token_Temp & String(Current_Character); --Type Conversion
> needed

Actually, no type conversion is needed. The '&' operator comes in
several flavors; one of them concatenates array elements onto arrays.
This will almost work:

Token_Temp := Token_Temp & Current_Character;

It still doesn't work because Token_Temp is a fixed length string, and
you are trying to make it bigger. Since this seems to be homework, I'll
direct you to your prof/TA for more help. 
 
>         Using:-
> 
>               Token_Temp : String (1..20) := (others => ' ');
>               Current_Character : Character;
>                 Thanks in advance,

No problem, but please consult your local resources first, or let us
know that they have failed.
> 
>                         Nick
> 
>     ************************************
>                 Nick Davies
>              2nd Year Comp.Sci
> 
>       e-mail : ndavies@comp.brad.ac.uk
>     ************************************

-- 
- Stephe




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

* Type Conversion
@ 1998-11-01  0:00 Heather Wright
  1998-11-01  0:00 ` dewarr
                   ` (3 more replies)
  0 siblings, 4 replies; 30+ messages in thread
From: Heather Wright @ 1998-11-01  0:00 UTC (permalink / raw)


Probably a really lame question, but what is the syntax for type conversion
in Ada?

I'm trying to convert a float to an int (or vice-versa if necessary), the
help files are doing
me no good and the closest thing I found online was a comparison between
type conversion and
qualifier.

Yeah, I'm a complete Newbie at Ada.

Thanks very much for any help,

Heather






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

* Re: Type Conversion
  1998-11-01  0:00 Type Conversion Heather Wright
@ 1998-11-01  0:00 ` dewarr
  1998-11-01  0:00 ` Tucker Taft
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 30+ messages in thread
From: dewarr @ 1998-11-01  0:00 UTC (permalink / raw)


In article <71g71d$r7d@news3.force9.net>,
  "Heather Wright" <daglitch@dapad_nojunk_.co.uk> wrote:
> Probably a really lame question, but what is the syntax for type conversion
> in Ada?
>
> I'm trying to convert a float to an int (or vice-versa if necessary), the
> help files are doing
> me no good and the closest thing I found online was a comparison between
> type conversion and
> qualifier.
>
> Yeah, I'm a complete Newbie at Ada.
>
> Thanks very much for any help,


You should definitely be able to answer simple syntax questions like this
for yourself. The RM is complex to read, but the *syntax* sections should
be perfectly straightforward, and if you don't understand the BNF notation
that is used there, make the effort to learn and understand it (understanding
BNF is an absolutely essential piece of knowledge for any programmer). THe
relevant syntax rules can be found in Annex P, where they are gathered
together, or you can trivially find the right section in the RM with a
simple search (or using the index!):

4.6 Type Conversions

1   Explicit type conversions, both value conversions and view conversions,
are allowed between closely related types as defined below.  This clause also
defines rules for value and view conversions to a particular subtype of a
type, both explicit ones and those implicit in other constructs.

                                   Syntax

2   type_conversion ::=
        subtype_mark(expression)
      | subtype_mark(name)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Type Conversion
  1998-11-01  0:00 Type Conversion Heather Wright
  1998-11-01  0:00 ` dewarr
@ 1998-11-01  0:00 ` Tucker Taft
  1998-11-02  0:00 ` Marin David Condic
  1998-11-02  0:00 ` Michael Kaufman
  3 siblings, 0 replies; 30+ messages in thread
From: Tucker Taft @ 1998-11-01  0:00 UTC (permalink / raw)


Heather Wright (daglitch@dapad_nojunk_.co.uk) wrote:

: Probably a really lame question, but what is the syntax for type conversion
: in Ada?

A type conversion looks like a function call, with the function name
being the target (sub)type name.  For example, to convert to Long_Float:

   Z := Long_Float(I);

To convert back to some Integer subtype, like Natural:

   I := Natural(Z);

: I'm trying to convert a float to an int (or vice-versa if necessary), the
: help files are doing
: me no good and the closest thing I found online was a comparison between
: type conversion and
: qualifier.

: Yeah, I'm a complete Newbie at Ada.

Not a problem.  

: Thanks very much for any help,

: Heather

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company




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

* Re: Type Conversion
  1998-11-01  0:00 Type Conversion Heather Wright
                   ` (2 preceding siblings ...)
  1998-11-02  0:00 ` Marin David Condic
@ 1998-11-02  0:00 ` Michael Kaufman
  1998-11-03  0:00   ` Arun Mangalam
  3 siblings, 1 reply; 30+ messages in thread
From: Michael Kaufman @ 1998-11-02  0:00 UTC (permalink / raw)


Hi,

In general type conversions look much like function calls, where the
destination type is the "function".  For example:

  procedure A_Test is

    A_Integer : Integer := 10;
    A_Float    : Float := 10.0;

  begin

    A_Integer := Integer(A_Float);  -- Converts the float to an integer.
    A_Float := Float(A_Integer);     -- Converts the integer to a float.

  end A_Test;

Note that the cast from float to integer will round.

Hope this helps,

Mike




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

* Re: Type Conversion
  1998-11-01  0:00 Type Conversion Heather Wright
  1998-11-01  0:00 ` dewarr
  1998-11-01  0:00 ` Tucker Taft
@ 1998-11-02  0:00 ` Marin David Condic
  1998-11-02  0:00 ` Michael Kaufman
  3 siblings, 0 replies; 30+ messages in thread
From: Marin David Condic @ 1998-11-02  0:00 UTC (permalink / raw)
  To: Heather Wright

See section 4.6 of the Ada Reference Manual for the full details - there are
implications with things like rounding, etc. that you may need to understand.
Basically, it looks like a function call with the type name as the name of the
function. As in:

declare
    X : Integer ;
    Y : Float := 1.234 ;
begin
    X := Float (Y) ;
end ;

Good luck.

MDC

Heather Wright wrote:

> Probably a really lame question, but what is the syntax for type conversion
> in Ada?
>
> I'm trying to convert a float to an int (or vice-versa if necessary), the
> help files are doing
> me no good and the closest thing I found online was a comparison between
> type conversion and
> qualifier.
>
> Yeah, I'm a complete Newbie at Ada.
>
> Thanks very much for any help,
>
> Heather

--
Marin David Condic
===========================================================
    "A government that is big enough to give you all you want is big
    enough to take it all away."

        --  Barry Goldwater
===========================================================






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

* Re: Type Conversion
  1998-11-02  0:00 ` Michael Kaufman
@ 1998-11-03  0:00   ` Arun Mangalam
  1998-11-06  0:00     ` Niklas Holsti
  0 siblings, 1 reply; 30+ messages in thread
From: Arun Mangalam @ 1998-11-03  0:00 UTC (permalink / raw)


In article <71lbsu$1ps@morgan.vf.lmco.com>, Michael Kaufman
<michael.f.kaufman@lmco.com> wrote:

>Hi,
>
>In general type conversions look much like function calls, where the
>destination type is the "function".  For example:
>
>  procedure A_Test is
>
>    A_Integer : Integer := 10;
>    A_Float    : Float := 10.0;
>
>  begin
>
>    A_Integer := Integer(A_Float);  -- Converts the float to an integer.
>    A_Float := Float(A_Integer);     -- Converts the integer to a float.
>
>  end A_Test;
>
>Note that the cast from float to integer will round.
>

So, if A_Float contains the number 10.5 initially, A_Integer will equal
11? I am asking because with my C background I would have thought
A_Integer would equal 10, because in C the fractions are truncated out.

-- 
asmang@CRAZYSPAMmail.wm.edu
remove the CRAZYSPAM to reply.
These spamming buggers are really annoying.




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

* Re: Type Conversion
  1998-11-03  0:00   ` Arun Mangalam
@ 1998-11-06  0:00     ` Niklas Holsti
  0 siblings, 0 replies; 30+ messages in thread
From: Niklas Holsti @ 1998-11-06  0:00 UTC (permalink / raw)


Arun Mangalam wrote:
> 
> In article <71lbsu$1ps@morgan.vf.lmco.com>, Michael Kaufman
> <michael.f.kaufman@lmco.com> wrote:
> >
> >Note that the cast from float to integer will round.
> >
> 
> So, if A_Float contains the number 10.5 initially, A_Integer will equal
> 11? I am asking because with my C background I would have thought
> A_Integer would equal 10, because in C the fractions are truncated out.

Yep, Integer(10.5) = 11, because rounding a value that is exactly
half-way
between two integers is defined to round away from zero.

If you want to truncate, use Float'Truncation(10.5). Similar functions
for 'Floor and 'Ceiling and so on are also available.




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

* type conversion
@ 2014-10-11 23:56 compguy45
  2014-10-12  0:07 ` compguy45
                   ` (3 more replies)
  0 siblings, 4 replies; 30+ messages in thread
From: compguy45 @ 2014-10-11 23:56 UTC (permalink / raw)


I have function...

myFunction that given string returns array of integers....lets call that array a

I have another function myOtherFunction that takes string as parameter....just for simplicity i am trying to do following....

myFunction(Integer'Image(a(1)));  -- compiler error

I tried also myFunction(Integer'Value(a(1))); -- error again

I know in other languages you could do var $d = String($someInt);

Obviously Ada can do same but online I was able to find only 2 solutions above but none worked.


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

* Re: type conversion
  2014-10-11 23:56 type conversion compguy45
@ 2014-10-12  0:07 ` compguy45
  2014-10-12  0:25   ` compguy45
  2014-10-12  0:33 ` Jeffrey Carter
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 30+ messages in thread
From: compguy45 @ 2014-10-12  0:07 UTC (permalink / raw)


when i try this myFunction("345"); everything works no problem...

i try this   myFunction(Integer'Image(a(1)));  -- program keeps to be hanging but compiles with no error.

 


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

* Re: type conversion
  2014-10-12  0:07 ` compguy45
@ 2014-10-12  0:25   ` compguy45
  0 siblings, 0 replies; 30+ messages in thread
From: compguy45 @ 2014-10-12  0:25 UTC (permalink / raw)


apparently there is space added to newly created string when Integer'Image is used...

so i also tried....myFunction(Ada.Strings.Fixed.Trim(a(1), Ada.Strings.Left));

unfortunately that didnt work either...



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

* Re: type conversion
  2014-10-11 23:56 type conversion compguy45
  2014-10-12  0:07 ` compguy45
@ 2014-10-12  0:33 ` Jeffrey Carter
  2014-10-12  0:38   ` compguy45
  2014-10-12  2:32 ` Shark8
  2014-10-12  9:31 ` Simon Wright
  3 siblings, 1 reply; 30+ messages in thread
From: Jeffrey Carter @ 2014-10-12  0:33 UTC (permalink / raw)


On 10/11/2014 04:56 PM, compguy45@gmail.com wrote:
> I have function...
> 
> myFunction that given string returns array of integers....lets call that array a
> 
> I have another function myOtherFunction that takes string as parameter....just for simplicity i am trying to do following....

Myotherfunction seems totally irrelevant to the problem.

> myFunction(Integer'Image(a(1)));  -- compiler error

Have you considered that knowing the error msg might help us help you?

-- 
Jeff Carter
"I fart in your general direction."
Monty Python & the Holy Grail
05


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

* Re: type conversion
  2014-10-12  0:33 ` Jeffrey Carter
@ 2014-10-12  0:38   ` compguy45
  2014-10-12  3:45     ` Jeffrey Carter
  0 siblings, 1 reply; 30+ messages in thread
From: compguy45 @ 2014-10-12  0:38 UTC (permalink / raw)


 myFunction(Integer'Value(a(1)));

gives compiler error 

expected type "Standard.String"
found type "Standard.Integer"
 compilation error

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

* Re: type conversion
  2014-10-11 23:56 type conversion compguy45
  2014-10-12  0:07 ` compguy45
  2014-10-12  0:33 ` Jeffrey Carter
@ 2014-10-12  2:32 ` Shark8
  2014-10-12  4:53   ` Anh Vo
  2014-10-12  9:16   ` Simon Wright
  2014-10-12  9:31 ` Simon Wright
  3 siblings, 2 replies; 30+ messages in thread
From: Shark8 @ 2014-10-12  2:32 UTC (permalink / raw)


Well, let's make some subtypes!

  Subtype Integer_String is
   with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer
                             or else raise Constraint_Error;


Function As_Integer(S : Integer_String) Return Integer is
  (Integer'Value(S));

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

* Re: type conversion
  2014-10-12  0:38   ` compguy45
@ 2014-10-12  3:45     ` Jeffrey Carter
  0 siblings, 0 replies; 30+ messages in thread
From: Jeffrey Carter @ 2014-10-12  3:45 UTC (permalink / raw)


On 10/11/2014 05:38 PM, compguy45@gmail.com wrote:
>  myFunction(Integer'Value(a(1)));
> 
> gives compiler error 
> 
> expected type "Standard.String"
> found type "Standard.Integer"
>  compilation error

That at least confirms that A (1) is of type Integer. Integer'Value obviously
won't work here since it takes a String, as the error msg indicates. I was
interested in the error msg for the case that looks correct, using Integer'Image.

-- 
Jeff Carter
"I fart in your general direction."
Monty Python & the Holy Grail
05


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

* Re: type conversion
  2014-10-12  2:32 ` Shark8
@ 2014-10-12  4:53   ` Anh Vo
  2014-10-12  4:57     ` Shark8
  2014-10-12  9:16   ` Simon Wright
  1 sibling, 1 reply; 30+ messages in thread
From: Anh Vo @ 2014-10-12  4:53 UTC (permalink / raw)


On Saturday, October 11, 2014 7:32:07 PM UTC-7, Shark8 wrote:
> Well, let's make some subtypes!
>  
>   Subtype Integer_String is 
>    with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer 
>                              or else raise Constraint_Error;
 
Look like the parent type is missing. You probably meant this.

   Subtype Integer_String is Integer
    with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer 
                              or else raise Constraint_Error;

Anh Vo


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

* Re: type conversion
  2014-10-12  4:53   ` Anh Vo
@ 2014-10-12  4:57     ` Shark8
  2014-10-12  5:41       ` Anh Vo
                         ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Shark8 @ 2014-10-12  4:57 UTC (permalink / raw)


On 10/11/2014 10:53 PM, Anh Vo wrote:
> On Saturday, October 11, 2014 7:32:07 PM UTC-7, Shark8 wrote:
>> Well, let's make some subtypes!
>>
>>    Subtype Integer_String is
>>     with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer
>>                               or else raise Constraint_Error;
>
> Look like the parent type is missing. You probably meant this.
>
>     Subtype Integer_String is Integer
>      with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer
>                                or else raise Constraint_Error;
>
> Anh Vo
>

Almost,

Subtype Integer_String is new String
   with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer
                             or else raise Constraint_Error;


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

* Re: type conversion
  2014-10-12  4:57     ` Shark8
@ 2014-10-12  5:41       ` Anh Vo
  2014-10-12  6:38       ` Jeffrey Carter
  2014-10-12  9:37       ` Pascal Obry
  2 siblings, 0 replies; 30+ messages in thread
From: Anh Vo @ 2014-10-12  5:41 UTC (permalink / raw)


On Saturday, October 11, 2014 9:57:54 PM UTC-7, Shark8 wrote:
> On 10/11/2014 10:53 PM, Anh Vo wrote: 
>> On Saturday, October 11, 2014 7:32:07 PM UTC-7, Shark8 wrote: 
>>> Well, let's make some subtypes! 
>>> 
>>>    Subtype Integer_String is 
>>>     with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer 
>>>                               or else raise Constraint_Error; 
>> 
>> Look like the parent type is missing. You probably meant this. 
>> 
>>     Subtype Integer_String is Integer 
>>      with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer 
>>                                or else raise Constraint_Error;  
> Almost,
> 
> Subtype Integer_String is new String 
>    with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer 
>                              or else raise Constraint_Error;

Of course. Otherwise, it won't pass through the compiler.

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

* Re: type conversion
  2014-10-12  4:57     ` Shark8
  2014-10-12  5:41       ` Anh Vo
@ 2014-10-12  6:38       ` Jeffrey Carter
  2014-10-12  9:37       ` Pascal Obry
  2 siblings, 0 replies; 30+ messages in thread
From: Jeffrey Carter @ 2014-10-12  6:38 UTC (permalink / raw)


On 10/11/2014 09:57 PM, Shark8 wrote:
> 
> Subtype Integer_String is new String
>   with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer
>                             or else raise Constraint_Error;

Still not right. Remove "new".

-- 
Jeff Carter
"I fart in your general direction."
Monty Python & the Holy Grail
05

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

* Re: type conversion
  2014-10-12  2:32 ` Shark8
  2014-10-12  4:53   ` Anh Vo
@ 2014-10-12  9:16   ` Simon Wright
  2014-10-12 21:05     ` Shark8
  1 sibling, 1 reply; 30+ messages in thread
From: Simon Wright @ 2014-10-12  9:16 UTC (permalink / raw)


Shark8 <OneWingedShark@gmail.com> writes:

> Subtype Integer_String is
>   with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer
>                             or else raise Constraint_Error;

Do you actually need the 'or else raise Contraint_Error'? or is that
just to control the exception raised?

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

* Re: type conversion
  2014-10-11 23:56 type conversion compguy45
                   ` (2 preceding siblings ...)
  2014-10-12  2:32 ` Shark8
@ 2014-10-12  9:31 ` Simon Wright
  3 siblings, 0 replies; 30+ messages in thread
From: Simon Wright @ 2014-10-12  9:31 UTC (permalink / raw)


You are leaving us all guessing, and while we are pleased to help you
are making it much more difficult than it needs to be. Sorry to shout,
but ...

PLEASE in future post a SMALL COMPLETE source code THAT CAN BE PASSED TO
THE COMPILER.

If the program won't compile, POST THE ACTUAL ERROR MESSAGES.

If the program doesn't do what you expect, SAY WHAT YOU EXPECT and WHAT
HAPPENS.

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

* Re: type conversion
  2014-10-12  4:57     ` Shark8
  2014-10-12  5:41       ` Anh Vo
  2014-10-12  6:38       ` Jeffrey Carter
@ 2014-10-12  9:37       ` Pascal Obry
  2014-10-12 11:54         ` compguy45
  2014-10-12 23:05         ` Georg Bauhaus
  2 siblings, 2 replies; 30+ messages in thread
From: Pascal Obry @ 2014-10-12  9:37 UTC (permalink / raw)


Le samedi 11 octobre 2014 à 22:57 -0600, Shark8 a écrit : 
> Almost,
> 
> Subtype Integer_String is new String
>    with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer
>                              or else raise Constraint_Error;


I don't see the point of the "or else" part. The exception
Assertion_Error will be raised if the first part "Interger'Value .. in
Integer" is not True anyway.

To control the message or the exception to be raised one can use the
Predicate_Failure aspect:

subtype Integer_String is new String
   with Dynamic_Predicate => Integer'Value (Integer_String) in Integer,
        Predicate_Failure => "not an integer string";

or

subtype Integer_String is new String
   with Dynamic_Predicate => Integer'Value (Integer_String) in Integer,
        Predicate_Failure => 
          raise Constraint_Error with "not an integer string";

-- 
  Pascal Obry /  Magny Les Hameaux (78)

  The best way to travel is by means of imagination

  http://v2p.fr.eu.org
  http://www.obry.net

  gpg --keyserver keys.gnupg.net --recv-key F949BD3B


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

* Re: type conversion
  2014-10-12  9:37       ` Pascal Obry
@ 2014-10-12 11:54         ` compguy45
  2014-10-12 23:05         ` Georg Bauhaus
  1 sibling, 0 replies; 30+ messages in thread
From: compguy45 @ 2014-10-12 11:54 UTC (permalink / raw)


What happened was that when you converting 123 into string it actually became " 123" so i had to use trim function to remove left empty space 

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

* Re: type conversion
  2014-10-12  9:16   ` Simon Wright
@ 2014-10-12 21:05     ` Shark8
  0 siblings, 0 replies; 30+ messages in thread
From: Shark8 @ 2014-10-12 21:05 UTC (permalink / raw)


On 10/12/2014 3:16 AM, Simon Wright wrote:
> Shark8 <OneWingedShark@gmail.com> writes:
>
>> Subtype Integer_String is
>>    with Dynamic_Predicate => Integer'Value( Integer_String ) in Integer
>>                              or else raise Constraint_Error;
>
> Do you actually need the 'or else raise Contraint_Error'? or is that
> just to control the exception raised?
>

Just controlling the exception raised.


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

* Re: type conversion
  2014-10-12  9:37       ` Pascal Obry
  2014-10-12 11:54         ` compguy45
@ 2014-10-12 23:05         ` Georg Bauhaus
  2014-10-13  5:40           ` Pascal Obry
                             ` (2 more replies)
  1 sibling, 3 replies; 30+ messages in thread
From: Georg Bauhaus @ 2014-10-12 23:05 UTC (permalink / raw)


On 12.10.14 11:37, Pascal Obry wrote:
> To control the message or the exception to be raised one can use the
> Predicate_Failure aspect:
>
> subtype Integer_String is new String
>     with Dynamic_Predicate => Integer'Value (Integer_String) in Integer,
>          Predicate_Failure => "not an integer string";

Is Predicate_Failure a new aspect in GNAT? My RM does not list it,
and GNAT GPL 2014 rejects it. GNAT does, however, accept

    subtype Integer_String is String
      with Dynamic_Predicate => Integer'Value (Integer_String) in Integer
            or else raise Assertion_Error with "not an integer string";

(And warns that one should use 'Valid instead of a membership test,
even though there is no object to which one could apply 'Valid.)

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

* Re: type conversion
  2014-10-12 23:05         ` Georg Bauhaus
@ 2014-10-13  5:40           ` Pascal Obry
  2014-10-13  7:26           ` Simon Wright
  2014-10-13 22:36           ` Randy Brukardt
  2 siblings, 0 replies; 30+ messages in thread
From: Pascal Obry @ 2014-10-13  5:40 UTC (permalink / raw)


Le lundi 13 octobre 2014 à 01:05 +0200, Georg Bauhaus a écrit : 
> Is Predicate_Failure a new aspect in GNAT? My RM does not list it,
> and GNAT GPL 2014 rejects it. GNAT does, however, accept
> 
>     subtype Integer_String is String
>       with Dynamic_Predicate => Integer'Value (Integer_String) in Integer
>             or else raise Assertion_Error with "not an integer string";
> 
> (And warns that one should use 'Valid instead of a membership test,
> even though there is no object to which one could apply 'Valid.)

This pragma has been added recently. It is described into Barnes's Ada
2012 book though. GNAT does not support it yet, I have filed a report
about this.

Regards,

-- 
  Pascal Obry /  Magny Les Hameaux (78)

  The best way to travel is by means of imagination

  http://v2p.fr.eu.org
  http://www.obry.net

  gpg --keyserver keys.gnupg.net --recv-key F949BD3B



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

* Re: type conversion
  2014-10-12 23:05         ` Georg Bauhaus
  2014-10-13  5:40           ` Pascal Obry
@ 2014-10-13  7:26           ` Simon Wright
  2014-10-13 22:36           ` Randy Brukardt
  2 siblings, 0 replies; 30+ messages in thread
From: Simon Wright @ 2014-10-13  7:26 UTC (permalink / raw)


Georg Bauhaus <bauhaus@futureapps.invalid> writes:

> On 12.10.14 11:37, Pascal Obry wrote:
>> To control the message or the exception to be raised one can use the
>> Predicate_Failure aspect:
>>
>> subtype Integer_String is new String
>>     with Dynamic_Predicate => Integer'Value (Integer_String) in Integer,
>>          Predicate_Failure => "not an integer string";
>
> Is Predicate_Failure a new aspect in GNAT? My RM does not list it,
> and GNAT GPL 2014 rejects it. GNAT does, however, accept
>
>    subtype Integer_String is String
>      with Dynamic_Predicate => Integer'Value (Integer_String) in Integer
>            or else raise Assertion_Error with "not an integer string";
>
> (And warns that one should use 'Valid instead of a membership test,
> even though there is no object to which one could apply 'Valid.)

Unfortunately using 'Valid would make no difference, because if
Integer_String is say "foo" you get 

   Exception name: CONSTRAINT_ERROR
   Message: bad input for 'Value: "foo"


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

* Re: type conversion
  2014-10-12 23:05         ` Georg Bauhaus
  2014-10-13  5:40           ` Pascal Obry
  2014-10-13  7:26           ` Simon Wright
@ 2014-10-13 22:36           ` Randy Brukardt
  2 siblings, 0 replies; 30+ messages in thread
From: Randy Brukardt @ 2014-10-13 22:36 UTC (permalink / raw)


"Georg Bauhaus" <bauhaus@futureapps.invalid> wrote in message 
news:m1f1gi$ooh$1@dont-email.me...
> On 12.10.14 11:37, Pascal Obry wrote:
>> To control the message or the exception to be raised one can use the
>> Predicate_Failure aspect:
>>
>> subtype Integer_String is new String
>>     with Dynamic_Predicate => Integer'Value (Integer_String) in Integer,
>>          Predicate_Failure => "not an integer string";
>
> Is Predicate_Failure a new aspect in GNAT? My RM does not list it,
> and GNAT GPL 2014 rejects it.

It'll be in Corrigendum 2015 (the next set of bug fixes for Ada). Before 
that comes out, I wouldn't depend on it (one expects it to take a while 
before compilers catch up to the Corrigendum).

                                        Randy.




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

end of thread, other threads:[~2014-10-13 22:36 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-11 23:56 type conversion compguy45
2014-10-12  0:07 ` compguy45
2014-10-12  0:25   ` compguy45
2014-10-12  0:33 ` Jeffrey Carter
2014-10-12  0:38   ` compguy45
2014-10-12  3:45     ` Jeffrey Carter
2014-10-12  2:32 ` Shark8
2014-10-12  4:53   ` Anh Vo
2014-10-12  4:57     ` Shark8
2014-10-12  5:41       ` Anh Vo
2014-10-12  6:38       ` Jeffrey Carter
2014-10-12  9:37       ` Pascal Obry
2014-10-12 11:54         ` compguy45
2014-10-12 23:05         ` Georg Bauhaus
2014-10-13  5:40           ` Pascal Obry
2014-10-13  7:26           ` Simon Wright
2014-10-13 22:36           ` Randy Brukardt
2014-10-12  9:16   ` Simon Wright
2014-10-12 21:05     ` Shark8
2014-10-12  9:31 ` Simon Wright
  -- strict thread matches above, loose matches on Subject: below --
1998-11-01  0:00 Type Conversion Heather Wright
1998-11-01  0:00 ` dewarr
1998-11-01  0:00 ` Tucker Taft
1998-11-02  0:00 ` Marin David Condic
1998-11-02  0:00 ` Michael Kaufman
1998-11-03  0:00   ` Arun Mangalam
1998-11-06  0:00     ` Niklas Holsti
1997-12-08  0:00 Nick Davies
1997-12-08  0:00 ` John English
1997-12-09  0:00 ` Stephen Leake

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