comp.lang.ada
 help / color / mirror / Atom feed
* HOW TO FIX THIS IN ADA?
@ 2001-02-20 19:37 Munir Albeelbisi
  2001-02-20 20:37 ` Pascal Obry
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Munir Albeelbisi @ 2001-02-20 19:37 UTC (permalink / raw)


with Ada.Text_IO; use Ada.Text_IO;

PROCEDURE  Random(Output) IS ;
    seed1 = 5; seed2 = 10000; seed3 = 3000;
        x, y, z : integer;
        looop : integer;
    FUNCTION   Unif return real is
        tmp : real;
        Begin
        x := 171*(x mod 177) - 2*(x div 177);
        if x<0 then x := x + 30269;
        y := 172*(y mod 176) -35*(y div 176);
        if y<0 then y := y + 30307;
        z := 170*(z mod 178) -63*(z div 178);
        if z<0 then z := z + 30323;
        tmp :=  x/30269.0 + y/30307.0 + z/30323.0;
        Unif := tmp - trunc(tmp);
        End;  {Unif}
    BEGIN
    x := seed1; y := seed2; z := seed3;
    for looop := 1.. 1000 loop
        writeln(loop:4, ' ==> ', unif:7:5);
    END loop;
  END unif;





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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-20 19:37 HOW TO FIX THIS IN ADA? Munir Albeelbisi
@ 2001-02-20 20:37 ` Pascal Obry
  2001-02-20 20:38 ` How to write this in Ada, was " tmoran
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: Pascal Obry @ 2001-02-20 20:37 UTC (permalink / raw)



"Munir Albeelbisi" <munir.albeelbisi@sympatico.ca> writes:

<<Pascal program removed>>

What is supposed to be fixed ? Do you expect somebody to guess the question by
looking at the source ? Or maybe I missed some messages...

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



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

* How to write this in Ada, was HOW TO FIX THIS IN ADA?
  2001-02-20 19:37 HOW TO FIX THIS IN ADA? Munir Albeelbisi
  2001-02-20 20:37 ` Pascal Obry
@ 2001-02-20 20:38 ` tmoran
  2001-02-21  8:56 ` Martin Dowie
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: tmoran @ 2001-02-20 20:38 UTC (permalink / raw)


There are several good Ada texts in paper, and also material on-line.
Take a look at www.adapower.com and check your local computer book store.



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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-20 19:37 HOW TO FIX THIS IN ADA? Munir Albeelbisi
  2001-02-20 20:37 ` Pascal Obry
  2001-02-20 20:38 ` How to write this in Ada, was " tmoran
@ 2001-02-21  8:56 ` Martin Dowie
  2001-02-22  4:44 ` Lao Xiao Hai
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: Martin Dowie @ 2001-02-21  8:56 UTC (permalink / raw)


Are you looking for someone to re-write this specific R.N.G. in Ada? If not,
look up section 'A.5.2 Random Number Generation' of the language reference
manual (try www.adapower.com and select 'Reference').

If someone has told you that Ada is Pascal, then you have been sadly
misinformed
and simply adding a Ada.Text_IO context clause isn't going to work :-)

Munir Albeelbisi <munir.albeelbisi@sympatico.ca> wrote in message
news:6Izk6.161065$Pm2.3005370@news20.bellglobal.com...
> with Ada.Text_IO; use Ada.Text_IO;
>
> PROCEDURE  Random(Output) IS ;
>     seed1 = 5; seed2 = 10000; seed3 = 3000;
>         x, y, z : integer;
>         looop : integer;
>     FUNCTION   Unif return real is
>         tmp : real;
>         Begin
>         x := 171*(x mod 177) - 2*(x div 177);
>         if x<0 then x := x + 30269;
>         y := 172*(y mod 176) -35*(y div 176);
>         if y<0 then y := y + 30307;
>         z := 170*(z mod 178) -63*(z div 178);
>         if z<0 then z := z + 30323;
>         tmp :=  x/30269.0 + y/30307.0 + z/30323.0;
>         Unif := tmp - trunc(tmp);
>         End;  {Unif}
>     BEGIN
>     x := seed1; y := seed2; z := seed3;
>     for looop := 1.. 1000 loop
>         writeln(loop:4, ' ==> ', unif:7:5);
>     END loop;
>   END unif;
>
>





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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-20 19:37 HOW TO FIX THIS IN ADA? Munir Albeelbisi
                   ` (2 preceding siblings ...)
  2001-02-21  8:56 ` Martin Dowie
@ 2001-02-22  4:44 ` Lao Xiao Hai
  2001-02-22 17:48   ` Pascal Obry
  2001-02-22  7:17 ` tmoran
  2001-02-23  2:21 ` William J. Thomas
  5 siblings, 1 reply; 14+ messages in thread
From: Lao Xiao Hai @ 2001-02-22  4:44 UTC (permalink / raw)


Well, on first glance at this code, it is clear it will never compile.
Unless
I am not reading it correctly, there is a missing return statement in
the function.

Richard Riehle

Munir Albeelbisi wrote:

> with Ada.Text_IO; use Ada.Text_IO;
>
> PROCEDURE  Random(Output) IS ;
>     seed1 = 5; seed2 = 10000; seed3 = 3000;
>         x, y, z : integer;
>         looop : integer;
>     FUNCTION   Unif return real is
>         tmp : real;
>         Begin
>         x := 171*(x mod 177) - 2*(x div 177);
>         if x<0 then x := x + 30269;
>         y := 172*(y mod 176) -35*(y div 176);
>         if y<0 then y := y + 30307;
>         z := 170*(z mod 178) -63*(z div 178);
>         if z<0 then z := z + 30323;
>         tmp :=  x/30269.0 + y/30307.0 + z/30323.0;
>         Unif := tmp - trunc(tmp);
>         End;  {Unif}
>     BEGIN
>     x := seed1; y := seed2; z := seed3;
>     for looop := 1.. 1000 loop
>         writeln(loop:4, ' ==> ', unif:7:5);
>     END loop;
>   END unif;




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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-20 19:37 HOW TO FIX THIS IN ADA? Munir Albeelbisi
                   ` (3 preceding siblings ...)
  2001-02-22  4:44 ` Lao Xiao Hai
@ 2001-02-22  7:17 ` tmoran
  2001-02-22 16:43   ` Al Christians
  2001-02-23  2:21 ` William J. Thomas
  5 siblings, 1 reply; 14+ messages in thread
From: tmoran @ 2001-02-22  7:17 UTC (permalink / raw)


> with Ada.Text_IO; use Ada.Text_IO;
  Ada.Text_IO is never used in this program.
>
> PROCEDURE  Random(Output) IS ;
  what kind of parameter is Output?  in, out, integer, float, ???
  It's never referenced in the program anyway
  The ';' is illegal and should be dropped
>     seed1 = 5; seed2 = 10000; seed3 = 3000;
  Presumably these '=' are supposed to be ':='?  But of course
  none of seed1, seed2, or seed3 has been declared.  Given the
  later use, perhaps these should be "seed1 : constant integer := 5;" etc
>         x, y, z : integer;
>         looop : integer;
   'looop' is never used.
>     FUNCTION   Unif return real is
>         tmp : real;
  I see no type declaration for 'real' - probably meant 'float'
>         Begin
>         x := 171*(x mod 177) - 2*(x div 177);
  There is no 'div' operator.  Since x is integer, x/177 does the job.
>         if x<0 then x := x + 30269;
  Is there supposed to be an 'end if;' here, or is it supposed to be elsewhere?
>         y := 172*(y mod 176) -35*(y div 176);
  There is no 'div' operator.  Since y is integer, y/176 does the job.
>         if y<0 then y := y + 30307;
  Is there supposed to be an 'end if;' here, or is it supposed to be elsewhere?
>         z := 170*(z mod 178) -63*(z div 178);
  There is no 'div' operator.  Since z is integer, z/178 does the job.
>         if z<0 then z := z + 30323;
  Is there supposed to be an 'end if;' here, or is it supposed to be elsewhere?
>         tmp :=  x/30269.0 + y/30307.0 + z/30323.0;
  Since x, y, and z are Integer, this is illegal.  Probably want 'float(x)' etc
>         Unif := tmp - trunc(tmp);
  Where is function 'trunc' defined?
  Where is a 'return' statement and what should it return?
>         End;  {Unif}
  '{Unif}' is not Ada.  Probably meant "End Unif;"
>     BEGIN
>     x := seed1; y := seed2; z := seed3;
>     for looop := 1.. 1000 loop
  The ":=" is wrong, should be "in"
  The for-loop will automatically declare a new variable for its index
  'looop' - it will not use the one declared above
>         writeln(loop:4, ' ==> ', unif:7:5);
  What do "loop:4" and "unif:7:5" mean?
  multicharacter strings are delimited with ", single character literals
  with '  So this probably should be   "  ==> "
  The string concatenation operator is '&', eg onething & "  ==> " & another
  There is no procedure "writeln" declared anywhere.
  Probably this is meant to be "put", or "put_line", in which case
  the line with-ing Ada.Text_IO should be restored.
>     END loop;
>   END unif;
  This is the end of procedure Random, not of function Unif
Get an Ada compiler and it will tell you all this much quicker than c.l.a.



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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-22  7:17 ` tmoran
@ 2001-02-22 16:43   ` Al Christians
  0 siblings, 0 replies; 14+ messages in thread
From: Al Christians @ 2001-02-22 16:43 UTC (permalink / raw)


That code looks like pascal.

tmoran@acm.org wrote:
> 
> > with Ada.Text_IO; use Ada.Text_IO;
>   Ada.Text_IO is never used in this program.
> >
> > PROCEDURE  Random(Output) IS ;
>   what kind of parameter is Output?  in, out, integer, float, ???
>   It's never referenced in the program anyway
>   The ';' is illegal and should be dropped
> >     seed1 = 5; seed2 = 10000; seed3 = 3000;
>   Presumably these '=' are supposed to be ':='?  But of course
>   none of seed1, seed2, or seed3 has been declared.  Given the
>   later use, perhaps these should be "seed1 : constant integer := 5;" etc
> >         x, y, z : integer;
> >         looop : integer;
>    'looop' is never used.
> >     FUNCTION   Unif return real is
> >         tmp : real;
>   I see no type declaration for 'real' - probably meant 'float'
> >         Begin
> >         x := 171*(x mod 177) - 2*(x div 177);
>   There is no 'div' operator.  Since x is integer, x/177 does the job.
> >         if x<0 then x := x + 30269;
>   Is there supposed to be an 'end if;' here, or is it supposed to be elsewhere?
> >         y := 172*(y mod 176) -35*(y div 176);
>   There is no 'div' operator.  Since y is integer, y/176 does the job.
> >         if y<0 then y := y + 30307;
>   Is there supposed to be an 'end if;' here, or is it supposed to be elsewhere?
> >         z := 170*(z mod 178) -63*(z div 178);
>   There is no 'div' operator.  Since z is integer, z/178 does the job.
> >         if z<0 then z := z + 30323;
>   Is there supposed to be an 'end if;' here, or is it supposed to be elsewhere?
> >         tmp :=  x/30269.0 + y/30307.0 + z/30323.0;
>   Since x, y, and z are Integer, this is illegal.  Probably want 'float(x)' etc
> >         Unif := tmp - trunc(tmp);
>   Where is function 'trunc' defined?
>   Where is a 'return' statement and what should it return?
> >         End;  {Unif}
>   '{Unif}' is not Ada.  Probably meant "End Unif;"
> >     BEGIN
> >     x := seed1; y := seed2; z := seed3;
> >     for looop := 1.. 1000 loop
>   The ":=" is wrong, should be "in"
>   The for-loop will automatically declare a new variable for its index
>   'looop' - it will not use the one declared above
> >         writeln(loop:4, ' ==> ', unif:7:5);
>   What do "loop:4" and "unif:7:5" mean?
>   multicharacter strings are delimited with ", single character literals
>   with '  So this probably should be   "  ==> "
>   The string concatenation operator is '&', eg onething & "  ==> " & another
>   There is no procedure "writeln" declared anywhere.
>   Probably this is meant to be "put", or "put_line", in which case
>   the line with-ing Ada.Text_IO should be restored.
> >     END loop;
> >   END unif;
>   This is the end of procedure Random, not of function Unif
> Get an Ada compiler and it will tell you all this much quicker than c.l.a.



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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-22  4:44 ` Lao Xiao Hai
@ 2001-02-22 17:48   ` Pascal Obry
  2001-02-23  3:22     ` Lao Xiao Hai
  2001-02-23  4:08     ` Jeffrey Carter
  0 siblings, 2 replies; 14+ messages in thread
From: Pascal Obry @ 2001-02-22 17:48 UTC (permalink / raw)



Lao Xiao Hai <laoxhai@ix.netcom.com> writes:

> Well, on first glance at this code, it is clear it will never compile.
> Unless
> I am not reading it correctly, there is a missing return statement in
> the function.

No, in Pascal you just assign a value to the function.

	Unif := ...;

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-20 19:37 HOW TO FIX THIS IN ADA? Munir Albeelbisi
                   ` (4 preceding siblings ...)
  2001-02-22  7:17 ` tmoran
@ 2001-02-23  2:21 ` William J. Thomas
  5 siblings, 0 replies; 14+ messages in thread
From: William J. Thomas @ 2001-02-23  2:21 UTC (permalink / raw)


Want to fix in Ada? Simple, code in Ada, fix real quick!!!

"Munir Albeelbisi" <munir.albeelbisi@sympatico.ca> wrote in message
news:6Izk6.161065$Pm2.3005370@news20.bellglobal.com...
> with Ada.Text_IO; use Ada.Text_IO;
>
> PROCEDURE  Random(Output) IS ;
>     seed1 = 5; seed2 = 10000; seed3 = 3000;
>         x, y, z : integer;
>         looop : integer;
>     FUNCTION   Unif return real is
>         tmp : real;
>         Begin
>         x := 171*(x mod 177) - 2*(x div 177);
>         if x<0 then x := x + 30269;
>         y := 172*(y mod 176) -35*(y div 176);
>         if y<0 then y := y + 30307;
>         z := 170*(z mod 178) -63*(z div 178);
>         if z<0 then z := z + 30323;
>         tmp :=  x/30269.0 + y/30307.0 + z/30323.0;
>         Unif := tmp - trunc(tmp);
>         End;  {Unif}
>     BEGIN
>     x := seed1; y := seed2; z := seed3;
>     for looop := 1.. 1000 loop
>         writeln(loop:4, ' ==> ', unif:7:5);
>     END loop;
>   END unif;
>
>





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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-22 17:48   ` Pascal Obry
@ 2001-02-23  3:22     ` Lao Xiao Hai
  2001-02-23  4:08     ` Jeffrey Carter
  1 sibling, 0 replies; 14+ messages in thread
From: Lao Xiao Hai @ 2001-02-23  3:22 UTC (permalink / raw)




Pascal Obry wrote:

> Lao Xiao Hai <laoxhai@ix.netcom.com> writes:
>
> > Well, on first glance at this code, it is clear it will never compile.
> > Unless
> > I am not reading it correctly, there is a missing return statement in
> > the function.
>
> No, in Pascal you just assign a value to the function.

Correct.  I did not read the code carefully enough to notice that it was
not really Ada.    All I did was scan quickly for the return statement.
OTOH, closer look at this makes the whole question more bewildering
than when I was doing a cursory look.

Richard Riehle




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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-22 17:48   ` Pascal Obry
  2001-02-23  3:22     ` Lao Xiao Hai
@ 2001-02-23  4:08     ` Jeffrey Carter
  2001-02-23 17:18       ` Pascal Obry
  1 sibling, 1 reply; 14+ messages in thread
From: Jeffrey Carter @ 2001-02-23  4:08 UTC (permalink / raw)


Pascal Obry wrote:
> 
> No, in Pascal you just assign a value to the function.
> 
>         Unif := ...;
> 
> Pascal.

We'd really rather not know what goes on inside you.

This is clearly Pascal that has been lightly Ada-ized. It seems like a
very strange way to try to learn Ada.

-- 
Jeff Carter
"You brightly-colored, mealy-templed, cranberry-smelling, electric
donkey-bottom biters."
Monty Python & the Holy Grail



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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-23  4:08     ` Jeffrey Carter
@ 2001-02-23 17:18       ` Pascal Obry
  2001-02-24  4:40         ` Jeffrey Carter
  0 siblings, 1 reply; 14+ messages in thread
From: Pascal Obry @ 2001-02-23 17:18 UTC (permalink / raw)



Jeffrey Carter <jrcarter@acm.org> writes:

> Pascal Obry wrote:
> > 
> > No, in Pascal you just assign a value to the function.
> > 
> >         Unif := ...;
> > 
> > Pascal.
> 
> We'd really rather not know what goes on inside you.

???

> This is clearly Pascal that has been lightly Ada-ized. It seems like a
> very strange way to try to learn Ada.

I'm not sure, do you reply to me or did you quote something that has nothing
to do with the answer ?

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-23 17:18       ` Pascal Obry
@ 2001-02-24  4:40         ` Jeffrey Carter
  2001-02-24  9:22           ` Pascal Obry
  0 siblings, 1 reply; 14+ messages in thread
From: Jeffrey Carter @ 2001-02-24  4:40 UTC (permalink / raw)


Pascal Obry wrote:
> 
> Jeffrey Carter <jrcarter@acm.org> writes:
> 
> > Pascal Obry wrote:
> > >
> > > No, in Pascal you just assign a value to the function.
> > >
> > >         Unif := ...;
> > >
> > > Pascal.
> >
> > We'd really rather not know what goes on inside you.
> 
> ???

Sorry. This was a (lame attempt at) a joke. Pascal (you) said "... in
Pascal, ...". If I interpret that as referring to yourself, not to the
language, then ... well, even good jokes seem lame if you try to explain
them.

> 
> > This is clearly Pascal that has been lightly Ada-ized. It seems like a
> > very strange way to try to learn Ada.
> 
> I'm not sure, do you reply to me or did you quote something that has nothing
> to do with the answer ?

This last paragraph was a general comment on the code that was posted.

-- 
Jeff Carter
"I blow my nose on you."
Monty Python & the Holy Grail



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

* Re: HOW TO FIX THIS IN ADA?
  2001-02-24  4:40         ` Jeffrey Carter
@ 2001-02-24  9:22           ` Pascal Obry
  0 siblings, 0 replies; 14+ messages in thread
From: Pascal Obry @ 2001-02-24  9:22 UTC (permalink / raw)



Jeffrey Carter <jrcarter@acm.org> writes:

> > > We'd really rather not know what goes on inside you.
> > 
> > ???
> 
> Sorry. This was a (lame attempt at) a joke. Pascal (you) said "... in
> Pascal, ...". If I interpret that as referring to yourself, not to the
> language, then ... well, even good jokes seem lame if you try to explain
> them.

Oh well, I get it now :)

> This last paragraph was a general comment on the code that was posted.

So you should have quoted the code, it was not so obvious :)

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



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

end of thread, other threads:[~2001-02-24  9:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-20 19:37 HOW TO FIX THIS IN ADA? Munir Albeelbisi
2001-02-20 20:37 ` Pascal Obry
2001-02-20 20:38 ` How to write this in Ada, was " tmoran
2001-02-21  8:56 ` Martin Dowie
2001-02-22  4:44 ` Lao Xiao Hai
2001-02-22 17:48   ` Pascal Obry
2001-02-23  3:22     ` Lao Xiao Hai
2001-02-23  4:08     ` Jeffrey Carter
2001-02-23 17:18       ` Pascal Obry
2001-02-24  4:40         ` Jeffrey Carter
2001-02-24  9:22           ` Pascal Obry
2001-02-22  7:17 ` tmoran
2001-02-22 16:43   ` Al Christians
2001-02-23  2:21 ` William J. Thomas

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