Sophie

Sophie

distrib > Mageia > 6 > armv5tl > media > core-release > by-pkgid > 97aea805d7769ff00c42a2832ddab6a9 > files > 103

asymptote-2.41-1.mga6.armv5tl.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head><title>
Asymptote FAQ - Section 7
</title>
<link rev="made" href="mailto:">
<link rel="Contents" href="index.html">
<link rel="Start" href="index.html">
<link rel="Next" href="section8.html"><link rel="Previous" href="section6.html"><link rel="Bookmark" title="Asymptote FAQ" href="index.html">
</head><body text="#000000" bgcolor="#FFFFFF"><h1>
Asymptote FAQ - Section 7 <br>
Questions about programming
</h1>

<ul>
<li><a href="#comporint" rel=subdocument>Q7.1. Is Asymptote an interpreter or a compiler? 
</a>
<li><a href="#framepicture" rel=subdocument>Q7.2. What is the difference between a frame and a picture?
</a>
<li><a href="#pathguide" rel=subdocument>Q7.3. What is the difference between a path and a guide?
</a>
<li><a href="#picarray" rel=subdocument>Q7.4. What is a convenient way to declare and initialize an array of
pictures?</a>
<li><a href="#genarrays" rel=subdocument>Q7.5. Is there a way to define functions that act on arrays in general (i.e.
work for arrays of any type)?</a>
<li><a href="#cirdep" rel=subdocument>Q7.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?</a>
<li><a href="#static" rel=subdocument>Q7.7. Where are static variables in for loops allocated?</a>
<li><a href="#debug" rel=subdocument>Q7.8. Is there a debugger for asy?</a>
<li><a href="#patches" rel=subdocument>Q7.9. Do you accept patches for Asymptote?</a>
</ul><hr>

<h2><A name="comporint">
Question 7.1.  Is Asymptote an interpreter or a compiler? 

</A></h2>

Asymptote compiles Asymptote commands into its own virtual machine
code. It  then runs this pseudocode on a virtual machine to produce PostScript
code.  
<h2><A name="framepicture">
Question 7.2.  What is the difference between a frame and a picture?

</A></h2>

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 <A href="section8.html#unitsizes">Q8.8 `In MetaPost, it is possible to have a drawing remain the same size in
different pictures by defining a unit <code>u</code> and explicitly multiply all the coordinates by
<code>u</code>. Is there a better way to do this in Asymptote?'</A>.  
<h2><A name="pathguide">
Question 7.3.  What is the difference between a path and a guide?

</A></h2>

A path is a cubic spline with fixed endpoint conditions. 

<p>
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.  
<h2><A name="picarray">
Question 7.4.  What is a convenient way to declare and initialize an
array of pictures?
</A></h2>

You could write yourself a routine such as:
<pre>
picture[] picture(int n) { 
  picture[] pic;
  for(int i=0; i &lt; n; ++i) { 
    pic[i]=new picture;
    size(pic[i],19cm,0);
  } 
  return pic;
} 
 
picture[] pic=picture(6);
</pre>

<h2><A name="genarrays">
Question 7.5.  Is there a way to define functions that act on arrays
in general (i.e. work for arrays of any type)?
</A></h2>

Generic types aren't yet implemented.  
<p>
But for now you can at least say  <pre>
typedef string T;
include F;
 
typedef real T;
include F;
</pre>
where <code>F.asy</code> contains some type-dependent code like <pre>
T[] operator $(T A, T B) {return new T[] {A,B};}
</pre>

<h2><A name="cirdep">
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?
</A></h2>

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: 
<pre>
struct B { 
  typedef void someroutine(B b);
 
  static struct A { 
    someroutine routine;
    void operator init(someroutine routine) { 
      this.routine=routine;
    } 
  } 
 
  string test=&quot;Testing&quot;;
} 
 
typedef B.A A;
 
A a=B.A(new void(B b){write(b.test);});
 
B b;
a.routine(b);
</pre>

<h2><A name="static">
Question 7.7.  Where are static variables in for loops
allocated?
</A></h2>

In the example  <pre>
void f() { 
  for(int i=0; i &lt; 3; ++i) { 
    static int n;
    ++n;
    write(n);
  }
} 

f(); // Writes 1, 2, 3
</pre>
the static qualifier means that <code>n</code> is allocated not just outside of the for loop, but also outside the function. This is clear if you
call  <code>f</code> multiple times; there is still only one instance of
<code>n</code>.  
<p>
The &quot;level&quot; of a variable (where it is allocated) has
nothing to do with the &quot;scope&quot; 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.  
<p>
Static modifiers are meaningless at the top level; they generate a
warning and are simply ignored: <pre>
for(int i=0; i &lt; 3; ++i) { 
  static int n;
  ++n;
  write(n);
}
// Writes warning about top-level static modifier and then 1, 1, 1
</pre>
Since 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: <pre>
int f();
 
for(int i=0; i &lt; 10; ++i) { 
  int j=10*i;
  if(i == 5)
    f=new int() {return j;};
} 
 
write(f()); // Writes 50
</pre>
Variables 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. 

<h2><A name="debug">
Question 7.8.  Is there a debugger for asy?
</A></h2>

Yes, Asymptote includes a line-based debugger:

<p>
<A href="http://asymptote.sourceforge.net/doc/Debugger.html">http://asymptote.sourceforge.net/doc/Debugger.html</A> 
<h2><A name="patches">
Question 7.9.  Do you accept patches for
Asymptote?
</A></h2>

Yes, in fact we would prefer that users submit patches for customized
features (to <A href="http://sourceforge.net/tracker/?atid=685685&group_id=120000">http://sourceforge.net/tracker/?atid=685685&amp;group_id=120000</A>) instead of relying on us to do all of the coding. Development will
proceed  faster that way.  <hr>
Next: <a href="section8.html" rel=precedes>Questions about differences between Asymptote and MetaPost</a>.<br>
Back: <a href="section6.html" rev=precedes>Questions about 2D graphs</a>.<br>
<a href="index.html" rev=subdocument>Return to contents</a>.<p>
<address>
<A href="http://asymptote.sourceforge.net">Asymptote</A> 
- 24 March 2017
</address><br>
Extracted from Asymptote Frequently Asked Questions,
Copyright &copy; 2017 .
</body></html>