什么相当于Rebol适用于红色,如果有的话?

时间:2018-06-18 20:20:46

标签: rebol red

Rebol已经申请Creating map function in Red language什么相当于Rebol适用于Red?如果有的话?

1 个答案:

答案 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