Parsing 如何在REBOL中解析内部进行本地单词赋值?
我需要一个使用Parsing 如何在REBOL中解析内部进行本地单词赋值?,parsing,rebol,rebol3,Parsing,Rebol,Rebol3,我需要一个使用PARSE和COPY x规则的函数,但不在函数外部更改x。我试图使用功能让它自动拾取本地x,但它不起作用: >> f: function [t] [parse t [copy x to end]] >> f ["a"] == true >> print x a 使用函数,您已经完成了一半。您可以合并两个最近的更改: 一切就绪!s在主体中用作局部变量 复制和设置解析规则以同时接受SET word!这是他们的第一个论点 所以这会给你: ;; Not
PARSE
和COPY x
规则的函数,但不在函数外部更改x
。我试图使用功能
让它自动拾取本地x
,但它不起作用:
>> f: function [t] [parse t [copy x to end]]
>> f ["a"]
== true
>> print x
a
使用函数,您已经完成了一半。您可以合并两个最近的更改:
;; Note the subtle change of `x` to `x:` compared to your original version:
>> f: function [t] [parse t [copy x: to end]]
>> f ["a"]
== true
>> x
** Script error: x has no value
或者,也可以使用/local
约定显式列出局部变量:
>> f: function [t /local x] [parse t [copy x to end]]
>> f ["a"]
>> x
** Script error: x has no value
或者,你也可以用固定词在函数中,但在解析的外部
>> f: function [t] [x: none c: charset [#"a" -#"] parse t [copy x some c] print x]
>> f "a"
a
>> x
** Script error: x has no value
虽然这比其他备选方案有更多的开销,但如果这样使用,可能会有助于调试:
>> f: function [t] [x: 10101 c: charset [#"a" -#"z"] parse t [copy x some c] print x]
>> f ""
10101
这就很明显,这条规则没有抓住任何东西