2009-08-23 14 views

答えて

1

悲しいことに、ビルドマークアップは、グローバル変数のみを使用しています:link text氏は述べています:タグ内で使用する変数は常にグローバル変数です注こと。

はここで内部オブジェクトを使用してそれを行うの少し不機嫌な方法です(BM-1は、問題を示します。aとbがそのグローバル値で印刷されている; BM-2は約不機嫌な作業です):

a: "global-a" 
b: "global-b" 


bm-1: func [a b][ 
     print build-markup "<%a%> <%b%>" 
    ] 

bm-2: func [a b][ 
    cont: context [ 
     v-a: a 
     v-b: b 
     ] 
     print build-markup "<%cont/v-a%> <%cont/v-b%>" 
    ] 

bm-1 "aaa" "bbb" 
bm-2 "aaa" "bbb" 

REBOL3は言い替えるではなくビルドマークアップを持っています。それはずっと柔軟です。

+0

あなたの不機嫌な方法を検討する、感謝:)ビバ:ここ

build-markup: func [ {Return markup text replacing <%tags%> with their evaluated results.} content [string! file! url!] /bind obj [object!] "Object to bind" ;ability to run in a local context /quiet "Do not show errors in the output." /local out eval value ][ content: either string? content [copy content] [read content] out: make string! 126 eval: func [val /local tmp] [ either error? set/any 'tmp try [either bind [do system/words/bind load val obj] [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) ] ] out ] 

は、いくつかの例では、建物内の企業ですR3! –

1

私は地元のコンテキストを使用できるようにするには、ビルド・マークアップ機能をパッチしました:

>> x: 1 ;global 
>> context [x: 2 print build-markup/bind "a <%x%> b" self] 
"a 2 b" 
>> print build-markup/bind "a <%x%> b" context [x: 2] 
"a 2 b" 
関連する問題