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

Add function to reference results of previous lines #1

Open
sagebind opened this issue May 8, 2020 · 2 comments
Open

Add function to reference results of previous lines #1

sagebind opened this issue May 8, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@sagebind
Copy link
Owner

sagebind commented May 8, 2020

As suggested by users, we should provide a built-in function (or magic variable) that allows you to reference the result of a previous line in a subsequent formula, without having to first assign it to a variable.

Example:

24*2            = 48
L(1)+2          = 50

I see two possible designs for L(n):

  • Return the result of the current line - n
  • Return the result of the absolute line n
  • Return the nth previous result

The effective difference between the last two results is that whitespace and non-math lines would not be factored in for the purposes of counting n. The last option would be the most flexible if the user wanted to shift lines up and down in a document and keep referencing each other relatively, but the first option might be best if you wanted to re-order some lines while still referencing, say, line 2. It would be worth investigating what other scratchpad calculator apps do to see if there's a common assumption.

@sagebind sagebind added the enhancement New feature or request label May 8, 2020
@Stakker
Copy link

Stakker commented May 8, 2020

Followed the discussion here, since I can't reply to the Extension Marketplace review anymore :-) Thanks for the Numi tip! I already like it better than Soulver and I'm also an Alfred user, so that workflow is a big bonus.

The total sum of all the lines has been at least for me the most used feature in Soulver (and Numi has it too), so I would love to see that implemented here too, if possible. (It seems to me you're talking about referencing just one line here?)

Maybe something like a SUM keyword? Or just some dashes "-----"? Or simply start a new line with "="? The main issue of course is how to reference the lines. Absolute and relative lines both have the issue that if you add/remove lines, you may need to update the function. Some way to mark the start of the block of lines to be summed up would solve this.

How about starting the block with a #Heading, since it's markdown after all? (And ignore empty lines, just calculate the sum from #Heading to the keyword.)

Just throwing some ideas!

@Stakker
Copy link

Stakker commented May 8, 2020

The way Numi does this (as you probably know) is calculating all the lines above until an empty line:

Line 1: $10
Line 2: $15
Result: sum

Line 1: $10
Line 2: $20
Result: average

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants