rebol中的递归问题

时间:2010-03-21 11:05:56

标签: rebol

我有一个块,我想以递归方式迭代

folders: [
    Chrome [
        content [
            preferences
            prefpages
        ]
    ]
    icons [
        default
    ]
    locale [
        en-EN [
            csbar
        ]
    ]
    skin
]

使用此功能:

iterate-folder: func [folders [block!]][
    foreach folder folders [
        either not block? folder [
            probe folder
            temp: folder
            input
        ] [
            print "folder"
            probe folder
            print "folders"
            probe folders
            probe select folders folder
            type-folder: type? select folders folder
            probe type-folder
            input
            iterate-folder select folders folder
        ]
    ]
]

但由于愚蠢的原因我无法看到,探测文件夹上面没有返回任何内容,因此它不起作用。

1 个答案:

答案 0 :(得分:3)

选择文件夹文件夹正在弄乱它,我认为..... 文件夹已经是您想要的数据结构。

试试这个(请注意询问而非输入只是为了在此时添加调试字符串):

iterate-folder: func [folders [block!]][
    foreach folder folders [
        either not block? folder [
            probe folder
            temp: folder
            ask "continue/not block"
    ] [
            print "folder"
            probe folder
            print "folders"
            probe folders
            probe select folders folder
            type-folder: folder
            probe type-folder
            ask "continue/block"
            iterate-folder folder 
        ]
    ]
]