为什么Rebol 3不接受带括号的带引号的函数参数? [英] Why doesn't Rebol 3 honor quoted function parameters that are parenthesized?

查看:108
本文介绍了为什么Rebol 3不接受带括号的带引号的函数参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DO方言使用PAREN类别的系列!优先级,通常会在调用函数之前将底层的括号结构煮掉.

The DO dialect uses series of category PAREN! for precedence, and will usually boil away the underlying parentheses structure prior to invoking a function.

但是,过去在Rebol 2中可能会在函数的定义中指定您希望其禁止在调用站点处对括号进行求值.您是通过在参数上使用文字"撇号来完成此操作的:

However, it used to be possible in Rebol 2 to specify in a function's definition that you wanted it to suppress evaluation of parentheses at the callsite. You did this by using a "literal word" apostrophe mark on a parameter:

evaluated: func [param] [probe param]

non-evaluated: func ['param] [probe param]

>> evaluated (1 + 2)
3

>> non-evaluated (1 + 2)
(1 + 2)

所以您通过了系列!类别类型,属于PAREN!类.在这种情况下,其中包含三个符号元素:1+2.这在Rebol 3中无效:

So you get passed a SERIES! category type, of class PAREN!...in this case with three symbolic elements inside: 1, +, 2. This does not work in Rebol 3:

>> non-evaluated (1 + 2)
3

这是错误还是有目的的设计决定?有解决方法吗?请注意,将引号运算符放在呼叫站点将不起作用,因为引号是符号词quote,然后是括号!自行求值,成为表达式的最终值:-/

Is this a bug or a purposeful design decision? Is there a workaround? Note that putting the quote operator at a callsite won't work, because then it's the symbolic word quote that gets quoted, and then the paren! gets evaluated on its own to become the final value of the expression :-/

>> non-evaluated quote (1 + 2)
quote
== 3

推荐答案

此参数传递类型的行为已被有意更改. (包括我在内的许多用户都要求进行更改).优点是您可以使用括号请求对此参数类型的求值(另一种请求求值的方法是使用get-word).如果您想传递真正未经评估的参数,请参阅以下内容:

The behaviour of this argument passing type has been changed on purpose. (Many users including myself requested the change). The advantage is that you can request evaluation for this argument type using parentheses (another way how to request evaluation is to use get-word). If you want truly unevaluated argument passing, see this:

quote: make function! [[
    "Returns the value passed to it without evaluation."
    :value [any-type!]
][
    :value
]]

与R2相比,这又是一个改进,R2的功能实际上并不完全相同.

That is again an improvement compared to R2, where such function does not really behave exactly the same way.

以防万一您真的想通过父母!您的函数,而又不想更改其定义以使用真正未评估的参数传递",则可以尝试以下操作:

And in case you really want to pass a paren! to your function while not wanting to change its definition to use "truly unevaluated argument passing" you can try this:

non-evaluated (quote (1 + 2))

这篇关于为什么Rebol 3不接受带括号的带引号的函数参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆