Hi,
I am writing a rather large function and I ended up encountered the error 'branch.
So I have to break down my code in to smaller piece to avoid the max 255 offset problem…
The first thing I am trying is to move some of the code to a separated function. For instance,
Original code
fx:{ line1; line2; line3; line4…}
New code
gx:{line2;line3}
fx:{line1; gx x; line4…}
However, if a variable (e.g. lets call it var1) is defined in fx, there is no way I can modify it within gx (or I dont know the method…). So I ended up using this method.
New code 2
define var1 (in global)
gx:{line2;line3}
fx:{line1; gx x; line4}
However, in such case, all the modification made to var1 need to use the following statement
var1 set (value).
This is quite annoying as I usually use the assignment operator (:) for variable assignment. And so that sometimes I messed up.
My question is, am I using a correct method to deal with the max 255 offset block problem? Are there any common method that deal with the problem in a more elegant way?
Thanks so much
Gary
you would need to refactor your code into a smaller set of functions.
Simply splitting it up into functions of groups of lines is not necessarily going to work, as you have discovered.
And spilling into global namespace will restrict your code in future (e.g. not peachable).
How you do this will depend on your algorithm…
(As a point of practice, I don’t think I’ve hit the branch limit in over 10 years.)
Thanks Charles,
A follow up question…
I am working on a function that read some (add / del / mod) order book action from a binary file and based on those action, I need a sub-function to actually change the orderbook table for me. So I have something like this…
readAction:{
declare orderBookTable
loop to read action file
sub-functions to change orderBookTable..
}
So in such case, is that true I have no way to let my sub-function to change my orderBookTable if it is declared within the function “readAction”? So the only way I can handle this problem is to declare the orderBookTable in the root namesapce and pass the name of the table to subfunction?
Thanks
Gary
You could always pass along the value that you want to operate on, modify it in the subfunction, and return it for the next iteration. If you need multiple return values because of this, then you could return a list, or a dictionary, or some other composite structure. You should avoid modifying global variables, and in this case, it sounds like you can definitely avoid it.
Best,
Jose