在 Rebol 中通过细化获取 Object 'Func
假设我有
o: context [
f: func[message /refine message2][
print [message]
if refine [print message 2]
]
]
我可以这样称呼它
do get in o 'f "hello"
但是我该怎么做才能细化呢?像这样的东西会起作用
>> do get in o 'f/refine "hello" "world"
** Script Error: in expected word argument of type: any-word
** Near: do get in o 'f/refine
>>
Let's say I have
o: context [
f: func[message /refine message2][
print [message]
if refine [print message 2]
]
]
I can call it like this
do get in o 'f "hello"
But how can I do for the refinement ? something like this that would work
>> do get in o 'f/refine "hello" "world"
** Script Error: in expected word argument of type: any-word
** Near: do get in o 'f/refine
>>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道是否有办法直接告诉解释器在调用函数值时使用细化。当它的参数是一个
函数时,这将需要对
类似的东西似乎不存在......但也许它隐藏在其他地方。do
进行一些参数化!我知道使用细化的唯一方法是使用路径。为了清楚起见,我将首先使用一个临时词:
组合后第二条语句的计算结果是:
您实际上也可以将函数值放入路径中。它消除了对中介的需要:
PS,上面的
message
和2
之间有一个额外的空格,它应该只是message2
I don't know if there's a way to directly tell the interpreter to use a refinement in invoking a function value. That would require some parameterization of
do
when its argument is afunction!
Nothing like that seems to exist...but maybe it's hidden somewhere else.The only way I know to use a refinement is with a path. To make it clear, I'll first use a temporary word:
What that second statement evaluates to after the compose is:
You can actually put function values into paths too. It gets rid of the need for the intermediary:
P.S. you have an extra space between
message
and2
above, where it should just bemessage2
执行此操作:
如果路径表达式中的括号对应于对象字段或系列拾取/戳索引引用,则对它们进行求值。这使得上面的代码等效于:
请注意,
apply
参数是位置性的,因此您需要知道声明参数的顺序。您无法通过函数细化本身来实现该技巧,因此如果您想参数化函数调用的细化,则必须使用apply
或创建路径表达式来评估。Do this:
Parens in a path expression are evaluated if they correspond to object field or series pick/poke index references. That makes the above code equivalent to this:
Note that
apply
arguments are positional, so you need to know the order the arguments were declared in. You can't do that trick with the function refinements themselves, so you have to useapply
or create path expressions to evaluate if you want to parameterize the refinements of the function call.使用简单路径 o/f/refine
Use the simple path o/f/refine