Added stack directive and global_pop function #93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
With your permission, I’d like to propose a small improvement to the bc syntax. I hope this won’t come across as too presumptuous.
There are several global variables in bc that affect a lot of things. Two of the most important are probably ibase and scale. Quite often, you have to save them at the beginning and restore them at the end of your functions, especially in library functions.
bc has a special flag that, if specified, changes this behavior — on entry to every function, the values of these and other global variables are pushed onto a special stack, and on exit they are restored from it.
But library functions, for universality, are still written without relying on this flag being set. For example, here’s a library function for cosine:
So, I thought it would be nice to have a directive that, when specified, always enables this stack for the function it marks; in addition, it would be useful to have a function that restores the values of global variables even before exiting the function. Sometimes this is necessary to return a number according to the parameters currently set in those variables.
With these new features, the cosine function would look like this: