Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: variable scopes and recursive func

From: sags:apollo:lv at: 12-Apr-2005 23:06

> dir:/c/www/sitex/02setup/Test2/5/c/www/sitex/02setup/Test2/
^ Sorry, depth counter is working ! Janeks On 12 Apr 2005 at 21:25, [rebolist--rebol--com] wrote:
> Hi, Michael! > > What I want to get is negative depth counter and control to do > not iterate deeper than depth parameter. > And I actualy did the same like in your example. > All that rez variable is just for debugging and studying
purposes yet
> ;-) What is my problem - that in rez output I can't see the
depth
> variable from line: > repend rez [ "<br>dir:" join thisDir aFile depth + 1 ] > f.ex.: > dir:/c/www/sitex/02setup/Test2/5/c/www/sitex/02setup/Test2/ > 003.art > dirinfo.txt >
dir:/c/www/sitex/02setup/Test2/test3/6/c/www/sitex/02setup/Test2/ test3
> / 003.art dirinfo.txt > > At the end of line dir:... should be a number! > It is why I started to play with curDepth... > > Janeks > > On 12 Apr 2005 at 1:05, Michael Berg wrote: > > > > > Hi Janeks, > > > > why don't you simply use just the depth parameter to the
function
> > and if you recurse down the directory tree add always one to
the
> > depth value. Then you can do in the function whatever you
like with
> > the depth parameter and you don't need a local parameter.
It's
> > anyway not clear to me how your output is supposed to look
exactly.
> > > > What about this version, which works but still gives some
kind of
> > senseless output ? > > > > readChaptDir2: func [ thisDir depth > > /local rez bl > > ] [ > > rez: copy thisDir > > bl: sort read thisDir ;separate to be able to see what
happends
> > probe bl ;just for debugging repeat aFile bl copy/deep [ > > print aFile ;just for debugging > > either #"/" = last aFile [ > > repend rez [ "<br>dir:" join thisDir aFile depth + 1 ] > > repend rez readChaptDir2 join thisDir aFile (depth + 1 > > ][ > > repend rez [ <br> aFile ] > > ] > > > > ] > > return rez > > ] > > > > readChaptDir2 %somedir/ 0 > > > > > > > > Michael > > > > On Mon, 11 Apr 2005 23:55:54 +0300, <[sags--apollo--lv]> wrote: > > > > > > Thanks, Michael! > > > > > > Those bindings is unlear for me yet. > > > But at least those variable scopes stays more clearer. > > > > > > Now the function is working with "repeat" and sorting list
in a
> > > proper way. Now the problem is how to add depth counter: > > > > > > readChaptDir2: func [ thisDir depth > > > /local rez curDepth > > > ] [ > > > curDepth: depth - 1 > > > rez: copy thisDir > > > repeat aFile sort read thisDir copy/deep [ > > > either #"/" = last aFile [ > > > repend rez [ "<br>dir:" join thisDir
aFile
> > > curDepth ] > > > repend rez readChaptDir2 join thisDir
aFile
> > > curDepth > > > ][ > > > repend rez [ <br> aFile ] > > > ] > > > > > > ] > > > return rez > > > ] > > > > > > brgds > > > > > > Janeks > > > > > > On 11 Apr 2005 at 1:03, Michael Berg wrote: > > > > > >> > > >> Ok, last time - I hope. :-) > > >> > > >> If I'm right the reason why the error came up at the first
empty
> > >> directory and if there has been none, then only the first > > >> subtree is traversed, because of the recursive rebinding
of the
> > >> word 'aFile to the repeat block. While recursing down the
first
> > >> branch of the directory tree the block gets all the time
bound
> > >> to a new version of 'aFile. Upon returning back from the > > >> recursion the function one level up doesn't find any more
the
> > >> 'aFile > > >> from before the recursive call and thus the test doesn't
work or
> > >> even > > >> > > >> fails. Fails when 'aFile has been bound to no value in the > > >> recursion when the directory was empty or to the last
value of
> > >> the file in the deepest directory, which just gets added
as
> > >> often as during the walk up in the tree some files (no > > >> directories) are encountered, because always the second
block of
> > >> 'either gets executed. > > >> > > >> :-) > > >> > > >> Just a question to somebody who might know: One of the
reasons
> > >> why the > > >> binding mechanisms of Rebol are necessary is to make the > > >> keywordlessness possible, else something like 'repeat
wouldn't
> > >> be possible, right ??? But nevertheless I think these
binding
> > >> issues should be one of the first things to be explained
to a
> > >> newcomer. It is an important property of Rebol and should
be
> > >> treated like this. If there are chances to encounter these > > >> things in normal life they have to be explained
appropriately
> > >> already on the beginning and not on some articles
(Ladislavs
> > >> Bindology) or some sidenote in the documentation that a
function
> > >> changes it's body argument. Without deeper glue of Rebol
it's
> > >> hardly to get the reason and just simply using hints like
using
> > >> copy/deep on a block in some circumstances is hard to
remember
> > >> and hard to explain. Thus if Rebol is like this it should
be put
> > >> on the frontplate. ????!!!! > > >> > > >> Michael > > >> > > >> On Sun, 10 Apr 2005 23:43:04 +0300, Michael Berg
<[mokkel--gmx--de]>
> > >> wrote: > > >> > > >> > > > >> > :-) Sorry, I maybe posted it too fast. I'm still
searching for
> > >> > the the why. > > >> > > > >> > I think that's one of the bad parts of Rebol. This
dynamic
> > >> > binding might be powerful, but it causes a lot of
trouble as
> > >> > well. For instance besides your note, I don't get right
now why
> > >> > it for instance without copy/deep brings up an error
when it
> > >> > encounters an empty directory, und with copy/deep it
runs. (at
> > >> > least without the error message) > > >> > > > >> > Nevertheless it works with copy deep if you add in the
argument
> > >> > section a "/local rez". I think you forgot to make rez
local to
> > >> > the function as it is by standard global and gets
everytime
> > >> > deleted. :-) > > >> > > > >> > Michael > > >> > > > >> > On Sun, 10 Apr 2005 23:13:14 +0300, <[sags--apollo--lv]>
wrote:
> > >> > > > >> >> > > >> >> Thanks! > > >> >> I noted this (copy/deep), but now it is working without > > >> >> errors, but not corectly: First line is wrong - first > > >> >> directory of base dir is added, and then just files of
base
> > >> >> dir. > > >> >> > > >> >> brgds > > >> >> Janeks > > >> >> > > >> >> On 10 Apr 2005 at 22:44, Michael Berg wrote: > > >> >> > > >> >>> > > >> >>> Hi, > > >> >>> > > >> >>> if you change the repeat line to > > >> >>> > > >> >>> repeat aFile read thisDir copy/deep [ > > >> >>> > > >> >>> it will work, as repeat modifies the block to be
repeated.
> > >> >>> See also at
http://www.rebol.com/docs/words/wrepeat.html the
> > >> >>> user comment from Ladislav. > > >> >>> > > >> >>> Didn't know this myself - until now. :-) > > >> >>> > > >> >>> Michael > > >> >>> > > >> >>> > > >> >>> > > >> >>> On Sun, 10 Apr 2005 21:36:25 +0300, <[sags--apollo--lv]>
wrote:
> > >> >>> > > >> >>> > > > >> >>> > Hi, Rebolers! > > >> >>> > > > >> >>> > I am new in rebol scopes. So it seems, that it cause > > >> >>> > problems in my recursive directory reading function.
Could
> > >> >>> > somebody give me a bit more description about
variable
> > >> >>> > scopes in following case: > > >> >>> > > > >> >>> > readChaptDir2: func [ thisDir ] [ > > >> >>> > rez: copy thisDir > > >> >>> > repeat aFile read thisDir [ > > >> >>> > either #"/" = last aFile [ > > >> >>> > repend rez [ "<br>dir:" join
thisDir aFile ]
> > >> >>> > repend rez readChaptDir2 join
thisDir aFile
> > >> >>> > ][ > > >> >>> > repend rez [ <br> aFile ] > > >> >>> > ] > > >> >>> > > > >> >>> > ] > > >> >>> > return rez > > >> >>> > ] > > >> >>> > > > >> >>> > Looking forward, > > >> >>> > > > >> >>> > Janeks > > >> >>> > > > >> >>> > > >> >>> > > >> >>> -- > > >> >>> To unsubscribe from the list, just send an email to > > >> >>> lists at rebol.com with unsubscribe as the subject. > > >> >>> > > >> >>> > > >> >> > > >> >> > > >> >> > > >> > > > >> > > > >> > > >> > > >> -- > > >> To unsubscribe from the list, just send an email to > > >> lists at rebol.com with unsubscribe as the subject. > > >> > > >> > > > > > > > > > > > > > > > -- > > To unsubscribe from the list, just send an email to > > lists at rebol.com with unsubscribe as the subject. > > > > >
------- End of forwarded message -------