Hi,

> Hi all,
>
> A na�ve question : how do you define a local variable in a
function and
> then return it:
>
> Instead of this :
>
> dirtree: make block! 100
> list-dirs: func [
>         "returns dir tree as block"
>         dir [file!] "root dir"
>         ]
>         [
>         foreach name read dir [
>                 if dir? dir/:name [
>                    append dirtree dir/:name
>                    list-dirs dir/:name
>                 ]
>         ]
>         dirtree
> ]
>
> Something like this :
>
> list-dirs: func [
>         "returns dir tree as block"
>         dir [file!] "root dir"
>         ]
>         [
>         dirtree: make block! 100
>         foreach name read dir [
>                 if dir? dir/:name [
>                    append dirtree dir/:name
>                    list-dirs dir/:name
>                 ]
>         ]
>         dirtree
> ]
>
> Problem is that " print list-dirs %/root " only works with the
first block of code, not
> the second.
>
> What do I get wrong ?
> --
> [EMAIL PROTECTED]
> http://perso.worldonline.fr/mutant
>

You can do it as follows:

 list-dirs: func [
         "returns dir tree as block"
         dir [file!] "root dir"
        /local dirtree rlist-dir
 ] [
     dirtree: make block! 100
    rlist-dir: func [
        dir
    ] [
         foreach name read dir [
                 if dir? dir/:name [
                    append dirtree dir/:name
                    rlist-dir dir/:name
                 ]
         ]
         dirtree
    ]
    rlist-dir dir
 ]

Regards
    Ladislav


Reply via email to