2010-07-26 4 views
0

J'ai essayé de générer dynamiquement le bloc d'actions dans le code ci-dessous (à partir de la version statique ici Extending Build-markup with repeat refinement) mais cela ne fonctionne pas pourquoi?Comment utiliser dynamiquement composer/only?

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 

Erreur de sortie:

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

Répondre

1

Il ressemble à un problème de liaison.

J'ai changé cette ligne:

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

à

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

e détient l'erreur,

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

Oh mon si elle est contraignante, je suis perdu :) Maintenant que dois-je faire ? –

+0

Je ne sais pas, désolé, je n'ai pas trop de temps. Mais juste réalisé que vous avez/raffinement de répétition et vous utilisez la fonction de répétition aussi. Cela peut entraîner un problème. – endo64

+0

Vous avez raison :) En passant, je pense vraiment que la syntaxe de raffinement est mauvaise: le raffinement devrait être en quelque sorte tapé. –

Questions connexes