expr icon indicating copy to clipboard operation
expr copied to clipboard

Explain mode

Open alexec opened this issue 4 years ago • 9 comments

I'd like to explain to users how a result was calculated:

Say we have this expression, this is what it would print out:

  • c + p / e + P / (n * e)
  • 2 + 100 / 250 + 2500 / (10 * 250)
  • 2 + 0 + 1
  • 3

alexec avatar Aug 16 '21 15:08 alexec

Nice idea, but currently I don’t a free time to wolf on it. Somebody else?

antonmedv avatar Aug 16 '21 16:08 antonmedv

"wolf"? 🐺

alexec avatar Aug 16 '21 16:08 alexec

Now working on profiler for Expr. Maybe it also can be used here.

antonmedv avatar Nov 05 '22 19:11 antonmedv

I'd also really like to see this feature. I'm willing to help/try doing it myself, but I don't even know where to start. Care to give me some ideas to put me on the right path?

gbgil avatar Jan 08 '23 19:01 gbgil

Start with opcode)

antonmedv avatar Jan 08 '23 20:01 antonmedv

I have some progress on the feature:

-((2 - 5) ** 3) - 2 / (+4 - 3) + -2
-(-3 ** 3) - 2 / 1 + -2
--27 - 2 + -2
25 + -2
23
reduce(filter(map(map(6..9, # - 2), # * 2), # > 6), #acc + #, -2)
reduce(filter(map(map([6,7,8,9], # - 2), # * 2), # > 6), #acc + #, -2)
reduce(filter(map([4,5,6,7], # * 2), # > 6), #acc + #, -2)
reduce(filter([8,10,12,14], # > 6), #acc + #, -2)
reduce([8,10,12,14], #acc + #, -2)
42
foo < 0 or (bar > 10 and baz == 5) or (qux <= 1 and quux >= 10 and corge > 0.5)
1 < 0 or (99 > 10 and 50 == 5) or (25 <= 1 and 10 >= 10 and 5 > 0.5)
false or (true and false) or (false and true and true)
false or false or (false and true)
false or false
false
garply.a + fn(grault[0] + 1)
1 + fn(1 + 1)
1 + fn(2)
1 + 2
3

antonmedv avatar Jan 17 '24 22:01 antonmedv

This sounds useful, @antonmedv 👍🏻

PranavPeshwe avatar Jan 18 '24 03:01 PranavPeshwe

How does one get/see the output you've shared?

PranavPeshwe avatar Jan 18 '24 03:01 PranavPeshwe

I’m working on this picture as part of Expr Pro package 📦

I will share results little bit later. It’s going to be an addition to Expr.

antonmedv avatar Jan 18 '24 09:01 antonmedv

Explain mode is done!

Now it comes in Expr Pro extension: https://expr-lang.org/expr-pro

antonmedv avatar Jan 23 '24 23:01 antonmedv