ah good old recursive function :-)
Maybe you understand it better if you run this. You get a message at each stage the return value is formed.
Code:
DEFINE VARIABLE cTmp AS CHARACTER NO-UNDO.
FUNCTION rev RETURNS CHAR(INPUT ll AS CHAR).
MESSAGE cTmp
VIEW-AS ALERT-BOX INFO BUTTONS OK.
IF LENGTH(ll) = 1
THEN DO:
ASSIGN cTmp = ll + cTmp.
MESSAGE 'finally: ' + cTmp
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN ll.
END.
ELSE do:
ASSIGN cTmp = SUBSTRING(ll,1,1) + cTmp.
RETURN rev(SUBSTRING(ll,2)) + SUBSTRING(ll,1,1).
END.
END.
DISP rev("shireesh") cTmp.
In essence the function is called until the length of the input value is 1.
To show that, I introduced a variable cTmp which shows how the final return value is formed.
As you can see the function calls itself until the length of the input value is 1 and then it returns to the caller.
I hope this clarifies the function a bit more.
Casper.
Bookmarks