Skip to content
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

feature request: formulae #3

Open
cowens opened this issue Feb 22, 2011 · 2 comments
Open

feature request: formulae #3

cowens opened this issue Feb 22, 2011 · 2 comments

Comments

@cowens
Copy link

cowens commented Feb 22, 2011

I understand the desire to avoid functions, but they do allow code reuse. A happy medium would be formulae, that is names attached to a specific expression. It could be as simple as

> sqr := a * a
formula sqr created
> a = 5
ans = 5.0
> sqr
ans = 25.0

or, with a little more work, as nice as

> sqr(a) := a * a
formula sqr created
> sqr(5)
ans = 25.0
@gregsexton
Copy link
Owner

Let me think about this one! Obviously, I pointed out in the help file why I didn't want to go down the path of user defined functions. I do quite like the idea, however, of labelled expressions that can be re-evaluated by evaluating the label.

The problem with adding parameters, your second example, is to do with complexity. With the first example it is obvious that a is a global and there is only one global scope. By adding parameters you would really then need to then add lexical scope.

Without conditionals recursion doesn't make sense either and so is an issue and would need to be handled carefully.

In the meantime: you can hit enter on an old expression to have it re-evaluate with any newly-bound variables.

@mMontu
Copy link

mMontu commented May 7, 2012

Another approach could be defining new functions through vim script.
Currently I'm doing this through Ctrl-r =, but this leaves no history of the function called or its parameters.

One possibility is that function sqr() is defined on .vimrc and it is called on VimCalc inside single quotes:
> 'x = sqr(a)'
x = 9

For sure the computation inside sqr() would be restrict to the floating point limits of vim instead of python, but I believe that would still be helpful.

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

No branches or pull requests

3 participants