NetRexx Rexx Method Objective/Traditional

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

NetRexx Rexx Method Objective/Traditional

Jeff Hennick-3

This seems it should be easy to answer, and easy to do, but I'm stumped.  I have not been able to find any info in the documents I have looked at, or by Google.

I would like to write a Method that is of type Rexx.  That is, it can work like this

"Some Rexx string".myMethod(6)

I can write the Traditional way

Method myMethod(str, pos)

...str...

and it works with a Traditional Rexx call, but when I try

Method myMethod(pos)

...this...

and call it as the above first example, it gives an error that the method myMethod is not found in class Rexx.

So, is there any way I can define a method that will work as type Rexx?  I can make it of some new class an then cast a Rexx type variable to the new one, but this is even less appealing to me.  And, it can not be used in train of methods.

Any help would be very welcomed.


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

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx Rexx Method Objective/Traditional

rvjansen
Don’t worry, it is not something really easy.

On first sight, you want to extend the Rexx class. In the sense that it will have more methods than it currently has. This can be done, you need to write the class so it extends netrexx.lang.Rexx and has its constructors. But then you need to cast your Rexx type strings to your new class before you can call the new methods on it. Or allocate (define, declare) string variables as the new type. This is because the translator cannot know that things you put between “quotes” are now of a type other than Rexx.

The other route is to define an interface that contains Rexx and your new type, with “extends Rexx, implements y”* and cast your calls accordingly.

The previous two are because of the static nature of Java and consequently NetRexx. At compile time the existing methods on a class are checked, and if not available, you are sure to see the message that you see.

The third route is to try and use the translator api to dynamically add a method to the Rexx type. That would be a very interesting exercise and that, if workable, is guaranteed to make the “NetRexx Programmer’s Guide”. I am not at all sure that would work but you gave me something to think about when I need an excuse to not do the thousand things I am supposed to do.

I might think about this more today, and give you a better answer.

best regards,

René.

On 22 Mar 2020, at 15:02, Jeff Hennick <[hidden email]> wrote:

This seems it should be easy to answer, and easy to do, but I'm stumped.  I have not been able to find any info in the documents I have looked at, or by Google.

I would like to write a Method that is of type Rexx.  That is, it can work like this

"Some Rexx string".myMethod(6)

I can write the Traditional way

Method myMethod(str, pos)

...str...

and it works with a Traditional Rexx call, but when I try

Method myMethod(pos)

...this...

and call it as the above first example, it gives an error that the method myMethod is not found in class Rexx.

So, is there any way I can define a method that will work as type Rexx?  I can make it of some new class an then cast a Rexx type variable to the new one, but this is even less appealing to me.  And, it can not be used in train of methods.

Any help would be very welcomed.

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



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

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx Rexx Method Objective/Traditional

Jeff Hennick-3

René,

Thank you for your reassurance, and the information that it is a fundamental Java limitation.

But it seems like such a useful concept.  My current "need" is for an enhanced/altered SUBSTR.  Rather than SUBSTR(start, length), I need SUBSTRX(start, end) (with both start and end being capable of being negative so as to be from the right end).  As I said, I can do it with a Traditional Rexx call.

But with some quick searches for workarounds in Java (no nice ones), I found that the Groovy language, a sister JVM language, does have this capability built in, and apparently fairly easy to use.  See: https://docs.groovy-lang.org/latest/html/documentation/core-metaprogramming.html#_extending_existing_classes  And for anyone who can read Groovy (which I can't), here is a short example: https://mrhaki.blogspot.com/2009/11/groovy-goodness-add-methods-dynamically.html  From the 2009 date, we see this is not a new idea.

Now, since NetRexx, Groovy, and Java all make CLASS files that are intercallable, I wonder if we can get some "horizontal gene transfer."

All this, of course, depends on if others -- and I'm looking at Mr. Cowlishaw -- would find this useful in NetRexx.  Otherwise, I'll drop it now.

On 3/22/2020 10:29 AM, René Jansen wrote:
Don’t worry, it is not something really easy.

On first sight, you want to extend the Rexx class. In the sense that it will have more methods than it currently has. This can be done, you need to write the class so it extends netrexx.lang.Rexx and has its constructors. But then you need to cast your Rexx type strings to your new class before you can call the new methods on it. Or allocate (define, declare) string variables as the new type. This is because the translator cannot know that things you put between “quotes” are now of a type other than Rexx.

The other route is to define an interface that contains Rexx and your new type, with “extends Rexx, implements y”* and cast your calls accordingly.

The previous two are because of the static nature of Java and consequently NetRexx. At compile time the existing methods on a class are checked, and if not available, you are sure to see the message that you see.

The third route is to try and use the translator api to dynamically add a method to the Rexx type. That would be a very interesting exercise and that, if workable, is guaranteed to make the “NetRexx Programmer’s Guide”. I am not at all sure that would work but you gave me something to think about when I need an excuse to not do the thousand things I am supposed to do.

I might think about this more today, and give you a better answer.

best regards,

René.

On 22 Mar 2020, at 15:02, Jeff Hennick <[hidden email]> wrote:

This seems it should be easy to answer, and easy to do, but I'm stumped.  I have not been able to find any info in the documents I have looked at, or by Google.

I would like to write a Method that is of type Rexx.  That is, it can work like this

"Some Rexx string".myMethod(6)

I can write the Traditional way

Method myMethod(str, pos)

...str...

and it works with a Traditional Rexx call, but when I try

Method myMethod(pos)

...this...

and call it as the above first example, it gives an error that the method myMethod is not found in class Rexx.

So, is there any way I can define a method that will work as type Rexx?  I can make it of some new class an then cast a Rexx type variable to the new one, but this is even less appealing to me.  And, it can not be used in train of methods.

Any help would be very welcomed.

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



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


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

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx Rexx Method Objective/Traditional

rvjansen
Hi Jeff,

No reason to not put this in the Rexx class as far as I am concerned. It does have some extra methods that are not in the ‘official’ documentation. I think the first step is to specify and document it formally.

Groovy was designed as a dynamic language. ooRexx  can do it; it went into the design. NetRexx was meant to be a static language. It might do it, but there are more hoops to jump through.

René.

On 22 Mar 2020, at 19:35, Jeff Hennick <[hidden email]> wrote:



René,

Thank you for your reassurance, and the information that it is a fundamental Java limitation.

But it seems like such a useful concept.  My current "need" is for an enhanced/altered SUBSTR.  Rather than SUBSTR(start, length), I need SUBSTRX(start, end) (with both start and end being capable of being negative so as to be from the right end).  As I said, I can do it with a Traditional Rexx call.

But with some quick searches for workarounds in Java (no nice ones), I found that the Groovy language, a sister JVM language, does have this capability built in, and apparently fairly easy to use.  See: https://docs.groovy-lang.org/latest/html/documentation/core-metaprogramming.html#_extending_existing_classes  And for anyone who can read Groovy (which I can't), here is a short example: https://mrhaki.blogspot.com/2009/11/groovy-goodness-add-methods-dynamically.html  From the 2009 date, we see this is not a new idea.

Now, since NetRexx, Groovy, and Java all make CLASS files that are intercallable, I wonder if we can get some "horizontal gene transfer."

All this, of course, depends on if others -- and I'm looking at Mr. Cowlishaw -- would find this useful in NetRexx.  Otherwise, I'll drop it now.

On 3/22/2020 10:29 AM, René Jansen wrote:
Don’t worry, it is not something really easy.

On first sight, you want to extend the Rexx class. In the sense that it will have more methods than it currently has. This can be done, you need to write the class so it extends netrexx.lang.Rexx and has its constructors. But then you need to cast your Rexx type strings to your new class before you can call the new methods on it. Or allocate (define, declare) string variables as the new type. This is because the translator cannot know that things you put between “quotes” are now of a type other than Rexx.

The other route is to define an interface that contains Rexx and your new type, with “extends Rexx, implements y”* and cast your calls accordingly.

The previous two are because of the static nature of Java and consequently NetRexx. At compile time the existing methods on a class are checked, and if not available, you are sure to see the message that you see.

The third route is to try and use the translator api to dynamically add a method to the Rexx type. That would be a very interesting exercise and that, if workable, is guaranteed to make the “NetRexx Programmer’s Guide”. I am not at all sure that would work but you gave me something to think about when I need an excuse to not do the thousand things I am supposed to do.

I might think about this more today, and give you a better answer.

best regards,

René.

On 22 Mar 2020, at 15:02, Jeff Hennick <[hidden email]> wrote:

This seems it should be easy to answer, and easy to do, but I'm stumped.  I have not been able to find any info in the documents I have looked at, or by Google.

I would like to write a Method that is of type Rexx.  That is, it can work like this

"Some Rexx string".myMethod(6)

I can write the Traditional way

Method myMethod(str, pos)

...str...

and it works with a Traditional Rexx call, but when I try

Method myMethod(pos)

...this...

and call it as the above first example, it gives an error that the method myMethod is not found in class Rexx.

So, is there any way I can define a method that will work as type Rexx?  I can make it of some new class an then cast a Rexx type variable to the new one, but this is even less appealing to me.  And, it can not be used in train of methods.

Any help would be very welcomed.

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



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

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


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

Reply | Threaded
Open this post in threaded view
|

Help for a NetRexx beginner

Ray Mansell
In reply to this post by rvjansen

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell


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

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx Rexx Method Objective/Traditional

Mike Cowlishaw
In reply to this post by Jeff Hennick-3
All this, of course, depends on if others -- and I'm looking at Mr. Cowlishaw -- would find this useful in NetRexx.  Otherwise, I'll drop it now. 
 
Really not up to me!   I'm very proud of the NetRexx language -- probably the best of the 13 I've designed .. but currently I have no projects that are based on the  Java platform so don't use NetRexx :-((.    I'm doing a lot of programming -- but it is almost all in classic/ooRexx and C (PanGazer, in particular, is very performance-critical).
 
Mike

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

Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

rvjansen
In reply to this post by Ray Mansell
Hi Ray,

good to see you here!

There is an explanation for this. ’Say’ has a safety against nullpointers. If you feed it a nullpointer, it will print you an empty line. Now in the second scenario, you concatenate ‘o’ with the nullpointer. The way this works, is that this ‘abuttal’ concatenation is called before the ’say’. This is done by the ‘concat’ method (netrexx.lang.Rexx.concat), which has no protection against nullpointers.

If you want to handle this, so your loop will end anyway, you can do this:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  do
    o = i':'
    say o array[i]
  catch NullpointerException
    say 'there was a null pointer'
  end
end


best regards,

René.

On 22 Mar 2020, at 20:13, Ray Mansell <[hidden email]> wrote:

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell

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



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

Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

Ray Mansell
Thank you, René, I had suspected something like that in view of the messages. This rather goes against the grain of one of Mike's original principles "there should be no surprises", although of course I was bending the rules a bit.

Anyway, onward with the learning, and thanks again,

Ray

On 3/22/2020 15:45, René Jansen wrote:
Hi Ray,

good to see you here!

There is an explanation for this. ’Say’ has a safety against nullpointers. If you feed it a nullpointer, it will print you an empty line. Now in the second scenario, you concatenate ‘o’ with the nullpointer. The way this works, is that this ‘abuttal’ concatenation is called before the ’say’. This is done by the ‘concat’ method (netrexx.lang.Rexx.concat), which has no protection against nullpointers.

If you want to handle this, so your loop will end anyway, you can do this:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  do
    o = i':'
    say o array[i]
  catch NullpointerException
    say 'there was a null pointer'
  end
end


best regards,

René.

On 22 Mar 2020, at 20:13, Ray Mansell <[hidden email]> wrote:

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell

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



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



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

Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

ThSITC
In reply to this post by Ray Mansell

As far as I do understand Your example, NOT assigned String Array items are containin a Null Pointer, thus are prohibited to be Referenced!

When  You would use array=Rexx[3]  'unknown' I think that should work ...

Kindly, Thomas Schneider, Vienna, Austria.

===============================================================================================

Am 22.03.2020 um 20:13 schrieb Ray Mansell:

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell


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


Virus-free. www.avg.com

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

rvjansen
In reply to this post by Ray Mansell
I have to agree. I don’t know how much code will be broken if I catch that in Rexx.concat()  - if everybody observed the rule (stated in the Java docs themselves), to not depend on exception handlers for program flow, none. Show we should have a vote on that.

René.

On 22 Mar 2020, at 20:52, Ray Mansell <[hidden email]> wrote:

Thank you, René, I had suspected something like that in view of the messages. This rather goes against the grain of one of Mike's original principles "there should be no surprises", although of course I was bending the rules a bit.

Anyway, onward with the learning, and thanks again,

Ray

On 3/22/2020 15:45, René Jansen wrote:
Hi Ray,

good to see you here!

There is an explanation for this. ’Say’ has a safety against nullpointers. If you feed it a nullpointer, it will print you an empty line. Now in the second scenario, you concatenate ‘o’ with the nullpointer. The way this works, is that this ‘abuttal’ concatenation is called before the ’say’. This is done by the ‘concat’ method (netrexx.lang.Rexx.concat), which has no protection against nullpointers.

If you want to handle this, so your loop will end anyway, you can do this:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  do
    o = i':'
    say o array[i]
  catch NullpointerException
    say 'there was a null pointer'
  end
end


best regards,

René.

On 22 Mar 2020, at 20:13, Ray Mansell <[hidden email]> wrote:

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell

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



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


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



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

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx Rexx Method Objective/Traditional

Jeff Hennick-3
In reply to this post by rvjansen

I am NOT asking that this, or any other, method be added to the base Rexx class.  Doing that piecemeal leads to madness.  Having a way to add them on-the-fly can be useful.  An Engineering Math package working with Rexx numbers anyone?

But, this is not at the top of my list.  The answer to my original question will remain:  Can't be done, now, and it would not be easy to implement.

Thanks as always for (all) your time and thoughts.

On 3/22/2020 3:03 PM, [hidden email] wrote:
Hi Jeff,

No reason to not put this in the Rexx class as far as I am concerned. It does have some extra methods that are not in the ‘official’ documentation. I think the first step is to specify and document it formally.

Groovy was designed as a dynamic language. ooRexx  can do it; it went into the design. NetRexx was meant to be a static language. It might do it, but there are more hoops to jump through.

René.

On 22 Mar 2020, at 19:35, Jeff Hennick [hidden email] wrote:



René,

Thank you for your reassurance, and the information that it is a fundamental Java limitation.

But it seems like such a useful concept.  My current "need" is for an enhanced/altered SUBSTR.  Rather than SUBSTR(start, length), I need SUBSTRX(start, end) (with both start and end being capable of being negative so as to be from the right end).  As I said, I can do it with a Traditional Rexx call.

But with some quick searches for workarounds in Java (no nice ones), I found that the Groovy language, a sister JVM language, does have this capability built in, and apparently fairly easy to use.  See: https://docs.groovy-lang.org/latest/html/documentation/core-metaprogramming.html#_extending_existing_classes  And for anyone who can read Groovy (which I can't), here is a short example: https://mrhaki.blogspot.com/2009/11/groovy-goodness-add-methods-dynamically.html  From the 2009 date, we see this is not a new idea.

Now, since NetRexx, Groovy, and Java all make CLASS files that are intercallable, I wonder if we can get some "horizontal gene transfer."

All this, of course, depends on if others -- and I'm looking at Mr. Cowlishaw -- would find this useful in NetRexx.  Otherwise, I'll drop it now.

On 3/22/2020 10:29 AM, René Jansen wrote:
Don’t worry, it is not something really easy.

On first sight, you want to extend the Rexx class. In the sense that it will have more methods than it currently has. This can be done, you need to write the class so it extends netrexx.lang.Rexx and has its constructors. But then you need to cast your Rexx type strings to your new class before you can call the new methods on it. Or allocate (define, declare) string variables as the new type. This is because the translator cannot know that things you put between “quotes” are now of a type other than Rexx.

The other route is to define an interface that contains Rexx and your new type, with “extends Rexx, implements y”* and cast your calls accordingly.

The previous two are because of the static nature of Java and consequently NetRexx. At compile time the existing methods on a class are checked, and if not available, you are sure to see the message that you see.

The third route is to try and use the translator api to dynamically add a method to the Rexx type. That would be a very interesting exercise and that, if workable, is guaranteed to make the “NetRexx Programmer’s Guide”. I am not at all sure that would work but you gave me something to think about when I need an excuse to not do the thousand things I am supposed to do.

I might think about this more today, and give you a better answer.

best regards,

René.

On 22 Mar 2020, at 15:02, Jeff Hennick <[hidden email]> wrote:

This seems it should be easy to answer, and easy to do, but I'm stumped.  I have not been able to find any info in the documents I have looked at, or by Google.

I would like to write a Method that is of type Rexx.  That is, it can work like this

"Some Rexx string".myMethod(6)

I can write the Traditional way

Method myMethod(str, pos)

...str...

and it works with a Traditional Rexx call, but when I try

Method myMethod(pos)

...this...

and call it as the above first example, it gives an error that the method myMethod is not found in class Rexx.

So, is there any way I can define a method that will work as type Rexx?  I can make it of some new class an then cast a Rexx type variable to the new one, but this is even less appealing to me.  And, it can not be used in train of methods.

Any help would be very welcomed.

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



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

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


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


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

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx Rexx Method Objective/Traditional

Mike Cowlishaw

I though that dynamic class/method adding was already part of NetRexx .. necessary for the 'interpreter' operation?
 
Mike


From: [hidden email] [mailto:[hidden email]] On Behalf Of Jeff Hennick
Sent: 22 March 2020 20:59
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] NetRexx Rexx Method Objective/Traditional

I am NOT asking that this, or any other, method be added to the base Rexx class.  Doing that piecemeal leads to madness.  Having a way to add them on-the-fly can be useful.  An Engineering Math package working with Rexx numbers anyone?

But, this is not at the top of my list.  The answer to my original question will remain:  Can't be done, now, and it would not be easy to implement.

Thanks as always for (all) your time and thoughts.

On 3/22/2020 3:03 PM, [hidden email] wrote:
Hi Jeff,

No reason to not put this in the Rexx class as far as I am concerned. It does have some extra methods that are not in the ‘official’ documentation. I think the first step is to specify and document it formally.

Groovy was designed as a dynamic language. ooRexx  can do it; it went into the design. NetRexx was meant to be a static language. It might do it, but there are more hoops to jump through.

René.

On 22 Mar 2020, at 19:35, Jeff Hennick [hidden email] wrote:



René,

Thank you for your reassurance, and the information that it is a fundamental Java limitation.

But it seems like such a useful concept.  My current "need" is for an enhanced/altered SUBSTR.  Rather than SUBSTR(start, length), I need SUBSTRX(start, end) (with both start and end being capable of being negative so as to be from the right end).  As I said, I can do it with a Traditional Rexx call.

But with some quick searches for workarounds in Java (no nice ones), I found that the Groovy language, a sister JVM language, does have this capability built in, and apparently fairly easy to use.  See: https://docs.groovy-lang.org/latest/html/documentation/core-metaprogramming.html#_extending_existing_classes  And for anyone who can read Groovy (which I can't), here is a short example: https://mrhaki.blogspot.com/2009/11/groovy-goodness-add-methods-dynamically.html  From the 2009 date, we see this is not a new idea.

Now, since NetRexx, Groovy, and Java all make CLASS files that are intercallable, I wonder if we can get some "horizontal gene transfer."

All this, of course, depends on if others -- and I'm looking at Mr. Cowlishaw -- would find this useful in NetRexx.  Otherwise, I'll drop it now.

On 3/22/2020 10:29 AM, René Jansen wrote:
Don’t worry, it is not something really easy.

On first sight, you want to extend the Rexx class. In the sense that it will have more methods than it currently has. This can be done, you need to write the class so it extends netrexx.lang.Rexx and has its constructors. But then you need to cast your Rexx type strings to your new class before you can call the new methods on it. Or allocate (define, declare) string variables as the new type. This is because the translator cannot know that things you put between “quotes” are now of a type other than Rexx.

The other route is to define an interface that contains Rexx and your new type, with “extends Rexx, implements y”* and cast your calls accordingly.

The previous two are because of the static nature of Java and consequently NetRexx. At compile time the existing methods on a class are checked, and if not available, you are sure to see the message that you see.

The third route is to try and use the translator api to dynamically add a method to the Rexx type. That would be a very interesting exercise and that, if workable, is guaranteed to make the “NetRexx Programmer’s Guide”. I am not at all sure that would work but you gave me something to think about when I need an excuse to not do the thousand things I am supposed to do.

I might think about this more today, and give you a better answer.

best regards,

René.

On 22 Mar 2020, at 15:02, Jeff Hennick <[hidden email]> wrote:

This seems it should be easy to answer, and easy to do, but I'm stumped.  I have not been able to find any info in the documents I have looked at, or by Google.

I would like to write a Method that is of type Rexx.  That is, it can work like this

"Some Rexx string".myMethod(6)

I can write the Traditional way

Method myMethod(str, pos)

...str...

and it works with a Traditional Rexx call, but when I try

Method myMethod(pos)

...this...

and call it as the above first example, it gives an error that the method myMethod is not found in class Rexx.

So, is there any way I can define a method that will work as type Rexx?  I can make it of some new class an then cast a Rexx type variable to the new one, but this is even less appealing to me.  And, it can not be used in train of methods.

Any help would be very welcomed.

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



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

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


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


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

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx Rexx Method Objective/Traditional

rvjansen
It is. I referred to that as ‘the third route’. I experimented with that some time ago but have to dig up the code.

René.

On 22 Mar 2020, at 22:09, Mike Cowlishaw <[hidden email]> wrote:


I though that dynamic class/method adding was already part of NetRexx .. necessary for the 'interpreter' operation?
 
Mike


From: [hidden email] [mailto:[hidden email]] On Behalf Of Jeff Hennick
Sent: 22 March 2020 20:59
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] NetRexx Rexx Method Objective/Traditional

I am NOT asking that this, or any other, method be added to the base Rexx class.  Doing that piecemeal leads to madness.  Having a way to add them on-the-fly can be useful.  An Engineering Math package working with Rexx numbers anyone?

But, this is not at the top of my list.  The answer to my original question will remain:  Can't be done, now, and it would not be easy to implement.

Thanks as always for (all) your time and thoughts.

On 3/22/2020 3:03 PM, [hidden email] wrote:
Hi Jeff,

No reason to not put this in the Rexx class as far as I am concerned. It does have some extra methods that are not in the ‘official’ documentation. I think the first step is to specify and document it formally.

Groovy was designed as a dynamic language. ooRexx  can do it; it went into the design. NetRexx was meant to be a static language. It might do it, but there are more hoops to jump through.

René.

On 22 Mar 2020, at 19:35, Jeff Hennick [hidden email] wrote:



René,

Thank you for your reassurance, and the information that it is a fundamental Java limitation.

But it seems like such a useful concept.  My current "need" is for an enhanced/altered SUBSTR.  Rather than SUBSTR(start, length), I need SUBSTRX(start, end) (with both start and end being capable of being negative so as to be from the right end).  As I said, I can do it with a Traditional Rexx call.

But with some quick searches for workarounds in Java (no nice ones), I found that the Groovy language, a sister JVM language, does have this capability built in, and apparently fairly easy to use.  See: https://docs.groovy-lang.org/latest/html/documentation/core-metaprogramming.html#_extending_existing_classes  And for anyone who can read Groovy (which I can't), here is a short example: https://mrhaki.blogspot.com/2009/11/groovy-goodness-add-methods-dynamically.html  From the 2009 date, we see this is not a new idea.

Now, since NetRexx, Groovy, and Java all make CLASS files that are intercallable, I wonder if we can get some "horizontal gene transfer."

All this, of course, depends on if others -- and I'm looking at Mr. Cowlishaw -- would find this useful in NetRexx.  Otherwise, I'll drop it now.

On 3/22/2020 10:29 AM, René Jansen wrote:
Don’t worry, it is not something really easy.

On first sight, you want to extend the Rexx class. In the sense that it will have more methods than it currently has. This can be done, you need to write the class so it extends netrexx.lang.Rexx and has its constructors. But then you need to cast your Rexx type strings to your new class before you can call the new methods on it. Or allocate (define, declare) string variables as the new type. This is because the translator cannot know that things you put between “quotes” are now of a type other than Rexx.

The other route is to define an interface that contains Rexx and your new type, with “extends Rexx, implements y”* and cast your calls accordingly.

The previous two are because of the static nature of Java and consequently NetRexx. At compile time the existing methods on a class are checked, and if not available, you are sure to see the message that you see.

The third route is to try and use the translator api to dynamically add a method to the Rexx type. That would be a very interesting exercise and that, if workable, is guaranteed to make the “NetRexx Programmer’s Guide”. I am not at all sure that would work but you gave me something to think about when I need an excuse to not do the thousand things I am supposed to do.

I might think about this more today, and give you a better answer.

best regards,

René.

On 22 Mar 2020, at 15:02, Jeff Hennick <[hidden email]> wrote:

This seems it should be easy to answer, and easy to do, but I'm stumped.  I have not been able to find any info in the documents I have looked at, or by Google.

I would like to write a Method that is of type Rexx.  That is, it can work like this

"Some Rexx string".myMethod(6)

I can write the Traditional way

Method myMethod(str, pos)

...str...

and it works with a Traditional Rexx call, but when I try

Method myMethod(pos)

...this...

and call it as the above first example, it gives an error that the method myMethod is not found in class Rexx.

So, is there any way I can define a method that will work as type Rexx?  I can make it of some new class an then cast a Rexx type variable to the new one, but this is even less appealing to me.  And, it can not be used in train of methods.

Any help would be very welcomed.

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



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

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


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

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


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

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx Rexx Method Objective/Traditional

Mike Cowlishaw

Ah .. OK.


 
It is. I referred to that as ‘the third route’. I experimented with that some time ago but have to dig up the code.

René.

On 22 Mar 2020, at 22:09, Mike Cowlishaw <[hidden email]> wrote:


I though that dynamic class/method adding was already part of NetRexx .. necessary for the 'interpreter' operation?
 
Mike

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

Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

Ray Mansell
In reply to this post by rvjansen
Another surprise!  Consider this code:
num = int[10]
num[2] = 123
say num[2] num[3]

array=String[10]
array[2]='String'
say array[2] array[3]
Two arrays, both with 10 elements, both only partially initialised.
The first 'say' is successful, the second fails:
C:\NetRexx\user>java array01

123 0

Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)
This is terribly unsettling - surely it should always succeed, or always fail? And if it fails, a meaningful error message would be nice (e.g. "Attempt to access an unitilialised array element")

Thank you,
Ray


On 3/22/2020 16:23, René Jansen wrote:
I have to agree. I don’t know how much code will be broken if I catch that in Rexx.concat()  - if everybody observed the rule (stated in the Java docs themselves), to not depend on exception handlers for program flow, none. Show we should have a vote on that.

René.

On 22 Mar 2020, at 20:52, Ray Mansell <[hidden email]> wrote:

Thank you, René, I had suspected something like that in view of the messages. This rather goes against the grain of one of Mike's original principles "there should be no surprises", although of course I was bending the rules a bit.

Anyway, onward with the learning, and thanks again,

Ray

On 3/22/2020 15:45, René Jansen wrote:
Hi Ray,

good to see you here!

There is an explanation for this. ’Say’ has a safety against nullpointers. If you feed it a nullpointer, it will print you an empty line. Now in the second scenario, you concatenate ‘o’ with the nullpointer. The way this works, is that this ‘abuttal’ concatenation is called before the ’say’. This is done by the ‘concat’ method (netrexx.lang.Rexx.concat), which has no protection against nullpointers.

If you want to handle this, so your loop will end anyway, you can do this:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  do
    o = i':'
    say o array[i]
  catch NullpointerException
    say 'there was a null pointer'
  end
end


best regards,

René.

On 22 Mar 2020, at 20:13, Ray Mansell <[hidden email]> wrote:

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell

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



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


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



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



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

Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

rvjansen
Hi Ray,

sorry about that - Java is mostly to blame here. The reason here is that an int is a native type, while a String is a reference type - an Object.Native types have default values, 0 in the case of an int. Were you to repeat this with type Integer, you’d see the same error.

We are use to this, is my only excuse. If you were to tell me that assembler is easier than Java, I would have to agree, it is just so much work. But the general issue here, is that there should not be any uninitialized reference types in our code, and this is Java’s unhelpful way to express that. As I said earlier, we could protect all these things in NetRexx runtime but the resulting picture would not be of any more clarity.

When I have a nullpointer, I do:

➜  test git:(master) ✗ raytest3.class
   --- raytest3.nrx
 2 *=* num = int[10]
   >>> "10"
   >v> num "[I@5cad8086"
 3 *=* num[2] = 123
   >>> "2"
   >v> num "123"
 4 *=* say num[2] num[3]
   >>> "2"
   >>> "3"
   >>> "123 0"
123 0
 6 *=* array=String[10]
   >>> "10"
   >v> array "[Ljava.lang.String;@610455d6"
 7 *=* array[2]='String'
   >>> "2"
   >v> array "String"
 8 *=* say array[2] array[3]
   >>> "2"
   >>> "3"
Exception in thread "main" java.lang.NullPointerException
at netrexx.lang.Rexx.concat(Rexx.java:2261)
at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
at raytest3.main(raytest3.java:9)

So you’ll see that the dereferencing of array[3] is where it falls apart.
Exactly because of this reason, modern versions of languages have optional types; not surprisingly these have their own issues.

But just see it as if you did a DS where it should have been a DC.




On 27 Mar 2020, at 14:13, Ray Mansell <[hidden email]> wrote:

Another surprise!  Consider this code:
num = int[10]
num[2] = 123
say num[2] num[3]

array=String[10]
array[2]='String'
say array[2] array[3]
Two arrays, both with 10 elements, both only partially initialised.
The first 'say' is successful, the second fails:
C:\NetRexx\user>java array01

123 0

Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)
This is terribly unsettling - surely it should always succeed, or always fail? And if it fails, a meaningful error message would be nice (e.g. "Attempt to access an unitilialised array element")

Thank you,
Ray


On 3/22/2020 16:23, René Jansen wrote:
I have to agree. I don’t know how much code will be broken if I catch that in Rexx.concat()  - if everybody observed the rule (stated in the Java docs themselves), to not depend on exception handlers for program flow, none. Show we should have a vote on that.

René.

On 22 Mar 2020, at 20:52, Ray Mansell <[hidden email]> wrote:

Thank you, René, I had suspected something like that in view of the messages. This rather goes against the grain of one of Mike's original principles "there should be no surprises", although of course I was bending the rules a bit.

Anyway, onward with the learning, and thanks again,

Ray

On 3/22/2020 15:45, René Jansen wrote:
Hi Ray,

good to see you here!

There is an explanation for this. ’Say’ has a safety against nullpointers. If you feed it a nullpointer, it will print you an empty line. Now in the second scenario, you concatenate ‘o’ with the nullpointer. The way this works, is that this ‘abuttal’ concatenation is called before the ’say’. This is done by the ‘concat’ method (netrexx.lang.Rexx.concat), which has no protection against nullpointers.

If you want to handle this, so your loop will end anyway, you can do this:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  do
    o = i':'
    say o array[i]
  catch NullpointerException
    say 'there was a null pointer'
  end
end


best regards,

René.

On 22 Mar 2020, at 20:13, Ray Mansell <[hidden email]> wrote:

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell

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



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


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



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


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



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

Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

Ray Mansell
Thanks again, René. I guess I'll just have to get used to it.

And yes, assembler is much easier than java, although I may be just a wee bit biased :-)

Ray

On 3/27/2020 09:32, René Jansen wrote:
Hi Ray,

sorry about that - Java is mostly to blame here. The reason here is that an int is a native type, while a String is a reference type - an Object.Native types have default values, 0 in the case of an int. Were you to repeat this with type Integer, you’d see the same error.

We are use to this, is my only excuse. If you were to tell me that assembler is easier than Java, I would have to agree, it is just so much work. But the general issue here, is that there should not be any uninitialized reference types in our code, and this is Java’s unhelpful way to express that. As I said earlier, we could protect all these things in NetRexx runtime but the resulting picture would not be of any more clarity.

When I have a nullpointer, I do:

➜  test git:(master) ✗ raytest3.class
   --- raytest3.nrx
 2 *=* num = int[10]
   >>> "10"
   >v> num "[I@5cad8086"
 3 *=* num[2] = 123
   >>> "2"
   >v> num "123"
 4 *=* say num[2] num[3]
   >>> "2"
   >>> "3"
   >>> "123 0"
123 0
 6 *=* array=String[10]
   >>> "10"
   >v> array "[Ljava.lang.String;@610455d6"
 7 *=* array[2]='String'
   >>> "2"
   >v> array "String"
 8 *=* say array[2] array[3]
   >>> "2"
   >>> "3"
Exception in thread "main" java.lang.NullPointerException
at netrexx.lang.Rexx.concat(Rexx.java:2261)
at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
at raytest3.main(raytest3.java:9)

So you’ll see that the dereferencing of array[3] is where it falls apart.
Exactly because of this reason, modern versions of languages have optional types; not surprisingly these have their own issues.

But just see it as if you did a DS where it should have been a DC.




On 27 Mar 2020, at 14:13, Ray Mansell <[hidden email]> wrote:

Another surprise!  Consider this code:
num = int[10]
num[2] = 123
say num[2] num[3]

array=String[10]
array[2]='String'
say array[2] array[3]
Two arrays, both with 10 elements, both only partially initialised.
The first 'say' is successful, the second fails:
C:\NetRexx\user>java array01

123 0

Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)
This is terribly unsettling - surely it should always succeed, or always fail? And if it fails, a meaningful error message would be nice (e.g. "Attempt to access an unitilialised array element")

Thank you,
Ray


On 3/22/2020 16:23, René Jansen wrote:
I have to agree. I don’t know how much code will be broken if I catch that in Rexx.concat()  - if everybody observed the rule (stated in the Java docs themselves), to not depend on exception handlers for program flow, none. Show we should have a vote on that.

René.

On 22 Mar 2020, at 20:52, Ray Mansell <[hidden email]> wrote:

Thank you, René, I had suspected something like that in view of the messages. This rather goes against the grain of one of Mike's original principles "there should be no surprises", although of course I was bending the rules a bit.

Anyway, onward with the learning, and thanks again,

Ray

On 3/22/2020 15:45, René Jansen wrote:
Hi Ray,

good to see you here!

There is an explanation for this. ’Say’ has a safety against nullpointers. If you feed it a nullpointer, it will print you an empty line. Now in the second scenario, you concatenate ‘o’ with the nullpointer. The way this works, is that this ‘abuttal’ concatenation is called before the ’say’. This is done by the ‘concat’ method (netrexx.lang.Rexx.concat), which has no protection against nullpointers.

If you want to handle this, so your loop will end anyway, you can do this:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  do
    o = i':'
    say o array[i]
  catch NullpointerException
    say 'there was a null pointer'
  end
end


best regards,

René.

On 22 Mar 2020, at 20:13, Ray Mansell <[hidden email]> wrote:

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell

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



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


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



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


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



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



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

Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

Jeff Hennick-3
In reply to this post by Ray Mansell

Ray,

Welcome!

My first thought on this is "Why 'int' and 'String'?"  Using these Java types means you are playing by Java's rules.  These should be used, rather than the default type of Rexx, only in special cases such as needing to interface with other Java classes or when high performance is mandatory.

The type Rexx is a "super string."  Use it as string or number (decimal, as many digits as needed).

But your question is valid, and likely should be considered a bug in SAY.

Jeff

On 3/27/2020 9:13 AM, Ray Mansell wrote:
Another surprise!  Consider this code:
num = int[10]
num[2] = 123
say num[2] num[3]

array=String[10]
array[2]='String'
say array[2] array[3]
Two arrays, both with 10 elements, both only partially initialised.
The first 'say' is successful, the second fails:
C:\NetRexx\user>java array01

123 0

Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)
This is terribly unsettling - surely it should always succeed, or always fail? And if it fails, a meaningful error message would be nice (e.g. "Attempt to access an unitilialised array element")

Thank you,
Ray


On 3/22/2020 16:23, René Jansen wrote:
I have to agree. I don’t know how much code will be broken if I catch that in Rexx.concat()  - if everybody observed the rule (stated in the Java docs themselves), to not depend on exception handlers for program flow, none. Show we should have a vote on that.

René.

On 22 Mar 2020, at 20:52, Ray Mansell <[hidden email]> wrote:

Thank you, René, I had suspected something like that in view of the messages. This rather goes against the grain of one of Mike's original principles "there should be no surprises", although of course I was bending the rules a bit.

Anyway, onward with the learning, and thanks again,

Ray

On 3/22/2020 15:45, René Jansen wrote:
Hi Ray,

good to see you here!

There is an explanation for this. ’Say’ has a safety against nullpointers. If you feed it a nullpointer, it will print you an empty line. Now in the second scenario, you concatenate ‘o’ with the nullpointer. The way this works, is that this ‘abuttal’ concatenation is called before the ’say’. This is done by the ‘concat’ method (netrexx.lang.Rexx.concat), which has no protection against nullpointers.

If you want to handle this, so your loop will end anyway, you can do this:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  do
    o = i':'
    say o array[i]
  catch NullpointerException
    say 'there was a null pointer'
  end
end


best regards,

René.

On 22 Mar 2020, at 20:13, Ray Mansell <[hidden email]> wrote:

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell

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



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


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



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



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


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

Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

rvjansen
On 27 Mar 2020, at 15:10, Jeff Hennick <[hidden email]> wrote:

But your question is valid, and likely should be considered a bug in SAY.

in concat.

Mike, what do you think about trapping this and making it succeed silently? It is about the semantics of a null pointer: would it be in the vein of Rexx to output ‘null’ instead of having the NullpointerException? But then, say says nothing when confronted with a singular null.

What does ooRexx do? There it will probably avoid a runtime error at all cost.

René.



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

Reply | Threaded
Open this post in threaded view
|

Re: Help for a NetRexx beginner

Ray Mansell
In reply to this post by Jeff Hennick-3
Jeff,

Thank you. I've been doing REXX for a very long time (1979 - I was privileged to work with both Mike and Simon in Hursley), and have only just got round to NetRexx, mostly so as to be able to use pipes on my Windows desktop. I was using examples from the Getting Started guide and from netrexx.org, which is where the array types were coded. Your explanation is very helpful, but even so, I find these inconsistencies irksome, although obviously I can live with them.

Ray

On 3/27/2020 10:10, Jeff Hennick wrote:

Ray,

Welcome!

My first thought on this is "Why 'int' and 'String'?"  Using these Java types means you are playing by Java's rules.  These should be used, rather than the default type of Rexx, only in special cases such as needing to interface with other Java classes or when high performance is mandatory.

The type Rexx is a "super string."  Use it as string or number (decimal, as many digits as needed).

But your question is valid, and likely should be considered a bug in SAY.

Jeff

On 3/27/2020 9:13 AM, Ray Mansell wrote:
Another surprise!  Consider this code:
num = int[10]
num[2] = 123
say num[2] num[3]

array=String[10]
array[2]='String'
say array[2] array[3]
Two arrays, both with 10 elements, both only partially initialised.
The first 'say' is successful, the second fails:
C:\NetRexx\user>java array01

123 0

Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)
This is terribly unsettling - surely it should always succeed, or always fail? And if it fails, a meaningful error message would be nice (e.g. "Attempt to access an unitilialised array element")

Thank you,
Ray


On 3/22/2020 16:23, René Jansen wrote:
I have to agree. I don’t know how much code will be broken if I catch that in Rexx.concat()  - if everybody observed the rule (stated in the Java docs themselves), to not depend on exception handlers for program flow, none. Show we should have a vote on that.

René.

On 22 Mar 2020, at 20:52, Ray Mansell <[hidden email]> wrote:

Thank you, René, I had suspected something like that in view of the messages. This rather goes against the grain of one of Mike's original principles "there should be no surprises", although of course I was bending the rules a bit.

Anyway, onward with the learning, and thanks again,

Ray

On 3/22/2020 15:45, René Jansen wrote:
Hi Ray,

good to see you here!

There is an explanation for this. ’Say’ has a safety against nullpointers. If you feed it a nullpointer, it will print you an empty line. Now in the second scenario, you concatenate ‘o’ with the nullpointer. The way this works, is that this ‘abuttal’ concatenation is called before the ’say’. This is done by the ‘concat’ method (netrexx.lang.Rexx.concat), which has no protection against nullpointers.

If you want to handle this, so your loop will end anyway, you can do this:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  do
    o = i':'
    say o array[i]
  catch NullpointerException
    say 'there was a null pointer'
  end
end


best regards,

René.

On 22 Mar 2020, at 20:13, Ray Mansell <[hidden email]> wrote:

After many years, I have at last started to learn  NetRexx, and am working my way through the QuickStart Guide. I didn't get very far before encountering a strange problem - or, more likely, I'm doing something wrong.

First, I used this example from the guide:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  say array[i]
end

I wondered what would happen if the array was not fully initialised, so I deleted the line that sets array[1], and again it worked, displaying a blank line for array[1].

Now I was curious as to whether or not anything at all was being printed for array[1], so I modified the program thus:

array=String[3] -- make an array of three Strings
array[0]='String one' --set each array item
-- array[1]='Another string'
array[2]='foobar'
loop i=0 to 2 -- display the items
  o = i':'
  say o array[i]
end

This is what happened:

java array01
0: String one
Exception in thread "main" java.lang.NullPointerException
        at netrexx.lang.Rexx.concat(Rexx.java:2261)
        at netrexx.lang.Rexx.OpCcblank(Rexx.java:1593)
        at array01.main(array01.java:8)

What am I doing wrong?

Ray Mansell

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



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


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



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



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


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



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

12