如何动态使用 compose/only?

发布于 2024-09-12 05:26:12 字数 2052 浏览 3 评论 0原文

我尝试在下面的代码中动态生成操作块(从此处的静态版本 扩展构建-带有重复细化的标记)但它不起作用,为什么?

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>}
>>

I tried to generate the actions block dynamically in the code below (from static version here Extending Build-markup with repeat refinement) but It doesn't work why ?

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

Output error:

>> build-markup template3
== {<table>
***ERROR no-value in: build-markup/repeat template2 [a b] [1 2 3 4 5 6]
</table>}
>>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2024-09-19 05:26:12

这看起来像是一个绑定问题。

我更改了这一行:

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

to

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

e 保留错误,

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

It looks like a binding problem.

I changed this line:

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

to

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

e holds the error,

>> e
** Script Error: i has no value
** Where: build-markup
** Near: i n [
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文