You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
define c(x){
auto b, s
b = ibase
ibase = A
s = scale
scale *= 1.2
x = s(2*a(1)+x)
scale = s
ibase = b
return(x/1)
}
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:
define stack c(x){
ibase = A
scale *= 1.2
x = s(2*a(1)+x)
global_pop()
return(x/1)
}
Thanks for your reply and for explaining the situation. Totally understand, and I really appreciate all the work you’ve put into the project.
I would prefer that the global popping actually happen in the return and return_void instructions.
It seems I didn’t explain my idea clearly enough. global_pop() is an optional construct. Without it, the values are restored from the stack automatically. global_pop() is only needed in cases where you want to restore the values earlier, as in my example above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: