Added stack directive and global_pop function#93
Added stack directive and global_pop function#93bolknote wants to merge 1 commit intogavinhoward:masterfrom
Conversation
|
I apologize for the long delay; there is a reason. I think the idea is sound, but I would prefer that the global popping actually happen in the That said, I really don't have the time or energy to handle this. I will leave it open in case anyone decides they really want it. |
|
Thanks for your reply and for explaining the situation. Totally understand, and I really appreciate all the work you’ve put into the project.
It seems I didn’t explain my idea clearly enough. |
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: