Skip to content

Conversation

@bolknote
Copy link
Contributor

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:

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)
}

@gavinhoward
Copy link
Owner

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 return and return_void instructions.

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.

@bolknote
Copy link
Contributor Author

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.

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

Successfully merging this pull request may close these issues.

2 participants