  User login Username: * Password: Remember me Frontpage Sponsor   Poll How big is your Baan-DB (just Data AND Indexes)0 - 200 GB18%200 - 500 GB29%500 - 800 GB3%800 - 1200 GB8%1200 - 1500 GB8%1500 - 2000 GB13%> 2000 GB24%Total votes: 80

 Recursion Example
 By afsfan at 18 Apr 2008 - 16:34 What you have shown below is recursion all right - but it's recursion in 3 GL. The issue is when u try to call events recursively in 4GL - Thats when the "recursion not implemented" message has real value. In your code you are pretty much implementing recursion yourself - only using the system stack. It would be intresting to see if the same works for calling "Event Labels" in a wrapper! As many of you will already know, recursion is possible in Baan. Despite the 'Recursion not (yet) implemented' message that is sometimes shown when you actually try it. For example, the following works (meaning: I got something like this to work recently, the code below is untested as it stands):   `function long fact(long n) { f_arg = n return(fact_aux()) } long f_arg long f_ret | This function guarantees that f_arg is not changed. function long fact_aux() { if f_arg = 0 then f_ret = 1 else DEC(f_arg) f_ret = fact_aux() | since f_arg is global, we must set it back INC(f_arg) endif return(f_ret) }` Actually, this can be done slightly simpler by declaring the 'f_ret' variable as a static local variable:   ` function long fact(long n) { f_arg = n return(fact_aux()) } long f_arg | This function guarantees that f_arg is not changed. function long fact_aux() { static long ret if f_arg = 0 then ret = 1 else DEC(f_arg) ret = fact_aux() | since f_arg is global, we must set it back INC(f_arg) endif return(ret) }` However, it can be made a lot simpler by doing it as follows:   ` | This function must be called with one long argument. function long fact(...) { static long n n = get.long.arg(1) return(n = 0 ? 1 : n * fact(n - 1)) }` Or alternatively, using a macro:   `| This function must be called with one long argument. function long fact(...) { #define n get.long.arg(1) return(n = 0 ? 1 : n * fact(n - 1)) #undef n } Summarizing: Recursion is possible if you do not use explicit function arguments ('...' is allowed) do not use normal local variables ('static's are allowed) Have fun! (Now ask yourself: is recursion really the best way to compute the factorial function?)` Average: 0 No votes yet

All times are GMT +2. The time now is 21:39.