2013-09-26 32 views
0

在下面的例子中,可查詢#q會被第二次評估嗎?什麼時候查詢表達式被調用?

local(max = 10, m = 5) 

local(q = with n in 1 to 10 select #n+#m) 

#q // 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 

if(true) => { 
    #q // is it invoke here like the above? 
} 

我懷疑沒有,但如果是這樣的話,它是調用查詢的#q-> asString?

回答

2

我認爲你是對的。這是一個簡單的測試,調用每次調用時遞增的計數器線程對象。

define test_count => thread { 
    data private val = 0 
    public asstring => { 
     .val += 1 
     return .val 
    } 
} 

local(max = 10, m = 5) 
test_count 

local(q = with n in 1 to 10 select #n+#m + integer(test_count -> asstring)) 
'<br />' 
test_count 
'<br />' 
#q 
'<br />' 
test_count 
'<br />' 
if(true) => { 
    #q 
} 
'<br />' 
test_count 

結果 - >

9,11,13,15,17,19,21,23,25,27

#q的第二次調用從不處理。但是,您可以強制它通過輸出來運行。

相關問題