global (public) variables

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

global (public) variables

christel.u.w.pachl christel.u.w.pachl
Can some kind soul tell me how to fix this;
http://rosettacode.org/mw/index.php?title=Continued_fraction&action=edit&section=11
Thank you in advance
Walter (NetRexx newbie but trying to learn)
If link doesn't work, something like this:
x=1
y=m(2)
say x
method m(inc) public static
x=x+inc
Return 0    

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: global (public) variables

alansam
Walter,

If you want to use "global" variables you really have to go "Object Oriented"  NetRexx may look procedural but the underlying Java architecture is OO.  Global variables need to exist as public static class properties.

Here's a "very" quick reworking of your code:

/* REXX ***************************************************************
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2=  1.41421356237309505              <- PL/I Result
*         1.41421356237309504880168872421  <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
*         2.71828182845904523536028747135
* PI=     3.14159262280484695
*         3.14159262280484694855146925223
* 07.09.2012 Walter Pachl
**********************************************************************/
options replace format comments java crossref savelog symbols
Numeric Digits 30
class RContinuedFractions public
properties static
  Sqrt2 =1
  napier=2
  pi    =3
  a     =0
  b     =0

method main(args = String[]) public static
  Say 'SQRT2='.left(7)  calc(sqrt2,  200)
  Say 'NAPIER='.left(7) calc(napier, 200)
  Say 'PI='.left(7)     calc(pi,     200)
  return

method get_Coeffs(form,n) public static
  select
    when form=Sqrt2 Then do
      if n > 0 then a = 2; else a = 1
      b = 1
      end
    when form=Napier Then do
      if n > 0 then a = n; else a = 2
      if n > 1 then b = n - 1; else b = 1
      end
    when form=pi Then do
      if n > 0 then a = 6; else a = 3
      b = (2*n - 1)**2
      end
    end
  Return a b

method calc(form,n)  public static
  temp=0
  loop ni = n to 1 by -1
    res=Get_Coeffs(form,ni)
    Parse res a b
    temp = b/(a + temp)
    end
  res=Get_Coeffs(form,0)
  Parse res a b
  return (A + temp)

Output:

SQRT2=  1.41421356237309504880168872421 
NAPIER= 2.71828182845904523536028747135 
PI=     3.14159262280484694855146925223 

Regards,
Alan.

On 7 September 2012 21:55, Walter Pachl <[hidden email]> wrote:
Can some kind soul tell me how to fix this;
http://rosettacode.org/mw/index.php?title=Continued_fraction&action=edit&section=11
Thank you in advance
Walter (NetRexx newbie but trying to learn)
If link doesn't work, something like this:
x=1
y=m(2)
say x
method m(inc) public static
x=x+inc
Return 0

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: global (public) variables

alansam
Walter,

Note too that I changed your "exit" to "return" in the main method. I did this for a very good reason; exit in NetRexx is translated to System.exit(0) which is a very heavy way to terminate a program and should be used with care (see http://www.javapractices.com/topic/TopicAction.do?Id=86 and http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#exit(int)).  Basically it terminates the JVM which may not be what you really intended to do.

Alan.

On 8 September 2012 11:07, Alan Sampson <[hidden email]> wrote:
Walter,

If you want to use "global" variables you really have to go "Object Oriented"  NetRexx may look procedural but the underlying Java architecture is OO.  Global variables need to exist as public static class properties.

Here's a "very" quick reworking of your code:

/* REXX ***************************************************************
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2=  1.41421356237309505              <- PL/I Result
*         1.41421356237309504880168872421  <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
*         2.71828182845904523536028747135
* PI=     3.14159262280484695
*         3.14159262280484694855146925223
* 07.09.2012 Walter Pachl
**********************************************************************/
options replace format comments java crossref savelog symbols
Numeric Digits 30
class RContinuedFractions public
properties static
  Sqrt2 =1
  napier=2
  pi    =3
  a     =0
  b     =0

method main(args = String[]) public static
  Say 'SQRT2='.left(7)  calc(sqrt2,  200)
  Say 'NAPIER='.left(7) calc(napier, 200)
  Say 'PI='.left(7)     calc(pi,     200)
  return

method get_Coeffs(form,n) public static
  select
    when form=Sqrt2 Then do
      if n > 0 then a = 2; else a = 1
      b = 1
      end
    when form=Napier Then do
      if n > 0 then a = n; else a = 2
      if n > 1 then b = n - 1; else b = 1
      end
    when form=pi Then do
      if n > 0 then a = 6; else a = 3
      b = (2*n - 1)**2
      end
    end
  Return a b

method calc(form,n)  public static
  temp=0
  loop ni = n to 1 by -1
    res=Get_Coeffs(form,ni)
    Parse res a b
    temp = b/(a + temp)
    end
  res=Get_Coeffs(form,0)
  Parse res a b
  return (A + temp)

Output:

SQRT2=  1.41421356237309504880168872421 
NAPIER= 2.71828182845904523536028747135 
PI=     3.14159262280484694855146925223 

Regards,
Alan.


On 7 September 2012 21:55, Walter Pachl <[hidden email]> wrote:
Can some kind soul tell me how to fix this;
http://rosettacode.org/mw/index.php?title=Continued_fraction&action=edit&section=11
Thank you in advance
Walter (NetRexx newbie but trying to learn)
If link doesn't work, something like this:
x=1
y=m(2)
say x
method m(inc) public static
x=x+inc
Return 0

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




--
Can't tweet, won't tweet!



--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: global (public) variables

billfen
In reply to this post by alansam
pi is 3.14159 26535 89793 23846 26433 83279 50288,
not   3.14159 26228 04846 94855 14692 5223

On 9/8/2012 2:07 PM, Alan Sampson wrote:
Walter,

If you want to use "global" variables you really have to go "Object Oriented"  NetRexx may look procedural but the underlying Java architecture is OO.  Global variables need to exist as public static class properties.

Here's a "very" quick reworking of your code:

/* REXX ***************************************************************
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2=  1.41421356237309505              <- PL/I Result
*         1.41421356237309504880168872421  <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
*         2.71828182845904523536028747135
* PI=     3.14159262280484695
*         3.14159262280484694855146925223
* 07.09.2012 Walter Pachl
**********************************************************************/
options replace format comments java crossref savelog symbols
Numeric Digits 30
class RContinuedFractions public
properties static
  Sqrt2 =1
  napier=2
  pi    =3
  a     =0
  b     =0

method main(args = String[]) public static
  Say 'SQRT2='.left(7)  calc(sqrt2,  200)
  Say 'NAPIER='.left(7) calc(napier, 200)
  Say 'PI='.left(7)     calc(pi,     200)
  return

method get_Coeffs(form,n) public static
  select
    when form=Sqrt2 Then do
      if n > 0 then a = 2; else a = 1
      b = 1
      end
    when form=Napier Then do
      if n > 0 then a = n; else a = 2
      if n > 1 then b = n - 1; else b = 1
      end
    when form=pi Then do
      if n > 0 then a = 6; else a = 3
      b = (2*n - 1)**2
      end
    end
  Return a b

method calc(form,n)  public static
  temp=0
  loop ni = n to 1 by -1
    res=Get_Coeffs(form,ni)
    Parse res a b
    temp = b/(a + temp)
    end
  res=Get_Coeffs(form,0)
  Parse res a b
  return (A + temp)

Output:

SQRT2=  1.41421356237309504880168872421 
NAPIER= 2.71828182845904523536028747135 
PI=     3.14159262280484694855146925223 

Regards,
Alan.

On 7 September 2012 21:55, Walter Pachl <[hidden email]> wrote:
Can some kind soul tell me how to fix this;
http://rosettacode.org/mw/index.php?title=Continued_fraction&action=edit&section=11
Thank you in advance
Walter (NetRexx newbie but trying to learn)
If link doesn't work, something like this:
x=1
y=m(2)
say x
method m(inc) public static
x=x+inc
Return 0

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2197 / Virus Database: 2437/5256 - Release Date: 09/08/12



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: global (public) variables

christel.u.w.pachl christel.u.w.pachl
In reply to this post by christel.u.w.pachl christel.u.w.pachl
Thanks y'all for the help
appreciated
Have a nice Sunday
Walter

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: global (public) variables

christel.u.w.pachl christel.u.w.pachl
In reply to this post by christel.u.w.pachl christel.u.w.pachl
Thanks
I shall investigate!!
:-(
Walter
---- Bill Fenlason <[hidden email]> schrieb:

> pi is 3.14159 26535 89793 23846 26433 83279 50288,
> not *3.14159 26228 04846 94855 14692 5223
> *
> On 9/8/2012 2:07 PM, Alan Sampson wrote:
> > Walter,
> >
> > If you want to use "global" variables you really have to go "Object
> > Oriented"  NetRexx may look procedural but the underlying Java
> > architecture is OO.  Global variables need to exist as public static
> > class properties.
> >
> > Here's a "very" quick reworking of your code:
> >
> > */* REXX ****************************************************************
> > ** Derived from REXX ... Derived from PL/I with a little "massage"*
> > ** SQRT2=  1.41421356237309505              <- PL/I Result*
> > **       1.41421356237309504880168872421  <- NetRexx Result 30 digits*
> > ** NAPIER= 2.71828182845904524*
> > **       2.71828182845904523536028747135*
> > ** PI=     3.14159262280484695*
> > **       3.14159262280484694855146925223*
> > ** 07.09.2012 Walter Pachl*
> > ***********************************************************************/*
> > *options replace format comments java crossref savelog symbols*
> > *Numeric Digits 30*
> > *class RContinuedFractions public*
> > *properties static*
> > *Sqrt2 =1*
> > *napier=2*
> > *  pi    =3*
> > *  a     =0*
> > *  b     =0*
> > *
> > *
> > *method main(args = String[]) public static*
> > *Say 'SQRT2='.left(7)  calc(sqrt2,  200)*
> > *Say 'NAPIER='.left(7) calc(napier, 200)*
> > *Say 'PI='.left(7)     calc(pi,     200)*
> > *return*
> > *
> > *
> > *method get_Coeffs(form,n) public static*
> > *select*
> > *when form=Sqrt2 Then do*
> > *  if n > 0 then a = 2; else a = 1*
> > *  b = 1*
> > *  end*
> > *when form=Napier Then do*
> > *  if n > 0 then a = n; else a = 2*
> > *  if n > 1 then b = n - 1; else b = 1*
> > *  end*
> > *when form=pi Then do*
> > *  if n > 0 then a = 6; else a = 3*
> > *  b = (2*n - 1)**2*
> > *  end*
> > *end*
> > *Return a b*
> > *
> > *
> > *method calc(form,n)  public static*
> > *temp=0*
> > *loop ni = n to 1 by -1*
> > *res=Get_Coeffs(form,ni)*
> > *Parse res a b*
> > *temp = b/(a + temp)*
> > *end*
> > *res=Get_Coeffs(form,0)*
> > *Parse res a b*
> > *return (A + temp)*
> >
> > *Output:*
> >
> > *SQRT2=  1.41421356237309504880168872421 *
> > *NAPIER= 2.71828182845904523536028747135 *
> > *PI=     3.14159262280484694855146925223 *
> >
> > Regards,
> > Alan.
> >
> > On 7 September 2012 21:55, Walter Pachl <[hidden email]
> > <mailto:[hidden email]>> wrote:
> >
> >     Can some kind soul tell me how to fix this;
> >     http://rosettacode.org/mw/index.php?title=Continued_fraction&action=edit&section=11
> >     Thank you in advance
> >     Walter (NetRexx newbie but trying to learn)
> >     If link doesn't work, something like this:
> >     x=1
> >     y=m(2)
> >     say x
> >     method m(inc) public static
> >     x=x+inc
> >     Return 0
> >
> >     _______________________________________________
> >     Ibm-netrexx mailing list
> >     [hidden email] <mailto:[hidden email]>
> >     Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
> >
> >
> >
> >
> > --
> > Can't tweet, won't tweet!
> >
> >
> > _______________________________________________
> > Ibm-netrexx mailing list
> > [hidden email]
> > Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
> >
> >
> >
> > No virus found in this message.
> > Checked by AVG - www.avg.com <http://www.avg.com>
> > Version: 2012.0.2197 / Virus Database: 2437/5256 - Release Date: 09/08/12
> >
>

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: global (public) variables

ThSITC
In reply to this post by christel.u.w.pachl christel.u.w.pachl
Hi Walter,
    it's so great, that *after years* I did try to convince you to
*learn* Netrexx, you now actually are
*doing* it !

My compliments,

Thomas Schneider,
(also) Vienna!
===================================================================================
Am 08.09.2012 06:55, schrieb Walter Pachl:

> Can some kind soul tell me how to fix this;
> http://rosettacode.org/mw/index.php?title=Continued_fraction&action=edit&section=11
> Thank you in advance
> Walter (NetRexx newbie but trying to learn)
> If link doesn't work, something like this:
> x=1
> y=m(2)
> say x
> method m(inc) public static
> x=x+inc
> Return 0
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
> Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
>
>


--
Thomas Schneider CEO ThSITC IT Consulting KG Erdbergstr. 52-60/1/13 1030
Wien Austria, Europe Skype ID: Thomas.Schneider.Wien Member of the Rexx
Languge Asscociation (www.rexxla.org) Member of the NetRexx Developer's
Team (www.netrexx.org)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com