vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
533 stars 89 forks source link

Feature request: `var oldAsin=asin;` copies the function #445

Closed user202729 closed 2 weeks ago

user202729 commented 2 months ago

Currently the behavior is

var g=asin;
    ^
a.asy: 1.5: could not infer type of initializer

If I understood correctly, the error will be raised when there are multiple overloads of the function in question (asin here). But in this case I think the reasonable option is to copy all options.

johncbowman commented 2 weeks ago

You can't copy all versions of asin to g. Here's an example of how to pick a particular one:

typedef real realfcn(real);
var g=(realfcn) asin;
charlesstaats commented 2 weeks ago

If I understand correctly, the feature request was that the line

var g = asin;

should create multiple variables named g, each with a different signature. We already do something like this with unravel and access; for instance, the line

from math access intersect as g;

will result in two different variables named g (with different signatures). So the proposed feature should definitely be possible to implement if we were sufficiently motivated.