Quite often Im using local procedures where I would like to return from the main procedure, but I cant put a
Return mainproc expression
inside a local procedure.
Sort of like the same thing you can do with cycle [label] but with return.
As far as I understand, Clarion does not allow GOTO outside its scope today. I think it is fine to do so. Knowing a Label outside the current scope is too dangerous. The same thing that can be done with a return can be done with a jump using a GOTO.
You wouldnt have to use it, but it would make my code simpler and easier to read because of the error checking Im now doing. A DABS defensive programming technique which can negate the need for a debugger even. Ive already found omitted() doesnt work if placed in a local procedure which only became detected with greater defensive programming techniques. The compiler never helped me in that situ and I wonder what else Ill find in the future.
just following on from this idea, you can choose to return multiple levels where you specify how many to return:
x long
code
x = myCalledProc()
if x < 0 then return x+1.
and have the same protocol up and down the chain, so if you want to return 3 levels, that is two extra levels over a normal single level return, so you say:
return -2
I was thinking if you allow the returning back without a specific protocol like that mentioned here, you might put some debug code in after a procedure call - but it never gets performed as it returns up multiple levels and you are left scratching your head. With the above idea, (whether you like the idea or not), it is at least apparent what is happening and you are not wondering why the code never seems to return from your procedure call (until an hour later you realize you were leap-frogged on a multi-level return).
So take the strposprocess proc Ive been working on recently. I return clarion errors as postive integers and my unit test fails and my code errors are returned as negative error codes.
A label would be a concious decision to return to the procedure name specified.
So I dont think a return -x would be useful as it prevents programmers from using negative error codes unless you are saying return -2 -7 ie two negative numbers where -2 is return two procedures and -7 is the negative errorcode?
you can only return one value from a procedure/function so the usual ways to get around this is to either pass parameters by reference (so you can return an altered value) or to have two numbers (of a given range) stored in one.
so say you wanted to have return values with a maximum range of ±1000
so for negatives that would be -1 to -999
so to your example of -2 -7 you could return -2007
so it can be done but possibly (probably?) more trouble than it is worth.
having said that you need to be careful of using modulus with negative numbers as there are two different conventions. There is a pragma compatible_modulus related to this:
#pragma define(compatible_modulus=> on | off )
Controls the sign of the result of modulus division.
If the pragma is set to zero (OFF), the modulus result
uses the sign of the divisor. If the pragma is set to
one (ON), the modulus result uses the sign of the
dividend.The default is off.
Example:
If compatible_modulus = 0, then
42 % -5 = -2 (-5 is the divisor(-) )
If compatible_modulus = 1, then
42 % -5 = 2 (42 is dividend (+))
I was questioning you. I know you can only return a single value, but if you happened to devise a method where you could combine two values into one and then decipher it on the otherside, yes it would be possible to return two values.
I know parameters passed by address can be used to pass a value back unlike the one way passed by value method.
Ive actually ditched the return of positive errors as clarion errors and negatives as my code and just gone with returning an error code which identifies the error with the info I need. Although ghidra and other tools can be used to look at the code, no point in giving too much away too easily.