我尝试用红色执行此脚本https://www.mail-archive.com/rebol-bounce@rebol.com/msg01222.html但我无法理解为什么
calc-workdays now / date 3-feb-2007 [1-feb-2007]
***脚本错误:>运算符缺少参数
***其中:做
*** Stack:打印calc-workdays
found?: func [
"Returns TRUE if value is not NONE."
value
][
not none? :value
]
calc-workdays: func [
"Return number of workdays between two dates, excluding holidays"
date1 [date!] "Start date"
date2 [date!] "End date"
holidays [block!] "Block of dates to exclude (holidays, etc.)"
/non "Return number of non-work days (weekend + holidays) between 2 dates"
/local days day1 day2 diff param
][
days: copy []
set [day1 day2] sort reduce [date1 date2]
diff: day2 - day1
param: pick [[> 5 union][< 6 exclude]] either found? non [1][2]
loop diff [
day1: day1 + 1
if do param/1 day1/weekday param/2 [append days day1]
]
return length? do param/3 days holidays
]
答案 0 :(得分:3)
Rebol2似乎允许你通过WORD!做,并评估它。如果这个单词恰好是一个包含ANY-FUNCTION!的变量,它将被运行......如果它是一个中缀&#34; OP!&#34;那么它就会像 not infix一样运行。
>> do quote > 1 2
== false
>> do quote < 1 2
== true
红色也是如此,但DO不是变量。它只能运行0个arity函数:
>> foo: does [print "hi"]
>> do quote foo
hi
>> bar: func [x] [print x]
>> do quote bar "hi"
*** Script Error: bar is missing its x argument
有问题的脚本试图使用此功能。但它可以用普通的COMPOSE或REDUCE来完成。所以改变:
if do param/1 day1/weekday param/2 [append days day1]
要:
if do reduce [day1/weekday param/1 param/2] [append days day1]
这将构建一个代码块,其中>
或<
运算符位于中间,并且正常执行它而不依赖于此WORD!-dispatch或DO的中继丢弃行为。< / p>
同样,改变:
return length? do param/3 days holidays
要:
return length? do reduce [param/3 days holidays]
通过这些更改,并删除found?
(没有必要),它似乎可以正常工作。