Closed Eswcvlad closed 4 months ago
this could cause backward-compatibility issues, if any new standard functions will be added
Two possible solutions:
preference?
If it was up to me, I would go with (1).
And, potentially, have something like "standard function names do not begin with _ (or $, not sure), so prefer such names, if possible". Might also have a potential side effect, that it will be easier to spot user-defined functions.
I was thinking, that a likely use case for register
would be to extract common expression parts under a short readable name, which goes against (2) somewhat.
I think I will also restrict the name construction to: /[_a-zA-Z][_a-zA-Z0-9$]*/
. i.e. a subset of identifier
We talked this over internally, and propose that we solve this by:
agreed
With the current implementation if you call
register
with an invalid function name, the call silently works without any warnings or errors. Ex.register("", &42)
,register("0foo", &42)
,register("фоо", &42)
.Would make sense to throw an error, if name does not match
[a-zA-Z_$][a-zA-Z0-9_$]*
for easier debugging.Another thing I've noticed, is that calling
register
with a name of an already existing function does not register the new function, with just a warning debug message shown. While I see the point, why we wouldn't want to allow overriding standard functions, this could cause backward-compatibility issues, if any new standard functions will be added. Ex. if there will be a document in the wild withregister("product", &@[0] * @[1])
included in the form and aproduct
function is added in the standard later, it will start failing.