Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more flexible to_string conversion to support ternary operators #24

Open
jonas-eschle opened this issue Jun 19, 2020 · 0 comments
Open

Comments

@jonas-eschle
Copy link
Contributor

jonas-eschle commented Jun 19, 2020

First of, thanks a lot for this great package!

Numexpr supports where whereas ROOT supports an (equivalent) ternary operator from C++ (Expression1 ? Expression2 : Expression3). While the former is already implemented and works fine with the current function registry, the latter cannot (AFAIK) be supported with the current construction of joining the arguments withing brackets with ,.

Two ideas (using as an example sqrt):

  1. To enable support for this conversion, I would propose a to_string method that can be registered with the function in PFunction. Defaults to the current conversion. This takes the name of the method and arguments.
    Disadvantage: we have too much freedom (e.g. for sqrt:
    ('sqrt', 1, lambda f, args: f + "(" + args[0] + ")")
    or duplicate the name
    ('sqrt', 1, lambda args: 'sqrt' + "(" + args[0] + ")").

  2. use string formatting: require the signature to be contained in the string definition: '(sqrt({})', 1).
    Disadvantage: arbitrary number of arguments?

I would propose to go for the first solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant