Open sweihub opened 1 year ago
Thank you for the pull request.
I think it may make more sense to support a dot operator as an actual operator. So I would not merge this for now.
I thought over this issue, if we implement a dot operator, how do you expose the interface to programmer?
In object orienting world, we define a class, and a method, the compiler basically translates the method into a function: object_method(instance, args, ...)
, the object
is strongly typed, and the compiler knows the associated method. But I think evalexpr
should not go that far, otherwise we can use Lua or JavaScript for embedding script.
For example, how do you call method get()
for instance x
, the get()
method was not a defined function inside evalexpr
, we do not have a strongly typed associated method, this is a user defined method, we should have a way to let the user to implement.
data = (1, 2, 3);
x = data;
y = x.get();
So the most simple way is let the user to implement a dot(x, "get", args)
, you can name the function, but we must have a way. dot operator
to get field is another story we can implement later, like
(1, 2, 3, ,4).0
w = { x:1, y:2, z:3}; a = w.x;
I would have an usecase for this in dezoomify-rs, to solve https://github.com/lovasoa/dezoomify-rs/issues/222
I think the simplest way would be to copy Rust: the expression a.f(b)
is equivalent to calling f(a, b)
.
How do you disambiguate from a.f(b) + f(x, b)
? if translate a.f(b)
to f(a, b)
?
You already have some built-in functions, so just let user to implement a dot function dot(self, args, ...)
is the simplest way.
I already forked the evalexpr
with the dot operator support, and it helps me a lot to implement simple object oriented. Who ever needs this feature, please use my fork.
https://github.com/sweihub/evalexpr
example
x = market("HSI2408");
a = x.ask + 0.01;
(a, x.bid, x.mid, x.last)
Currently, evalexpr
allows var.names.ok
for vars and I have a ton of them.
The introduced feature breaks the functionality. I suppose, according to SemVer, you should not merge it in the "next" release.
in my case I have variables starting with '.', they are debugger symbols like '._main', please dont break that
Hi @ISibboI
Would you review and merge this? Once the dot operator supported, we can do object like expressions, a quick glance:
The full test