0

In the below example would the queryable #q be evaluated a second time?

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

I suspect not, but if that's the case is it #q->asString that invokes the query?

4

1 回答 1

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

结果->

1
2
9、11、13、15、17、19、21、23、25、27
13
14

对 #q 的第二次调用永远不会被处理。但是,您可以通过输出它来强制它运行。

于 2013-09-26T10:47:51.760 回答