mathpad icon indicating copy to clipboard operation
mathpad copied to clipboard

Add function to reference results of previous lines

Open sagebind opened this issue 4 years ago • 2 comments

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 avatar May 08 '20 14:05 sagebind

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 avatar May 08 '20 16:05 Stakker

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

Stakker avatar May 08 '20 16:05 Stakker