scicloj / wolframite

An interface between Clojure and Wolfram Language (the language of Mathematica)
https://scicloj.github.io/wolframite/
Mozilla Public License 2.0
56 stars 2 forks source link

Multi-argument failure of Wolfram functions #63

Closed light-matters closed 2 months ago

light-matters commented 4 months ago

For future decision, I'm separating this from the pull request that was merged.

(wl/eval (w/-)) => ERROR
(wl/eval (w/- 5 4 3)) => ERROR
(wl/eval '(w/- 5 4 3)) => ERROR
(wl/eval (w/Subtract 5 4 3)) => (Subtract 5 4 3)
(wl/eval '(w/Subtract 5 4 3)) => (Subtract 5 4 3)

with ERROR

1. Unhandled java.lang.IllegalArgumentException
   Can't handle more than 2 arguments

Note that the error message is not strictly true for the first example.

Here, we see that passing the wrong number of arguments to Wolfram functions does not fail in the way that it would if it was done directly in a Wolfram system. Using a higher-level Wolfram abstraction (-) in the Clojurey way however, does. This may end up being desired behaviour, but using '-' from within Mathematica will only fail if there is nothing else at all in the cell (incomplete expression) and will otherwise work as Subtract or Minus depending on the context.

holyjak commented 2 months ago

Hm, even if Subtract[1,2,3] works, I cannot find in the docs mention of supporting more than 2 args, or how many it does support. Can you @light-matters ? -> https://reference.wolfram.com/language/ref/Subtract.html

light-matters commented 2 months ago

Subtract[1,2,3] doesn't work. I think it only supports binary operations and is converted internally to Plus[x,-y]. I think the problem here is the inconsistent errors.

holyjak commented 2 months ago

So if we changed the error message as

- Can't handle more than 2 arguments
+ Can't handle less than one or more than 2 arguments

then it would be fine?

light-matters commented 2 months ago

A change in error message might help a littel, but I think my original point was that using 'Subtract doesn't 'fail' with an error, but using '-' does. I'm not sure if this is really a problem, but it's at least strange. Why is it more of a problem when there's an alias?

holyjak commented 2 months ago

https://github.com/scicloj/wolframite/pull/123 makes sure that Subtract with incorrect args also fails.