Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastmath vec2/vec3/vec4 dosn't render and causes exception #64

Closed
genmeblog opened this issue Jan 27, 2022 · 11 comments
Closed

fastmath vec2/vec3/vec4 dosn't render and causes exception #64

genmeblog opened this issue Jan 27, 2022 · 11 comments

Comments

@genmeblog
Copy link

genmeblog commented Jan 27, 2022

Hi, with the latest nextjournal (0.5.346) following code results in exception and renders as nil value. Maybe something is wrong with fastmath.vector implementation however I can't understand what.

(ns sometest
  (:require [fastmath.vector :as v]))

(v/vec2 3 4)
;; => #vec2 [3.0, 4.0]

(comment
  (require '[nextjournal.clerk :as clerk])
  (clerk/build-static-app! {:out-path "docs" :paths ["src/sometest.clj"]}))

The html is generated and prints nil as a vec2 value:

image

And exception is like:

#error {
 :cause class clojure.lang.Keyword cannot be cast to class java.lang.Character (clojure.lang.Keyword is in unnamed module of loader 'app'; java.lang.Character is in module java.base of loader 'bootstrap')
 :via
 [{:type java.lang.ClassCastException
   :message class clojure.lang.Keyword cannot be cast to class java.lang.Character (clojure.lang.Keyword is in unnamed module of loader 'app'; java.lang.Character is in module java.base of loader 'bootstrap')
   :at [clojure.lang.RT uncheckedIntCast RT.java 1476]}]
 :trace
 [[clojure.lang.RT uncheckedIntCast RT.java 1476]
  [fastmath.vector.Vec2 invoke vector.clj 365]
  [fastmath.vector.Vec2 valAt vector.clj 352]
  [clojure.lang.RT get RT.java 760]
  [nextjournal.clerk.viewer$var_from_def_QMARK_ invokeStatic viewer.cljc 163]
  [nextjournal.clerk.viewer$var_from_def_QMARK_ invoke viewer.cljc 162]
  [nextjournal.clerk.viewer$wrapped_with_viewer invokeStatic viewer.cljc 293]
  [nextjournal.clerk.viewer$wrapped_with_viewer invoke viewer.cljc 280]
  [nextjournal.clerk.viewer$describe$fn__18862 invoke viewer.cljc 375]
  [nextjournal.clerk.viewer$describe invokeStatic viewer.cljc 375]
  [nextjournal.clerk.viewer$describe invoke viewer.cljc 366]
  [nextjournal.clerk.viewer$describe invokeStatic viewer.cljc 372]
  [nextjournal.clerk.viewer$describe invoke viewer.cljc 366]
  [nextjournal.clerk.view$__GT_result invokeStatic view.clj 110]
  [nextjournal.clerk.view$__GT_result invoke view.clj 109]
  [nextjournal.clerk.view$describe_block invokeStatic view.clj 164]
  [nextjournal.clerk.view$describe_block invoke view.clj 151]
  [clojure.core$partial$fn__5859 invoke core.clj 2635]
  [clojure.core$map$fn__5880$fn__5881 invoke core.clj 2746]
  [clojure.lang.PersistentVector reduce PersistentVector.java 343]
  [clojure.core$transduce invokeStatic core.clj 6885]
  [clojure.core$into invokeStatic core.clj 6901]
  [clojure.core$into invoke core.clj 6889]
  [nextjournal.clerk.view$doc__GT_viewer$fn__22748 invoke view.clj 171]
  [clojure.core$update invokeStatic core.clj 6185]
  [clojure.core$update invoke core.clj 6177]
  [nextjournal.clerk.view$doc__GT_viewer invokeStatic view.clj 171]
  [nextjournal.clerk.view$doc__GT_viewer invoke view.clj 167]
  [nextjournal.clerk$file__GT_viewer invokeStatic clerk.clj 274]
  [nextjournal.clerk$file__GT_viewer invoke clerk.clj 271]
  [nextjournal.clerk$file__GT_viewer invokeStatic clerk.clj 273]
  [nextjournal.clerk$file__GT_viewer invoke clerk.clj 271]
  [clojure.core$juxt$fn__5840 invoke core.clj 2598]
  [clojure.core$map$fn__5880$fn__5881 invoke core.clj 2746]
  [clojure.lang.PersistentVector reduce PersistentVector.java 343]
  [clojure.core$transduce invokeStatic core.clj 6885]
  [clojure.core$into invokeStatic core.clj 6901]
  [clojure.core$into invoke core.clj 6889]
  [nextjournal.clerk$build_static_app_BANG_ invokeStatic clerk.clj 380]
  [nextjournal.clerk$build_static_app_BANG_ invoke clerk.clj 366]
  [somtest$eval32629 invokeStatic form-init3528201830096940289.clj 8]
  [sometest$eval32629 invoke form-init3528201830096940289.clj 8]
  [clojure.lang.Compiler eval Compiler.java 7181]
  [clojure.lang.Compiler eval Compiler.java 7136]
  [clojure.core$eval invokeStatic core.clj 3202]
  [clojure.core$eval invoke core.clj 3198]
  [nrepl.middleware.interruptible_eval$evaluate$fn__1231$fn__1232 invoke interruptible_eval.clj 87]
  [clojure.lang.AFn applyToHelper AFn.java 152]
  [clojure.lang.AFn applyTo AFn.java 144]
  [clojure.core$apply invokeStatic core.clj 667]
  [clojure.core$with_bindings_STAR_ invokeStatic core.clj 1977]
  [clojure.core$with_bindings_STAR_ doInvoke core.clj 1977]
  [clojure.lang.RestFn invoke RestFn.java 425]
  [nrepl.middleware.interruptible_eval$evaluate$fn__1231 invoke interruptible_eval.clj 87]
  [clojure.main$repl$read_eval_print__9110$fn__9113 invoke main.clj 437]
  [clojure.main$repl$read_eval_print__9110 invoke main.clj 437]
  [clojure.main$repl$fn__9119 invoke main.clj 458]
  [clojure.main$repl invokeStatic main.clj 458]
  [clojure.main$repl doInvoke main.clj 368]
  [clojure.lang.RestFn invoke RestFn.java 1523]
  [nrepl.middleware.interruptible_eval$evaluate invokeStatic interruptible_eval.clj 84]
  [nrepl.middleware.interruptible_eval$evaluate invoke interruptible_eval.clj 56]
  [nrepl.middleware.interruptible_eval$interruptible_eval$fn__1264$fn__1268 invoke interruptible_eval.clj 152]
  [clojure.lang.AFn run AFn.java 22]
  [nrepl.middleware.session$session_exec$main_loop__1334$fn__1338 invoke session.clj 218]
  [nrepl.middleware.session$session_exec$main_loop__1334 invoke session.clj 217]
  [clojure.lang.AFn run AFn.java 22]
  [java.lang.Thread run Thread.java 833]]}
@mk mk closed this as completed in a30123a Jan 28, 2022
@mk
Copy link
Member

mk commented Jan 28, 2022

Can you try the attached fix? The problem was that (get (fastmath.vector/vec2 3 4) :nextjournal.clerk/var-from-def) throws and the code assumed it would not.

@genmeblog
Copy link
Author

Tried and fix is working. Thank you very much!

@borkdude
Copy link
Collaborator

I would say their ILookup implementation is wrong :).

@genmeblog
Copy link
Author

@borkdude oh! can clarify you why?

@borkdude
Copy link
Collaborator

ILookup should not throw when a key/index is not present.

user=> ([1 2 3] 3) ;; this is how you probably implemented it
Execution error (IndexOutOfBoundsException) at user/eval143 (REPL:1).
null
user=> (get [1 2 3] 3) ;; this is how it should behave
nil

@genmeblog
Copy link
Author

It doesn't throw:

(def v (fastmath.vector/vec2 1 2))

(v 3)
;; => nil

(get v 3)
;; => nil
(get v 3 :not-found)
;; => :not-found

(sorry for offtopic)

@borkdude
Copy link
Collaborator

Oh, then I misunderstood the issue, sorry.

@borkdude
Copy link
Collaborator

borkdude commented Jan 28, 2022

@genmeblog Why does:

(get (fastmath.vector/vec2 3 4) :nextjournal.clerk/var-from-def)

throw? I don't think it should throw.

@genmeblog
Copy link
Author

Oh. Indeed! Got it. Thanks!

@genmeblog
Copy link
Author

Hmmm @mk I think you should revert the change. get works on many types other than map itself. Looks like I misunderstood the contract for ILookup. I'm fixing it now on my side.

@mk
Copy link
Member

mk commented Jan 28, 2022

@genmeblog think the change should stay anyway. As we've seen, it can cause problems with code that's out there and being more defensive here doesn't hurt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants