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
I can write the Traditional way
and it works with a Traditional Rexx call, but when I try
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/ |
Don’t worry, it is not something really easy. 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é.
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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:
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:
This is what happened:
What am I doing wrong? Ray Mansell _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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/ |
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é.
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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,
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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:
_______________________________________________ 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 |
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é.
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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, _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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/ |
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:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Ah .. OK.
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by rvjansen
Another surprise! Consider this code:
Two arrays, both with 10 elements, both
only partially initialised.
The first 'say' is successful, the
second fails:
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.
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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.
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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,
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
On 27 Mar 2020, at 15:10, Jeff Hennick <[hidden email]> wrote:
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/ |
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:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Free forum by Nabble | Edit this page |