Rebol calc-workdays 不适用于红色
Rebol calc-workdays not working on Red
我试图以红色执行此脚本 https://www.mail-archive.com/rebol-bounce@rebol.com/msg01222.html,但我不明白为什么我得到
calc-workdays now/date 3-feb-2007 [1-feb-2007]
*** Script Error: > operator is missing an argument
*** Where: do
*** Stack: print 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
]
Rebol2好像可以让你传一个WORD!做,并评估它。如果这个词恰好是一个包含 ANY-FUNCTION! 的变量,它将是 运行...如果它是一个中缀 "OP!" 那么它将是 运行 就好像它是 不是中缀。
>> do quote > 1 2
== false
>> do quote < 1 2
== true
红色也这样做,但 DO 不是可变的。它只能 运行 0 个参数函数:
>> 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!-DO的dispatch或infix-dropping行为.
同样,更改:
return length? do param/3 days holidays
收件人:
return length? do reduce [param/3 days holidays]
通过这些更改,并删除 found?
(这不是必需的)然后它似乎可以工作。
我试图以红色执行此脚本 https://www.mail-archive.com/rebol-bounce@rebol.com/msg01222.html,但我不明白为什么我得到
calc-workdays now/date 3-feb-2007 [1-feb-2007]
*** Script Error: > operator is missing an argument
*** Where: do
*** Stack: print 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
]
Rebol2好像可以让你传一个WORD!做,并评估它。如果这个词恰好是一个包含 ANY-FUNCTION! 的变量,它将是 运行...如果它是一个中缀 "OP!" 那么它将是 运行 就好像它是 不是中缀。
>> do quote > 1 2
== false
>> do quote < 1 2
== true
红色也这样做,但 DO 不是可变的。它只能 运行 0 个参数函数:
>> 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!-DO的dispatch或infix-dropping行为.
同样,更改:
return length? do param/3 days holidays
收件人:
return length? do reduce [param/3 days holidays]
通过这些更改,并删除 found?
(这不是必需的)然后它似乎可以工作。