comp.lang.ada
 help / color / mirror / Atom feed
* Ada begginer's new problem.
@ 2004-10-28  8:11 bubble
  2004-10-28  8:44 ` Jacob Sparre Andersen
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: bubble @ 2004-10-28  8:11 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1326 bytes --]


1. ��continue�� reserve word support?
Ada has no ��continue�� word.


   outer:loop
         execute_some_Statement_here0;
      EXIT when some_condition;
         execute_some_Statement_here1;
      inner: loop
         execute_some_Statement_here3;
         IF some_condition_is_true THEN
            goto outerContinueLabel;
         END IF;
         execute_some_Statement_here4;
      end loop inner;
         execute_some_Statement_here5;
      <<outerContinueLabel>>
         null;
   end loop outer;

It's hard to read,
How should I do to remove "goto"  ....?



2. type declare problem

I know there are some choices can apply to my program.
( a ). Type stock_price is new float;
( b ). Type stock_price is digits 5;
( c ). Subtype stock_price is float;

I know if I use ( c ) style.  I can mix stock_price and float type to
compute together.

if we don't consider ( c ) style, only  consider (a) and (b).
which style is best?


3. possible assign a IEEE754 NaN value to float type variable?

I use gwindows.database package to access atabase. It is great and very easy
to use.
Unfortunately, my database exits some null value in a table.
Many other languages will assign a NaN value to variable if it is null value
and float type.
Can I assign a NaN to float variable, like other languages?









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

* Re: Ada begginer's new problem.
  2004-10-28  8:11 Ada begginer's new problem bubble
@ 2004-10-28  8:44 ` Jacob Sparre Andersen
  2004-10-28 10:38 ` Larry Kilgallen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Jacob Sparre Andersen @ 2004-10-28  8:44 UTC (permalink / raw)


"bubble" <bubble@bubble.d2g.com> writes:

[ please use relevant subject lines ]

>    outer:loop
>          execute_some_Statement_here0;
>       EXIT when some_condition;
>          execute_some_Statement_here1;
>       inner: loop
>          execute_some_Statement_here3;
>          IF some_condition_is_true THEN
>             goto outerContinueLabel;
>          END IF;
>          execute_some_Statement_here4;
>       end loop inner;
>          execute_some_Statement_here5;
>       <<outerContinueLabel>>
>          null;
>    end loop outer;
> 
> It's hard to read,

Yes. :-(

 Outer:
   loop
      Execute_Some_Statement_Here0;
      exit Outer when Some_Condition;
      Execute_Some_Statement_Here1;

    Inner:
      loop
         Execute_Some_Statement_Here3;
         exit Inner when Some_Condition_Is_True;
         Execute_Some_Statement_Here4;
      end loop Inner;

      if not Some_Condition_Is_True then
         Execute_Some_Statement_Here5;
      end if;
   end loop Outer;

Greetings,

Jacob
-- 
"There is a slight error in the exponent" - quantum vaacum
 mass is 10^35 times the total dark matter mass



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

* Re: Ada begginer's new problem.
  2004-10-28  8:11 Ada begginer's new problem bubble
  2004-10-28  8:44 ` Jacob Sparre Andersen
@ 2004-10-28 10:38 ` Larry Kilgallen
  2004-10-28 11:26 ` Eric Jacoboni
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Larry Kilgallen @ 2004-10-28 10:38 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 829 bytes --]

In article <clqa5t$pif$1@netnews.hinet.net>, "bubble" <bubble@bubble.d2g.com> writes:
> 
> 1. ��continue�� reserve word support?
> Ada has no ��continue�� word.

What would you like the word "continue" to mean ?

If "continue" means something in another language with which you are
familiar, please do not assume that we all know that language.  It
might actually mean different things in different languages.

I see from

http://h71000.www7.hp.com/doc/73final/6296/6296_profile_025.html#index_x_691

> 6.8.8 CONTINUE
> 
> Function 
> 
> The CONTINUE statement indicates that no executable statement is present.
> It causes an implicit control transfer to the next executable statement.

That meaning is implicit in Ada, or you can use the statement "null;"
if you are being compensated on a per-line basis :-)



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

* Re: Ada begginer's new problem.
  2004-10-28  8:11 Ada begginer's new problem bubble
  2004-10-28  8:44 ` Jacob Sparre Andersen
  2004-10-28 10:38 ` Larry Kilgallen
@ 2004-10-28 11:26 ` Eric Jacoboni
  2004-10-28 20:19 ` Nick Roberts
  2004-10-29  2:47 ` Steve
  4 siblings, 0 replies; 7+ messages in thread
From: Eric Jacoboni @ 2004-10-28 11:26 UTC (permalink / raw)


"bubble" <bubble@bubble.d2g.com> writes:

> 1. ��continue�� reserve word support?
> Ada has no ��continue�� word.

Why Ada should have such a construct which breaks, imho,
logical flow of a program? (i suppose you talk about the C continue
statement).

> It's hard to read,

Perhaps because you could use another algorihm to achieve the same goal ?

> How should I do to remove "goto"  ....?

The question is rather: why i've had to use a goto in my algorithm ? ;-)

> 2. type declare problem
>
> I know there are some choices can apply to my program.
> ( a ). Type stock_price is new float;
> ( b ). Type stock_price is digits 5;
> ( c ). Subtype stock_price is float;
>
> I know if I use ( c ) style.  I can mix stock_price and float type to
> compute together.
>
> if we don't consider ( c ) style, only  consider (a) and (b).
> which style is best?

b is the best of your 3 options as it fits exactly to your requirement.
But, for modelizing prizes, i suggest you look at decimal fixed point, rather. 
-- 
�ric Jacoboni, n� il y a 1402406099 secondes



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

* Re: Ada begginer's new problem.
  2004-10-28  8:11 Ada begginer's new problem bubble
                   ` (2 preceding siblings ...)
  2004-10-28 11:26 ` Eric Jacoboni
@ 2004-10-28 20:19 ` Nick Roberts
  2004-10-29  2:58   ` bubble
  2004-10-29  2:47 ` Steve
  4 siblings, 1 reply; 7+ messages in thread
From: Nick Roberts @ 2004-10-28 20:19 UTC (permalink / raw)


bubble wrote:

>    outer:loop
>          execute_some_Statement_here0;
>       EXIT when some_condition;
>          execute_some_Statement_here1;
>       inner: loop
>          execute_some_Statement_here3;
>          IF some_condition_is_true THEN
>             goto outerContinueLabel;
>          END IF;
>          execute_some_Statement_here4;
>       end loop inner;
>          execute_some_Statement_here5;
>       <<outerContinueLabel>>
>          null;
>    end loop outer;
> 
> It's hard to read,
> How should I do to remove "goto"  ....?

In the above construction, it appears execute_some_Statement_here5 can
never be executed. Did you make a mistake?
         
Anyway, my personal advice would be not to try to eliminate gotos that
are difficult to eliminate. I think it is nearly always better (clearer,
easier to understand) to leave them in.

> I know there are some choices can apply to my program.
> ( a ). Type stock_price is new float;
> ( b ). Type stock_price is digits 5;
> ( c ). Subtype stock_price is float;
> ...
> if we don't consider ( c ) style, only  consider (a) and (b).
> which style is best?

I suggest you use a decimal fixed-point type for a stock price. It has
absolute accuracy. For example:

   type Stock_Price_in_Dollars is
      delta 0.01 digits 10 range 0.00 .. 99_999_999.99;

This requests a type which is always accurate to the cent, and can
represent values up to (but not including) $100mil.

It is usually better to declare types with an explicit request of the
properties you require of them. It may be possible for a pre-existing
type to not have these properties.

I think it is possible that you might want a more general-purpose type
to do all your currency calculations, and to use subtypes to impose
appropriate ranges. For example:

   type Dollars is delta 0.01 digits 10;

   subtype Stock_Price_in_Dollars is
      Dollars range 0.00 .. 99_999_999.99;

   subtype Price_Differential_in_Dollars is
      Dollars range -99_999_999.99 .. 99_999_999.99;

This way, you do not have the (probably inapproprate) inconvenience of
doing a lot of conversions to do mixed arithmetic:

   Old_Price, New_Price: Stock_Price_in_Dollars;
   Price_Change: Price_Differential_in_Dollars;
   ...
   New_Price := Old_Price + Price_Change;

> 3. possible assign a IEEE754 NaN value to float type variable?

It is implementation defined how to do this sort of thing. If you look
in the reference manual for your Ada compiler, you may find that there
is a method (for example, an implementation-defined attribute).

-- 
HTH
Nick Roberts



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

* Re: Ada begginer's new problem.
  2004-10-28  8:11 Ada begginer's new problem bubble
                   ` (3 preceding siblings ...)
  2004-10-28 20:19 ` Nick Roberts
@ 2004-10-29  2:47 ` Steve
  4 siblings, 0 replies; 7+ messages in thread
From: Steve @ 2004-10-29  2:47 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2208 bytes --]

For this specific example, I would use:

    outer:
        loop
            execute_some_Statement_here0;
            exit when some_condition;
            execute_some_Statement_here1;
            inner:
                loop
                    execute_some_Statement_here3;
                    if some_condition_is_true then
                        execute_some_Statement_here5;
                        exit inner;
                    end if;
                    execute_some_Statement_here4;
              end loop inner;
        end loop outer;

BTW:  I also use that other language you're probably refering to, and I
almost never use continue or goto in that language either.

Steve
(The Duck)


"bubble" <bubble@bubble.d2g.com> wrote in message
news:clqa5t$pif$1@netnews.hinet.net...
>
> 1. ��continue�� reserve word support?
> Ada has no ��continue�� word.
>
>
>    outer:loop
>          execute_some_Statement_here0;
>       EXIT when some_condition;
>          execute_some_Statement_here1;
>       inner: loop
>          execute_some_Statement_here3;
>          IF some_condition_is_true THEN
>             goto outerContinueLabel;
>          END IF;
>          execute_some_Statement_here4;
>       end loop inner;
>          execute_some_Statement_here5;
>       <<outerContinueLabel>>
>          null;
>    end loop outer;
>
> It's hard to read,
> How should I do to remove "goto"  ....?
>
>
>
> 2. type declare problem
>
> I know there are some choices can apply to my program.
> ( a ). Type stock_price is new float;
> ( b ). Type stock_price is digits 5;
> ( c ). Subtype stock_price is float;
>
> I know if I use ( c ) style.  I can mix stock_price and float type to
> compute together.
>
> if we don't consider ( c ) style, only  consider (a) and (b).
> which style is best?
>
>
> 3. possible assign a IEEE754 NaN value to float type variable?
>
> I use gwindows.database package to access atabase. It is great and very
easy
> to use.
> Unfortunately, my database exits some null value in a table.
> Many other languages will assign a NaN value to variable if it is null
value
> and float type.
> Can I assign a NaN to float variable, like other languages?
>
>
>
>
>
>





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

* Re: Ada begginer's new problem.
  2004-10-28 20:19 ` Nick Roberts
@ 2004-10-29  2:58   ` bubble
  0 siblings, 0 replies; 7+ messages in thread
From: bubble @ 2004-10-29  2:58 UTC (permalink / raw)




>
> In the above construction, it appears execute_some_Statement_here5 can
> never be executed. Did you make a mistake?
For example, I want print all prime number between 1 to 1000;
I rewrite java version prime example to ada version.

The code is

WITH ada.Text_IO;
PROCEDURE primeNum is
   PACKAGE sout is new ada.Text_IO.Integer_IO(integer);
   test:integer:=1;
begin
   sout.put(1);
   ada.Text_IO.New_Line;
   loop
      test := test+2;
      EXIT when test >1000;
      FOR fac in 2..test-1 loop
         IF test mod fac =0 THEN
            goto continueLoop;
         END IF;
      end loop;
      sout.put(test);
      ada.Text_IO.New_Line;
      <<continueLoop>>
             null;
   end loop;
end primeNum;

now I change it to another version.
It seem better.

WITH ada.Text_IO;
PROCEDURE primeNum is
   PACKAGE sout is new ada.Text_IO.Integer_IO(integer);
   test:integer:=1;
   FUNCTION isPrime(test:integer) return boolean is
   begin
     FOR fac in 2..test-1 loop
         IF test mod fac =0 THEN
            RETURN false;
         END IF;
      end loop;
      RETURN true;
   end isPrime;
begin
   sout.put(1);
   ada.Text_IO.New_Line;
   loop
      test := test+2;
      EXIT when test >1000;
      IF isPrime(test)=true THEN
         sout.put(test);
         ada.Text_IO.New_Line;
      END IF;
   end loop;
end primeNum;

thank jacob,larry,eric,nick,
your suggestions are very useful.


> Anyway, my personal advice would be not to try to eliminate gotos that
> are difficult to eliminate. I think it is nearly always better (clearer,
> easier to understand) to leave them in.
>
> > I know there are some choices can apply to my program.
> > ( a ). Type stock_price is new float;
> > ( b ). Type stock_price is digits 5;
> > ( c ). Subtype stock_price is float;
> > ...
> > if we don't consider ( c ) style, only  consider (a) and (b).
> > which style is best?
>
> I suggest you use a decimal fixed-point type for a stock price. It has
> absolute accuracy. For example:
>
>    type Stock_Price_in_Dollars is
>       delta 0.01 digits 10 range 0.00 .. 99_999_999.99;
>
> This requests a type which is always accurate to the cent, and can
> represent values up to (but not including) $100mil.
>
> It is usually better to declare types with an explicit request of the
> properties you require of them. It may be possible for a pre-existing
> type to not have these properties.
>
> I think it is possible that you might want a more general-purpose type
> to do all your currency calculations, and to use subtypes to impose
> appropriate ranges. For example:
>
>    type Dollars is delta 0.01 digits 10;
>
>    subtype Stock_Price_in_Dollars is
>       Dollars range 0.00 .. 99_999_999.99;
>
>    subtype Price_Differential_in_Dollars is
>       Dollars range -99_999_999.99 .. 99_999_999.99;
>
> This way, you do not have the (probably inapproprate) inconvenience of
> doing a lot of conversions to do mixed arithmetic:
>
>    Old_Price, New_Price: Stock_Price_in_Dollars;
>    Price_Change: Price_Differential_in_Dollars;
>    ...
>    New_Price := Old_Price + Price_Change;
>
> > 3. possible assign a IEEE754 NaN value to float type variable?
>
> It is implementation defined how to do this sort of thing. If you look
> in the reference manual for your Ada compiler, you may find that there
> is a method (for example, an implementation-defined attribute).
>
> -- 
> HTH
> Nick Roberts





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

end of thread, other threads:[~2004-10-29  2:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-28  8:11 Ada begginer's new problem bubble
2004-10-28  8:44 ` Jacob Sparre Andersen
2004-10-28 10:38 ` Larry Kilgallen
2004-10-28 11:26 ` Eric Jacoboni
2004-10-28 20:19 ` Nick Roberts
2004-10-29  2:58   ` bubble
2004-10-29  2:47 ` Steve

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