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

Clojure '-' is replaced with Wolfram's 'Subtract' but Wolfram's Subtract takes exactly two arguments #29

Closed light-matters closed 5 months ago

light-matters commented 10 months ago

(- 5 4) -> Subtract[5,4] (fine) (- 5) -> Subtract[5] (error) (- 5 4 3) -> Subtract[5, 4, 3] (error)

(- 5) should go to 'Minus[5]' (- 5 4 3) should go to Plus[5, -4, -3]?

light-matters commented 6 months ago

I've realised that this can be solved quickly (but probably not ideally) by writing a Wolfram function

WolframiteSubtract[xs__] := 
 Module[{output = Map[Minus[#] &, List[xs]]},
  If[Length@output != 1, output[[1]] = Minus@output[[1]]];
  Apply[Plus, output]
  ]

and then aliasing to this function. This feels like a very slow solution, but the principal is there.

holyjak commented 6 months ago

Currently, our aliases are simple 1 for 1 substitution, so there is no place to put the conditional logic w.r.t. number of arguments. Thus we'd either need to extend that, or go the Wolfram extension way.