Quantcast
Channel: Jason Andrews Blog
Viewing all articles
Browse latest Browse all 33813

RE: variable scopes within cdf files

$
0
0
The callbacks are evaluated in the global scope. Because of this it doesn't matter where you define those constants, provided they are defined by the time the callback gets first executed. You should however ensure that any constants you define have a sufficiently unique name - we suggest using a prefix starting with an uppercase letter (since Cadence doesn't do that for its functions) for any global variables to avoid clashing with any other code. Alternatively, you could take advantage of SKILL++'s lexical scoping by creating all your callback functions in a file with the .ils suffix: let((const1 const2 const3) procedure(factorial(n "x") if(n>1 then n*factorial(n-1) else 1 ) ) const1=3.14159265358979323 const2=1.6180339887 const3=factorial(15) globalProc(MyCallback1() const1*const3 ) globalProc(MyCallback2() const1*const2 ) ) In the above, the three variables const1, const2, const3 are only visible within the scope of the block of text containing the let (hence the term lexical scoping). That means that they are visible in the locally defined functions too. The function factorial is truly local - can't be called from outside, whereas MyCallback1 and MyCallback2 are visible outside the let, but when they run, they can see any variables (or functions) within their lexical scope. This only works in SKILL++ mode (with the .ils suffix) because SKILL needs to know that this is defined with the different scoping rules (SKILL's normal scoping rule is dynamic scoping). Possibly more than you wanted to know, but it may help somebody! Regards, Andrew.

Viewing all articles
Browse latest Browse all 33813

Latest Images

Trending Articles



Latest Images