u
and explicitly multiply all the coordinates by
u
. Is there a better way to do this in Asymptote?'.
A guide is an unresolved cubic spline (list of cubic-spline nodes and control points). A guide is like a path except that the computation of the cubic spline is deferred until drawing time (when it is resolved into a path); this allows two guides with free endpoint conditions to be joined together smoothly.
picture[] picture(int n) { picture[] pic; for(int i=0; i < n; ++i) { pic[i]=new picture; size(pic[i],19cm,0); } return pic; } picture[] pic=picture(6);
But for now you can at least say
typedef string T; include F; typedef real T; include F;where
F.asy
contains some type-dependent code like T[] operator $(T A, T B) {return new T[] {A,B};}
struct B { typedef void someroutine(B b); static struct A { someroutine routine; void operator init(someroutine routine) { this.routine=routine; } } string test="Testing"; } typedef B.A A; A a=B.A(new void(B b){write(b.test);}); B b; a.routine(b);
void f() { for(int i=0; i < 3; ++i) { static int n; ++n; write(n); } } f(); // Writes 1, 2, 3the static qualifier means that
n
is allocated not just outside of the for loop, but also outside the function. This is clear if you
call f
multiple times; there is still only one instance of
n
.
The "level" of a variable (where it is allocated) has nothing to do with the "scope" of a variable (how long it can be referred to by name). The curly braces enclosing a block affect only a variable's scope, not its level.
Static modifiers are meaningless at the top level; they generate a warning and are simply ignored:
for(int i=0; i < 3; ++i) { static int n; ++n; write(n); } // Writes warning about top-level static modifier and then 1, 1, 1Since version 1.22, non-static variables allocated in a loop body are allocated anew every iteration. This is only noticable in obscure cases where a variable in a loop is accessed in the closure of a function defined in the loop:
int f(); for(int i=0; i < 10; ++i) { int j=10*i; if(i == 5) f=new int() {return j;}; } write(f()); // Writes 50Variables in the body of a loop last as long as that iteration of the loop, unless they are kept alive by a function closure as in the example above. In a function body, variables will last at least as long as the function call, though because of closures and garbage collection, they may last longer than that. If defined at the top level of a file or at the interactive prompt, they will last at least until the end of the file or prompt's run.
https://asymptote.sourceforge.io/doc/Debugger.html
Asymptote - 2024-11-14