Re: converting sequence to string
- Posted by Nick Johnson <arachnid at MAD.SCIENTIST.COM> Mar 27, 2000
- 547 views
Bernie Ryan wrote: > On Sun, 26 Mar 2000 17:58:43 -0500, Irv Mullins <irv at ELLIJAY.COM> wrote: > > >You can do recursion without routine_id, because the function is declared > before > >the line that calls it. > > Irv: > > This is the example I was replying to: > -- > global function deNest(sequence nestedSequence) > --deNests a sequence by recursing through it and 'flattening' it > to 1 level > sequence outputSequence outputSequence = {} > for a=1 to length(nestedSequence) do > if not sequence(nestedSequence[a]) then > outputSequence = outputSequence&nestedSequence[a] > else outputSequence = outputSequence & > deNest(nestedSequence[a]) -- <<<<<<<<<<<<<<<<< --- look here > end if > end for > return outputSequence > end function > > If I run this in Euphoria how will Euphoria know what deNest function > looks like the first time in the first pass of the interpeter without > seeing the whole function first thats why I thought that a routine_id > function, a call_func function and routine_id variable is necessary. > This needs a forward reference to resolve this code so a Euphoria does > not error out on the first pass. > Maybe I'am wrong so straight my thinking out ? > Maybe you have a different trick to do this ? > > Bernie Weeeell, I tested the code here with a deeply nested sequence and it worked fine, no problems. My understanding is that because this function is being called from some code further down (what starts the whole thing), the function has already been read and tokenised into memory, so when you call it from the other code, the whole thing is already there and it can call it'self to hearts desire :) Nick