Rebol已经申请Creating map function in Red language什么相当于Rebol适用于Red?如果有的话?
答案 0 :(得分:2)
当前,红色没有本机apply
。您可以自己写apply
:
apply: func [
"Apply a function to a block of arguments"
fn [any-function!] "Function value to apply"
args [block!] "Block of arguments (to quote refinement use QUOTE keyword)"
/local refs vals val
][
refs: copy []
vals: copy []
set-val: [set val skip (append/only vals val)]
parse args [
some [
'quote set-val
| set val refinement! (append refs to word! val)
| set-val
]
]
do compose [(make path! head insert refs 'fn) (vals)]
]
它的工作方式与Rebol的apply
略有不同(因为我不喜欢Rebol的apply
语法)。如果您定义一些功能:
f: func [
foo
/bar
baz
][
reduce [foo bar baz]
]
然后是使用此apply
的方法:
>> apply :f [1 /bar 1]
== [1 true 1]
>> apply :f [quote /bar]
== [/bar false none]
>> apply :f [quote /bar /bar 1]
== [/bar true 1]
有关详细信息,请参见http://red.qyz.cz/apply-and-ufcs.html。