Hola, Fantam!

 /local dirtree [block!]

as far as I know, you only get to declare the 
type of params passed to be checked, not 
the type of a local var.  as somebody put it,
values are type-checked, not variables,
so it is even more reliable.

Here is the error I got when I ran what you posted:
** Script Error: append expected series argument of type: series port.
** Where: append dirtree dir/:name
list-dirs dir/:name

It appears that on the second call, when 
count = 1, then the local dirtree is not initialized,
and Rebol does not have a type for its unset value.
Therefore it complains about the type not being series value.

Obviously, if you remove the local declaration of dirtree,
then a global one works better.  It even accumulates all 
the whole tree.

But this one works without needing any global variables:

get-dirtree: func [
 "returns directory tree as block"
 startdir [file!] "starting directory"
 /local
 dirtree
 recursive-dirlist
][
 dirtree: make block! 100
 recursive-dirlist: func [
  dir [file!]
 ][
  foreach name read dir [
   if dir? dir/:name [
    append dirtree dir/:name
    recursive-dirlist dir/:name
   ]
  ]
 ]
 recursive-dirlist startdir
 dirtree
]

dir: %/c/temp/
print get-dirtree dir

This is a relatively simple example,
but I have often found that it is better 
to separate the pure recursive function from
the setup stuff that is actually invoked
during normal usage.

This simple function doesn't really require much 
setup, though, so you can just do this 
if you want a pure-recursive:

get-dirtree: func [
 "returns directory tree as block"
 dir [file!] "starting directory"
 dirtree  [block!]
][
 foreach name read dir [
  if dir? dir/:name [
   append dirtree dir/:name
   get-dirtree dir/:name dirtree
  ]
 ]
 dirtree
]

dir: %/c/temp/
print get-dirtree dir copy []

---------------------------------
You see, you just have to always remember to 
initialize and pass in the empty result block.

-Galt


>===== Original Message From [EMAIL PROTECTED] =====
>Hello all,
>In the following script, 'list-dirs is a function that returns the
>directory tree under the directory specified as an argument.
>On WinNT, using REBOL/Core 2.4.24.3.1, that script will throw an error
>when it encounters a directory that has a dot in its name (for
>example, "temp.old"). Furthermore, the error is thrown only if that
>directory is a second level sub-directory of the argument (for example
>"%/c/temp/temp1/temp.old" and not "%/c/temp/temp.old").
>The most confusing thing is that if I remove the local definition of
>'dirtree in the func spec, no error is thrown at all.
>I do not understand what is happening.
>
>REBOL []
>dir: %/c/temp/
>count: 0
>list-dirs: func [
>        "returns dir tree as block"
>        dir [file!] "root dir"
>        /local dirtree [block!]
>        ]
>        [
>  if count = 0 [dirtree: make block! 100]
>  count: count + 1
>  foreach name read dir [
>        if dir? dir/:name [
>                append dirtree dir/:name
>                list-dirs dir/:name
>      ]
>  ]
>        dirtree
>]
>print list-dirs dir
>halt
>
>--
>Fantam

Reply via email to