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

Replace symbols with their aliases in ->clj also for - #89

Closed light-matters closed 1 month ago

light-matters commented 3 months ago

I was adding tests to the custom-aliases branch when I noticed:

(is (= '(- 5 4)
         (wl/->clj "Subtract[5, 4]")))
(is (= '(- 5)
         (wl/->clj "Minus[5]")))

both fail. They return (Subtract 5 4) and (Minus 5), respectively, instead of (- 5 4) and (- 5). This is something due to the experimental-fn implementation.

Example where this works as expected:

(wl/->clj "Power[2,Rational[-1,2]]")
=> (** 2 -1/2)

This is, as suggested, most likely due to the fact that - has as alias a fn that maps either to Minus or Subtract and the code does not handle the reverse transformation.

holyjak commented 2 months ago

They happens is that

(wl/->clj "Subtract[5, 4]") ; => (Subtract 5 4)
(wl/->clj "Minus[5]").        ; => (Minus 5)

while you expected to get '(- 5 4) and (- 5) - but we currently do not support reverse alias application and I see no need for it. We could do it (walk the transformed clj data, replace anything that has an alias with the alias)...