1. Recursion question?
- Posted by Tony Bucholtz <tony_bucholtz at HOTMAIL.COM> Dec 14, 2000
- 473 views
G'day all When a recusive function is used in Euphoria, are all the internal variables (including anything passed into the function) put in a stack of some kind? Ferinstance: <NONSENSE CODE> function myfunc(sequence bigseq) define another_bigseq define other variables do stuff to bigseq and another_bigseq if somecondition return(myfunc(another_bigseq)) else return(another_bigseq) end if end function </NONSENSE CODE> Do all the intermediate "values" of each iteration of the function (including the big sequences) get pushed onto a stack? Or do I have that wrong? TIA Regards Tony
2. Re: Recursion question?
- Posted by Graeme <graemeburke at CROSSWINDS.NET> Dec 14, 2000
- 447 views
- Last edited Dec 15, 2000
At 03:16 AM 14/12/00 -0500, you wrote: >G'day all > >When a recusive function is used in Euphoria, are all the internal >variables (including anything passed into the function) put in a stack of >some kind? Ferinstance: > ><NONSENSE CODE> >function myfunc(sequence bigseq) > define another_bigseq > define other variables > do stuff to bigseq and another_bigseq > if somecondition > return(myfunc(another_bigseq)) > else > return(another_bigseq) > end if >end function ></NONSENSE CODE> > >Do all the intermediate "values" of each iteration of the function >(including the big sequences) get pushed onto a stack? Or do I have that >wrong? > >TIA > >Regards >Tony > > Yes. Private variables are the property of each instance of a function and stay in memory until the termination of that instance. (cool huh?;) This recursive function returns a list of the full paths to all files in the directory passed and its subdirectories. include file.e function all_files(sequence path) -- no trailing '\' unless root dir i.e. c:\ sequence d,list list={} d=dir(path) for x=1 to length(d) do if find('d',d[x][2]) then if d[x][1][1]!='.' then list=list&all_files(path&'\\'&d[x][1]) end if else list=append(list,path&'\\'&d[x][1]) end if end for return list end function Graeme Burke ----------------------------------------------------
3. Re: Recursion question?
- Posted by Tony Bucholtz <tony_bucholtz at HOTMAIL.COM> Dec 14, 2000
- 457 views
On Thu, 14 Dec 2000 19:38:01 +1100, Graeme <graemeburke at CROSSWINDS.NET> wrote: >> >>When a recusive function is used in Euphoria, are all the internal >>variables (including anything passed into the function) put in a stack of >>some kind? Ferinstance: > >Yes. >Private variables are the property of each instance of >a function and stay in memory until the termination of >that instance. (cool huh?;) > G'day all Thanks, Graeme. Does that mean that a recursive function with *lots* of big sequences and recursed *lots* of times will eat up heaps of memory? My poor old P166 16Mb beast goes from slow to s...l...o...w after looping around one of these things for a while. I guess running out of RAM will do that :) Regards Tony
4. Re: Recursion question?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Dec 14, 2000
- 450 views
Tony, If recursion eats up too much memory in your machine, then maybe you could find another way to do what you want other than by recursion? That might take more code in source, but less in execution? Dan Moyer ----- Original Message ----- From: "Tony Bucholtz" <tony_bucholtz at HOTMAIL.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, December 14, 2000 5:26 AM Subject: Re: Recursion question? > On Thu, 14 Dec 2000 19:38:01 +1100, Graeme <graemeburke at CROSSWINDS.NET> > wrote: > > >> > >>When a recusive function is used in Euphoria, are all the internal > >>variables (including anything passed into the function) put in a stack of > >>some kind? Ferinstance: > > > >Yes. > >Private variables are the property of each instance of > >a function and stay in memory until the termination of > >that instance. (cool huh?;) > > > > G'day all > Thanks, Graeme. Does that mean that a recursive function with *lots* of big > sequences and recursed *lots* of times will eat up heaps of memory? My poor > old P166 16Mb beast goes from slow to s...l...o...w after looping around > one of these things for a while. I guess running out of RAM will do that :) > > Regards > Tony
5. Re: Recursion question?
- Posted by Graeme <graemeburke at CROSSWINDS.NET> Dec 15, 2000
- 459 views
At 08:26 AM 14/12/00 -0500, you wrote: >On Thu, 14 Dec 2000 19:38:01 +1100, Graeme <graemeburke at CROSSWINDS.NET> >wrote: > >>> >>>When a recusive function is used in Euphoria, are all the internal >>>variables (including anything passed into the function) put in a stack of >>>some kind? Ferinstance: >> >>Yes. >>Private variables are the property of each instance of >>a function and stay in memory until the termination of >>that instance. (cool huh?;) >> > >G'day all >Thanks, Graeme. Does that mean that a recursive function with *lots* of big >sequences and recursed *lots* of times will eat up heaps of memory? My poor >old P166 16Mb beast goes from slow to s...l...o...w after looping around >one of these things for a while. I guess running out of RAM will do that :) > >Regards >Tony > > Not Nesesarily. Euphoria is pretty tricky about how it copies sequences. Initially, it only copies a pointer to the sequence. The sequence will only be actually copied when one of the two(or more) variables that is assigned to it is modified. So basically if they're read only, you can make any number of copies of a sequence for virtually no memory overhead, you only 'pay' for the copy when you modify it. What are you doing? Will a local sequence of some kind that all instances can work on do the job? Graeme. ----------------------------------------------------
6. Re: Recursion question?
- Posted by Graeme <graemeburke at CROSSWINDS.NET> Dec 15, 2000
- 460 views
Also of note on sequences/pointers is their effect of large structure access, consider: for i = 1 to 10 do setText( textbox[i], myseq[x][y][z][i] ) end for now consider: sequence ptr ptr=myseq[x][y][z] for i = 1 to 10 do setText( textbox[i], ptr[i] ) end for myseq[x][y][z] is not copied. ptr is simply assigned as a pointer to that element, which is, of course a sequence in it's own right. now each time the loop executes it only looks up ptr...[i] Graeme. ----------------------------------------------------
7. Re: Recursion question?
- Posted by Tony Bucholtz <tony_bucholtz at hotmail.com> Dec 15, 2000
- 460 views
On Fri, 15 Dec 2000 00:47:55 +1100, Graeme <graemeburke at CROSSWINDS.NET> wrote: >At 08:26 AM 14/12/00 -0500, you wrote: >>On Thu, 14 Dec 2000 19:38:01 +1100, Graeme <graemeburke at CROSSWINDS.NET> >>wrote: >> <SNIP!> > >What are you doing? Will a local sequence of some kind >that all instances can work on do the job? > >Graeme. > >---------------------------------------------------- G'day all Graeme, I'm not doing anything serious with this, just experimenting with large sequences, and ran across the recursion issue sort of by accident. My original question was more out of curiousity than needing to "fix" something. Still, I've learnt from the replies I got, so thanks to you and Dan for the responses. Regards Tony