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

Add a `parser.getAll()` function which returns a list of all variables and functions currently in scope. #644

Closed
gbmhunter opened this Issue Apr 10, 2016 · 6 comments

Comments

Projects
None yet
2 participants
@gbmhunter

gbmhunter commented Apr 10, 2016

I think a parser.getAll() function which returns a list of all variables and functions currently in scope would be useful to developers. We can then display the list to the user, so the user has some feedback/guidance on what variables and functions he/she can currently use.

@gbmhunter gbmhunter changed the title from Add a `parser.getAll()` function which returns a list of all variable and functions currently in scope. to Add a `parser.getAll()` function which returns a list of all variables and functions currently in scope. Apr 10, 2016

@josdejong

This comment has been minimized.

Owner

josdejong commented Apr 10, 2016

That makes sense, thanks for your suggestion.

@josdejong josdejong added the feature label Apr 10, 2016

@gbmhunter

This comment has been minimized.

gbmhunter commented Apr 10, 2016

I don't know whether it would be best to add two separate functions:
parser.getAllVariables()
parser.getAllFunctions()
or to just return a single list/array:
parser.getAll()
and be able to determine whether it's a variable or function by inspecting a identifying member of each list/array element?

@josdejong

This comment has been minimized.

Owner

josdejong commented Apr 11, 2016

I don't think we should separate functions and variables. You can always filter this yourself if you need to.

I suppose parser.getAll() should just return the user defined functions and variables, not built-in functions like sin, sqrt, pi, etc. Like parser.get(name) only returns user defined variables too.

@gbmhunter

This comment has been minimized.

gbmhunter commented Apr 11, 2016

Yes, maybe it would be worth extending the function name to parser.getAllCustom() or something similar, to suggest it is not actually retrieving all functions and variables.

But then again, if parser.get() only returns user defined objects than it might better to keep it as just parser.getAll() to keep it inline with what is currently available.

@josdejong

This comment has been minimized.

Owner

josdejong commented Apr 15, 2016

But then again, if parser.get() only returns user defined objects than it might better to keep it as just parser.getAll() to keep it inline with what is currently available.

Yes I would let getAll only return custom defined variables. If you want to create a list of everything custom defined and built-in, you can do something like:

var custom = parser.getAll();
var everything = _.assign({}, math, custom); // use lodash assign
var names = Object.keys(everything);

@josdejong josdejong closed this in 6671681 Apr 16, 2016

@josdejong

This comment has been minimized.

Owner

josdejong commented Apr 16, 2016

I've implemented Parser.getAll() in v3.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment