【发布时间】:2010-07-24 19:14:31
【问题描述】:
我尝试使用上一个答案向 build-markup 函数添加重复优化: How to bind to foreach context?
build-markup: func [
{Return markup text replacing <%tags%> with their evaluated results.}
content [string! file! url!]
/repeat block-fields block-values
/quiet "Do not show errors in the output."
/local out eval value
][
either not repeat [
content: either string? content [copy content] [read content]
out: make string! 126
eval: func [val /local tmp] [
either error? set/any 'tmp try [do val] [
if not quiet [
tmp: disarm :tmp
append out reform ["***ERROR" tmp/id "in:" val]
]
] [
if not unset? get/any 'tmp [append out :tmp]
]
]
parse/all content [
any [
end break
| "<%" [copy value to "%>" 2 skip | copy value to end] (eval value)
| copy value [to "<%" | to end] (append out value)
]
]
][
probe :block-fields
foreach :block-fields block-values [
print get pick :block-fields 1
print get pick :block-fields 2
]
]
out
]
c: [a b]
template: "<%a%> <%b%>"
build-markup/repeat template :c [1 2 3 4]
输出不是我想要的:
>> c: [a b]
== [a b]
>> template: "<%a%> <%b%>"
== "<%a%> <%b%>"
>> build-markup/repeat template :c [1 2 3 4]
[a b]
1
1 a b
1
1 a b
正如我所预料的那样
1
2
3
4
那我应该怎么改正呢?
【问题讨论】:
标签: rebol