gavinhoward / bc

An implementation of the POSIX bc calculator with GNU extensions and dc, moved away from GitHub. Finished, but well-maintained.
https://git.gavinhoward.com/gavin/bc
Other
145 stars 29 forks source link

Allowing redefinition of builtin function such as abs() for compatibility with bc scripts #77

Closed oliverkwebb closed 2 months ago

oliverkwebb commented 2 months ago

First I'd like to thank you for the work and care in making bc.

I replaced GNU bc with your bc on my system, and ran into a error trying to run bc with some external bc libraries that define functions such as abs()

This is because your bc already has a built in abs(), and unlike the functions in the -l math library, will not let you redefine it because it appear to not just be a function, but also a lexer tokens/keyword.

Is this a problem that you've ran into or considered before?

gavinhoward commented 2 months ago

Yup! And my bc already has a solution:

$ bc -r abs <other_args...>

See here, scroll to the -r/--redefine option.

In short, it allows you to "redefine" keywords as functions, variables, or arrays.

Of course, if that doesn't fix your problem, then it is a bug.

oliverkwebb commented 2 months ago

Putting -r abs in my function arguments will run the library.

Thank you for your help