Similarity of Julia to Asymptote Programming Language

I am just getting started in Julia but am very familiar with the Asymptote graphics program scripting language -

Asymptote

It seems to me that the Asymptote language has many of Julia’s features and is similar (nowhere near as extensive). I wondered what the opinion is of those who are more familiar with Julia and Asymptote.

What features do you see in common? I’m not familar with Asymptote, but the syntax and code samples I’m seeing on their site remind me of LaTeX/TikZ more than anything else.

Multiple dispatch and strong typing for example. Asymptote does not have classes just structures but I can emulate a class using their structures. Here is some of my Asymptote code that is more Julia like (mainly overloading operators) -

// Conveinence Functions for Real Functions

typedef real REALFCT(real x);

REALFCT operator|(REALFCT f,REALFCT g) // f(g(x))
{
return new real(real x) {return f(g(x));};
}

real[] operator|(REALFCT f,real[] x) // f(x[])
{
real[] f_of_x;

for (int i=0; i < x.length; ++i)
{
f_of_x.push(f(x[i]));
}

return f_of_x;
}

REALFCT operator*(REALFCT f,REALFCT g) // (f*g)(x) = f(x)*g(x)
{
return new real(real x) {return f(x)*g(x);};
}

REALFCT operator*(real a,REALFCT g) // (a*g)(x) = a*g(x)
{
return new real(real x) {return a*g(x);};
}

REALFCT operator*(REALFCT g,real a) // (g*a)(x) = a*g(x)
{
return new real(real x) {return a*g(x);};
}

REALFCT operator+(REALFCT f,REALFCT g) // (f+g)(x) = f(x)+g(x)
{
return new real(real x) {return f(x)+g(x);};
}

REALFCT operator+(real a,REALFCT g) // (a+g)(x) = a+g(x)
{
return new real(real x) {return a+g(x);};
}

REALFCT operator+(REALFCT f,real a) // (f+a)(x) = f(x)+a
{
return new real(real x) {return f(x)+a;};
}

REALFCT operator-(REALFCT f,REALFCT g) // (f-g)(x) = f(x)-g(x)
{
return new real(real x) {return f(x)-g(x);};
}

REALFCT operator-(real a,REALFCT g) // (a-g)(x) = a-g(x)
{
return new real(real x) {return a-g(x);};
}

REALFCT operator-(REALFCT f,real a) // (f-a)(x) = f(x)-a
{
return new real(real x) {return f(x)-a;};
}

REALFCT linmap(pair Int,pair Int1) // Linear map from interval Int to interval Int1
{
real dy = Int.y-Int.x;
real dy1 = Int1.y-Int1.x;
real a = dy/dy1;

return new real(real y1) { return a*(y1-Int1.x)+Int.x;};
}

real linterp(pair pt1,pair pt2,real x) // Linear interpolate between pt1 and pt2
{
real dx = pt2.x-pt1.x;
return pt2.y*((x-pt1.x)/dx)-pt1.y*((x-pt2.x)/dx);
}

struct PieceWiseFunction
{
real[] X;
REALFCT[] F;
int Nx1;
int Nf1;

void init(real[] x, REALFCT[] f)
{
X = x;
F = f;
Nx1 = x.length-1;
Nf1 = f.length-1;
}

real f(real x)
{
int ix = search(X,x);
if (ix==-1)
{
return F[0](x);
}
if (ix==Nx1)
{
return F[Nf1](x);
}
return F[ix+1](x);
}
}

It looks like Asymptote is a statically typed language, not a dynamically typed language (ala Julia)? And it only supports something like C++'s static overloading, which is different from multiple dispatch (ala Julia). For example, according to the Asymptote manual, you can’t add new methods (new signatures) to an existing function and affect other functions that were declared previously:

However, if f is overloaded by a new function definition, previous calls will still access the original version of f

See this talk on why dynamic multiple dispatch semantics (ala Julia) are distinct from static overloading (ala C++ function overloading).

So, it seems like a very different language. (Of course, you can still find commonalities.)

6 Likes

You can still use a Julia version of Asymptote, AsyPlots.jl GitHub - sswatson/AsyPlots.jl: A Julia package for making figures with Asymptote and Cairo

2 Likes