manpagez: man pages & more
info asymptote
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.9.3 User-defined operators

The following symbols may be used with operator to define or redefine operators on structures and built-in types:

- + * / % ^ ! < > == != <= >= & | ^^ .. :: -- --- ++
<< >> $ $$ @ @@

The operators on the second line have precedence one higher than the boolean operators <, >, <=, and >=.

Guide operators like .. may be overloaded, say, to write a user function that produces a new guide from a given guide:

guide dots(... guide[] g)=operator ..;

guide operator ..(... guide[] g) {
  guide G;
  if(g.length > 0) {
    write(g[0]);
    G=g[0];
  }
  for(int i=1; i < g.length; ++i) {
    write(g[i]);
    write();
    G=dots(G,g[i]);
  }
  return G;
}

guide g=(0,0){up}..{SW}(100,100){NE}..{curl 3}(50,50)..(10,10);
write("g=",g);

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.