奇怪的 rebol bug:错误需要一个值

发布于 2024-08-10 02:16:28 字数 1254 浏览 4 评论 0原文

当执行

do-file: func[file][
  if error? error: try [
    if (find [%.r %.cgi] (suffix? file)) [
      do file
    ]
  ][
    disarm error
    print ["error executing " file]
    input
  ]
]


foreach-file: func [
    "Perform function on each file in selected directory recursively"
    dir [file! url!] "Directory to look in"
    act [function!] "Function to perform (filename is unput to function)"
    /directory "Perform function also on directories"
    /local f files
][
    if not equal? last dir #"/" [
      dir: to-rebol-file join dir #"/"
    ]
    files: attempt [read dir]
    either none? files [return][
        foreach file files [
            f: join dir file
            either dir? f [
                either directory [
                    act f
                    foreach-file/directory f :act
                ][
                    foreach-file f :act
                ]
            ][act f]
        ]
    ]
]

feach-file %test/ :do-file

where %test 将包含一个仅包含 rebo 标头的文件时:

rebol []

程序因错误而停止,而不是解除错误!

如果文件包含类似内容,它不会给出错误

rebol []

test: context []

,但如果它包含

rebol []

print ""

Why ,它会再次失败?

When executing

do-file: func[file][
  if error? error: try [
    if (find [%.r %.cgi] (suffix? file)) [
      do file
    ]
  ][
    disarm error
    print ["error executing " file]
    input
  ]
]


foreach-file: func [
    "Perform function on each file in selected directory recursively"
    dir [file! url!] "Directory to look in"
    act [function!] "Function to perform (filename is unput to function)"
    /directory "Perform function also on directories"
    /local f files
][
    if not equal? last dir #"/" [
      dir: to-rebol-file join dir #"/"
    ]
    files: attempt [read dir]
    either none? files [return][
        foreach file files [
            f: join dir file
            either dir? f [
                either directory [
                    act f
                    foreach-file/directory f :act
                ][
                    foreach-file f :act
                ]
            ][act f]
        ]
    ]
]

feach-file %test/ :do-file

where %test would contain a file with just rebo header:

rebol []

The program stops with an error instead of disarming the error !

It doesn't give an error if the file contains something like

rebol []

test: context []

but it would fail again if it contains

rebol []

print ""

Why ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夕嗳→ 2024-08-17 02:16:28

必须为设置的单词提供一个值,如下控制台会话所示:

<块引用>

a: func [] [#[未设置!]]
乙:一
** 脚本错误:b 需要一个值
** 近:b:a

解决方案是使用 set/any 而不是 set 词。

<块引用>

?放
用法:
设置字值 /any /pad

描述:
将单词、单词块或对象设置为指定值。
SET 是一个原生值。

论据:
word -- 要设置的一个或多个单词(类型:任意单词块对象)
value -- 值或值块(类型:任何类型)

改进:
/any——允许将单词设置为任何值。
/pad -- 对于对象,如果块太短,则剩余字设置为 NONE。

你可以使用类似的东西:

<块引用>

如果有错误? set/any 'error try [] [解除错误]
==无

顺便说一句,您可以通过 Rebol 邮件列表存档找到许多问题的答案,网址为 http://www.rebol.org/ml-index.r

A set word must be supplied with a value as illustrated by this console session:

a: func [] [#[unset!]]
b: a
** Script Error: b needs a value
** Near: b: a

The solution is to use set/any instead of a set word.

? set
USAGE:
SET word value /any /pad

DESCRIPTION:
Sets a word, block of words, or object to specified value(s).
SET is a native value.

ARGUMENTS:
word -- Word or words to set (Type: any-word block object)
value -- Value or block of values (Type: any-type)

REFINEMENTS:
/any -- Allows setting words to any value.
/pad -- For objects, if block is too short, remaining words are set to NONE.

You can use something like:

if error? set/any 'error try [] [disarm error]
== none

By the way, you can find the answers to many of your questions through the Rebol Mailing List Archive at http://www.rebol.org/ml-index.r.

放血 2024-08-17 02:16:28
do-file: func [ file
  /local err
][
  if error? set/any 'err try [
    if find [%.r %.cgi] suffix? file [
      do file
    ]
  ][
    print ["error executing " file]
    print mold disarm err
  ]
]

那些括号是不必要的。

这是另一种风格

do-file: func [file] [
    /local err
] [
    if error? set/any 'err try [
        all [
            find [%.r %.cgi] suffix? file
            do file
        ]
    ] [
        print ["error executing " file]
        print mold disarm err
    ]
]
do-file: func [ file
  /local err
][
  if error? set/any 'err try [
    if find [%.r %.cgi] suffix? file [
      do file
    ]
  ][
    print ["error executing " file]
    print mold disarm err
  ]
]

Those parentheses were unnecessary.

Here's an alternate style

do-file: func [file] [
    /local err
] [
    if error? set/any 'err try [
        all [
            find [%.r %.cgi] suffix? file
            do file
        ]
    ] [
        print ["error executing " file]
        print mold disarm err
    ]
]
梓梦 2024-08-17 02:16:28

成功创建文件时没有返回有效值。
set-word 需要一个值,而 set/any 可以接受任何值。

There is no a valid value returned when success do a file.
while set-word need a value, set/any can accept any value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文