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

Better error when ->clj fails due to problems with starting Wolfram #114

Closed light-matters closed 2 months ago

light-matters commented 2 months ago
(wl/->clj "Solve[List[
                        Equal[x,
                              Times[Sqrt[Times[eps, Power[2, -1]]], w, Cosh[xi],
                        Cos[Eta]]],
 Equal[y,
       Times[Sqrt[Times[eps, Power[2, -1]]], w, Sinh[xi],
 Sin[Eta]]]], List[xi, Eta]]")

Failing with error:

1. Unhandled java.lang.NullPointerException
   Cannot enter synchronized block because "locklocal__5802__auto__49527" is
   null

               express.clj:   13  wolframite.base.express/express/fn
               express.clj:   13  wolframite.base.express/express
               express.clj:    4  wolframite.base.express/express
               convert.clj:  112  wolframite.base.convert/eval49594/fn
              MultiFn.java:  234  clojure.lang.MultiFn/invoke
                   cep.clj:   20  wolframite.base.cep/cep
                   cep.clj:    8  wolframite.base.cep/cep
                  core.clj:  192  wolframite.core/eval
                  core.clj:  169  wolframite.core/eval
                  core.clj:  216  wolframite.core/->clj
                  core.clj:  209  wolframite.core/->clj
                      REPL:   26  scicloj.talk.ince-gaussian/eval50071

In Mathematica, it returns a list of rules which are valid solutions to the system of equations. There is a warning returned as well though: "Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information."

light-matters commented 2 months ago

This is not strictly a 'bug' because it seems to have been a problem caused by the (wl/start) function not executing properly (because I already had Mathematica open).

The situation however, was not obvious from the error message!

holyjak commented 2 months ago

Not sure what happened here, or whether you had recent code. For me it fails as expected with

(wl/->clj "Plus[1,2]")
java.lang.IllegalStateException: Not initialized, call start first
    at wolframite.core$eval.invoke(core.clj:169)
    at wolframite.core$__GT_clj.invoke(core.clj:217)

(this is when I did wl/stop first)