0
我試圖在下面的代碼中動態生成動作塊(從靜態版本Extending Build-markup with repeat refinement),但它不工作,爲什麼?如何動態使用撰寫/只?
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
][
out: make string! 126
either not repeat [
content: either string? content [copy content] [read content]
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)
]
]
][
actions: copy []
n: length? block-fields
repeat i n [
append actions compose/only [
set in system/words (to-lit-word pick (block-fields) (i)) get pick (block-fields) (i)
]
]
append actions compose/only [
append out build-markup content
]
foreach :block-fields block-values actions
]
out
]
template1: { <td><%a%></td><td><%b%></td>
}
template2: { <tr>
<%build-markup/repeat template1 [a b] [1 2 3 4]%>
</tr>
}
template3: {<table>
<%build-markup/repeat template2 [a b] [1 2 3 4 5 6]%>
</table>}
build-markup template3
輸出錯誤:
>> build-markup template3
== {<table>
***ERROR no-value in: build-markup/repeat template2 [a b] [1 2 3 4 5 6]
</table>}
>>
噢,我的,如果它的結合我迷路了:)現在我應該怎麼做什麼? – 2010-07-27 20:01:03
我不知道,對不起,我沒有太多時間。但只是意識到,你有/重複完善,你也使用重複功能。這可能會導致問題。 – endo64 2010-07-29 10:58:23
你是對的:)順便說一下,我真的認爲細化語法很糟糕:細化應該以某種方式輸入。 – 2010-07-29 19:20:14