Asymptote FAQ - Section 7
Questions about programming


Question 7.1. Is Asymptote an interpreter or a compiler?

Asymptote compiles Asymptote commands into its own virtual machine code. It then runs this pseudocode on a virtual machine to produce PostScript code.

Question 7.2. What is the difference between a frame and a picture?

Frames are canvases for drawing in PostScript coordinates. While working with frames directly is occasionally necessary for constructing deferred drawing routines, pictures are usually more convenient to work with. See Q8.8 `In MetaPost, it is possible to have a drawing remain the same size in different pictures by defining a unit u and explicitly multiply all the coordinates by u. Is there a better way to do this in Asymptote?'.

Question 7.3. What is the difference between a path and a guide?

A path is a cubic spline with fixed endpoint conditions.

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.

Question 7.4. What is a convenient way to declare and initialize an array of pictures?

You could write yourself a routine such as:
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); 

Question 7.5. Is there a way to define functions that act on arrays in general (i.e. work for arrays of any type)?

Generic types aren't yet implemented.

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

Question 7.6. Is there any way to declare structures ahead of their definition, e.g. where struct A performs some operation on struct B, but B contains an A member?

Asymptote does not support forward declaration of types. You can, however, nest structures, so that both types are visible for parts of the bodies of both structure definitions. For example:
struct B { 
typedef void someroutine(B b); 
 
static struct A { 
someroutine routine; 
void init(someroutine routine) { 
this.routine=routine; 
} 
} 
 
A a=new A; 
string test="Testing"; 
} 
 
typedef B.A A; 
 
A operator init() {return new A;} 
B operator init() {return new B;} 
 
 
A a; 
a.init(new void(B b){write(b.test);}); 
 
B b; 
a.routine(b);

Question 7.7. Is there a debugger for asy?

Yes, Asymptote includes a line-based debugger:

http://asymptote.sourceforge.net/doc/Debugger

Question 7.8. Do you accept patches for Asymptote?

Yes, in fact we would prefer that users submit patches for customized features, instead of relying on us to do all of the coding. Development will proceed faster that way.
Next: Questions about differences between Asymptote and MetaPost.
Back: Questions about 2D graphs.
Return to contents.

Asymptote - 01 November 2006

Extracted from Asymptote Frequently Asked Questions, Copyright © 2006 .