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 docs #4

Open
talamaska opened this issue Feb 17, 2014 · 2 comments
Open

More docs #4

talamaska opened this issue Feb 17, 2014 · 2 comments

Comments

@talamaska
Copy link

Hello, I'm very interested into using this library for parsing custom math expressions.
I'm planning to have Web ui for creating those, and save them into my database.
the question that bothers me is about the variables. I guess I could save them separately and input them into the evaluate with .set('x',3).
Then if I have expression x**2-PI which result in calculation Math.pow(3,2)-Math.PI.
I'm not quite sure how to set PI or E in the expression string.

@l8nite
Copy link
Owner

l8nite commented Feb 18, 2014

Hey Talamaska, the "Math.PI", etc are defined in lib/Constants.js -- those should just work out of the box. The list supported is: ['E', 'LN2', 'LN10', 'LOG2E', 'LOG10E', 'PI', 'SQRT1_2', 'SQRT2']

For the variables, you'll want to look into overriding the lib/Variables.js class (in particular, the "load" and "save" methods) so that you can store them wherever you wish. I would recommend something like Redis as a quick&dirty in-memory storage solution that should perform well for you.

The way it was currently designed, the variables are intended to be "shared" (this was used in an IRC bot, so multiple users in the same channel would have the same value for "x"). If you want the variables to be user-specific for your website, you're going to need to add some additional plumbing to your customizations so that you can pass a user identifier along with the variables to get/set/save/load.

@l8nite
Copy link
Owner

l8nite commented Feb 20, 2014

Yea, per-instance is not a bad idea. It was never intended to be used as
such when I was toying around, but I can see the point. Fork it and send
me a pull request? :)

Definitely agree on semantic versioning.

Shaun

On Tue, Feb 18, 2014 at 12:09 AM, Konrad Borowski
[email protected]:

I think that variable sharing is a bug, but one that could be difficult to
fix, and it's something that would require version bump to 2.0.0(assuming you follow semantic versioning, which is preferred versioning
scheme for Node.js libraries).

Instead, it could have used object oriented interface, which stores only
between instances. If the compatibility is a concern, and you don't want to
bump the version to 2.0.0, you may support both interfaces. No need to
worry about my IRC bot, it can handle with such scenario.

Reply to this email directly or view it on GitHubhttps://github.com//issues/4#issuecomment-35361186
.

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

2 participants