diff --git a/src/wolframite/base/express.clj b/src/wolframite/base/express.clj index 1d08d05..324e392 100644 --- a/src/wolframite/base/express.clj +++ b/src/wolframite/base/express.clj @@ -8,7 +8,10 @@ (assert (string? s) (str "Expected '" (pr-str s) "' to be a string but is " (type s))) ;; TODO: debug log: "express string>" (let [held-s (str "HoldComplete[" s "]") - link (proto/kernel-link jlink-instance) + link (or (proto/kernel-link jlink-instance) + (throw (IllegalStateException. + (str "Something is wrong - there is no JLink instance, which shouldn't" + " be possible. Try to stop and start Wolframite again.")))) output (io! (locking link (doto link diff --git a/src/wolframite/impl/jlink_proto_impl.clj b/src/wolframite/impl/jlink_proto_impl.clj index 67c151d..d0f334e 100644 --- a/src/wolframite/impl/jlink_proto_impl.clj +++ b/src/wolframite/impl/jlink_proto_impl.clj @@ -90,9 +90,10 @@ res)))) (terminate-kernel! [_this] ;; BEWARE: it is not absolutely guaranteed that the kernel will die immediately - (doto ^KernelLink @kernel-link-atom - (.terminateKernel) - (.close)) + (when-let [link ^KernelLink @kernel-link-atom] + (doto link + (.terminateKernel) + (.close))) (reset! kernel-link-atom nil)) (expr [_this primitive-or-exprs] (make-expr primitive-or-exprs))