2010-07-26 59 views
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>} 
>> 

回答

1

它看起来像一个绑定的问题。

我改变了这一行:

either error? set/any 'tmp try [do val] [ 

either error? set/any 'tmp e: try [do val] [ 

Ë持有错误,

>> e 
** Script Error: i has no value 
** Where: build-markup 
** Near: i n [ 
+0

噢,我的,如果它的结合我迷路了:)现在我应该怎么做什么? – 2010-07-27 20:01:03

+0

我不知道,对不起,我没有太多时间。但只是意识到,你有/重复完善,你也使用重复功能。这可能会导致问题。 – endo64 2010-07-29 10:58:23

+0

你是对的:)顺便说一下,我真的认为细化语法很糟糕:细化应该以某种方式输入。 – 2010-07-29 19:20:14