DesModder icon indicating copy to clipboard operation
DesModder copied to clipboard

Implicit multiplication in text mode

Open jared-hughes opened this issue 3 years ago • 6 comments

I keep wanting to use implicit multiplication in Text Mode.

IIRC, the original reasons why not were:

  1. If x y is supported for x*y, then it would seem like xy might be supported, but that's a two-letter variable instead of multiplying x and y.
  2. Problem with knowing when one line ends and the next line starts.

(2) is fixed now since it's clear with double-newline (or semicolon). (and was always a problem even without implicit multipication, e.g. a line y=f followed by a line (x+1)^2 could be parsed as y=f(x+1)^2)

(1) could be worked around by disallowing implicit identifier times identifier.

It would still be hugely beneficial to allow implicit multiplication for everything besides identifier times identifier:

  • y = x { x > 3 } would work
  • y = 2x^2 + 5x + 3 would work
  • (1,2,3) t would work

Note cross would be a keyword once implemented. So y = (1,2,3) cross (4,5,6) would not be parsed like y = (1,2,3) * cross * (4,5,6)

jared-hughes avatar Oct 07 '23 08:10 jared-hughes

(1) could be worked around by disallowing implicit identifier times identifier.

My main concern with this would be people inadvertently trying to do identifier times identifier and accidentally making a larger, compound identifier. In theory, this could be mitigated by recognizing that an identifier doesn't exist and seeing if it can be split apart into smaller identifiers that can be multiplied together, and then showing a specific error message if it can.

radian628 avatar Oct 07 '23 16:10 radian628

The worst case, though, is if the two identifiers merge into a single larger identifier that still "works" in the context in which it exists, effectively creating a silent error. E.g. trying to do a*b as ab when a variable ab is already defined.

radian628 avatar Oct 07 '23 16:10 radian628

Mathematica inserts a gray little multiplication icon when there's implicit multiplication image

If we do the same and be consistent that every implicit multiplication has a multiplication icon, then it'll be clear when a certain syntax isn't implicit multiplication (because it lacks the implicit multiplication symbol).

Problem is the lack of space: 2x{x>3} has two implicit multiplications but no space for such a symbol.

jared-hughes avatar Oct 07 '23 19:10 jared-hughes

I like the "multiplication icon" solution, though I don't see why that would break for 2x{x>3}. You'd need space to put two multiplication symbols there, but with codemirror embeds (kinda like what you do with booleans already) that should in theory be doable. I guess it could cause misalignment issues though if you ask me that's an acceptable sacrifice.

radian628 avatar Oct 07 '23 19:10 radian628

Alignment issues could be mitigated by having the multiplication symbols be in a monospace font.

radian628 avatar Oct 07 '23 19:10 radian628

Good point about the inline widgets. That was the plan anyways. Just forgot that an inline widget could be inserted that replaces nothing (if there's a space, the inline multiplication widget will replace one of the spaces).

jared-hughes avatar Oct 07 '23 20:10 jared-hughes