Fork me on GitHub
#nextjournal
<
2022-01-28
>
mkvlr08:01:11

morning @tsulej, taking a look at your issue right now

genmeblog08:01:59

Hi there! Thanks! I found something more regarding custom types (playing with that now). Will post details in the thread.

🙏 2
genmeblog09:01:01

I'll start with the following, which works properly.

(deftype MyType [a b])
(MyType. 1 2)
;; => #object[sometest.MyType 0x57c6a598 "sometest.MyType@57c6a598"]

genmeblog09:01:25

Then, l add toString:

(deftype MyType [a b]
  Object
  (toString [_] (str "#MyType " [a b])))

(MyType. 1 2)
;; => #object[sometest.MyType 0x1987e9b3 "#MyType [1 2]"]

genmeblog09:01:29

Now it's rendered with nippy error (also ignoring toString:

genmeblog09:01:17

Now I add two more interfaces:

(deftype MyType [a b]
  Object
  (toString [_] (str "#MyType " [a b]))
  clojure.lang.Sequential
  clojure.lang.Seqable
  (seq [_] (seq [a b])))

(MyType. 1 2)
;; => #object[sometest.MyType 0x6fd2252 "#MyType [1 2]"]

genmeblog09:01:54

Now, generating html causes the exception:

genmeblog09:01:59

1. Unhandled java.lang.AbstractMethodError
   Receiver class sometest.MyType does not define or inherit an
   implementation of the resolved method 'abstract clojure.lang.ISeq
   seq()' of interface clojure.lang.Seqable.

                   RT.java:  543  clojure.lang.RT/seqFrom
                   RT.java:  537  clojure.lang.RT/seq
                  core.clj:  139  clojure.core/seq
                  core.clj: 7392  clojure.core/bounded-count
                  core.clj: 7386  clojure.core/bounded-count
               viewer.cljc:  320  nextjournal.clerk.viewer$bounded_count_opts$fn__18923/invoke
               viewer.cljc:  320  nextjournal.clerk.viewer$bounded_count_opts/invokeStatic
               viewer.cljc:  317  nextjournal.clerk.viewer$bounded_count_opts/invoke
               viewer.cljc:  418  nextjournal.clerk.viewer$describe/invokeStatic
               viewer.cljc:  366  nextjournal.clerk.viewer$describe/invoke
               viewer.cljc:  372  nextjournal.clerk.viewer$describe/invokeStatic
               viewer.cljc:  366  nextjournal.clerk.viewer$describe/invoke
                  view.clj:  110  nextjournal.clerk.view/->result
                  view.clj:  109  nextjournal.clerk.view/->result
                  view.clj:  164  nextjournal.clerk.view/describe-block
                  view.clj:  151  nextjournal.clerk.view/describe-block
                  core.clj: 2635  clojure.core/partial/fn
                  core.clj: 2746  clojure.core/map/fn/fn
     PersistentVector.java:  343  clojure.lang.PersistentVector/reduce
                  core.clj: 6885  clojure.core/transduce
                  core.clj: 6901  clojure.core/into
                  core.clj: 6889  clojure.core/into
                  view.clj:  171  nextjournal.clerk.view/doc->viewer/fn
                  core.clj: 6185  clojure.core/update
                  core.clj: 6177  clojure.core/update
                  view.clj:  171  nextjournal.clerk.view/doc->viewer
                  view.clj:  167  nextjournal.clerk.view/doc->viewer
                 clerk.clj:  274  nextjournal.clerk/file->viewer
                 clerk.clj:  271  nextjournal.clerk/file->viewer
                 clerk.clj:  273  nextjournal.clerk/file->viewer
                 clerk.clj:  271  nextjournal.clerk/file->viewer
                  core.clj: 2598  clojure.core/juxt/fn
                  core.clj: 2746  clojure.core/map/fn/fn
     PersistentVector.java:  343  clojure.lang.PersistentVector/reduce
                  core.clj: 6885  clojure.core/transduce
                  core.clj: 6901  clojure.core/into
                  core.clj: 6889  clojure.core/into
                 clerk.clj:  380  nextjournal.clerk/build-static-app!
                 clerk.clj:  366  nextjournal.clerk/build-static-app!
                      REPL:   15  sometest/eval25870

genmeblog09:01:01

I belive it's something with state / caching

genmeblog09:01:03

When I copied above code to the different namespace I've got the same error. When I changed MyType to MyType2 the result is almost ok (ignoring toString though):

genmeblog09:01:33

adding another interface causes an error again (for example clojure.lang.Counted (count [_] 2)

mkvlr09:01:54

pushed a fix for the first issue https://github.com/nextjournal/clerk/commit/a30123a231a4b13e7caed66e12b4d29bdd92d772 now looking at the second one…

🙏 1
mkvlr09:01:01

I can generate a static app fine

mkvlr09:01:23

can you try to add the ^:nextjournal.clerk/no-cache tag to see if that fixes it?

mkvlr09:01:07

ok, yeah, I can reproduce

genmeblog09:01:58

no-cache seems to work

mkvlr09:01:02

I think the issue is that we’re not yet handling deftype wrt caching

mkvlr09:01:32

can you make an issue with your code?

mkvlr09:01:55

thank you!

genmeblog10:01:49

@mkvlr how to locally install Clerk snapshot from the source code (I use lein in current project I wanted to test for #64)?

mkvlr10:01:46

oh, not sure how this works with lein and git deps these days…

genmeblog10:01:23

I tried to run clj -X:build but have no access to cas repo

mkvlr10:01:35

(in-ns 'nextjournal.clerk.viewer)

(defn- var-from-def? [x]
  (and (map? x) (get x :nextjournal.clerk/var-from-def)))

mkvlr10:01:44

maybe easiest to try this in the repl

genmeblog10:01:27

Ok, tried that and no changes (looks like this functions is not called)

genmeblog10:01:02

genuary.2022.day26> (in-ns 'nextjournal.clerk.viewer)
#namespace[nextjournal.clerk.viewer]
nextjournal.clerk.viewer> (defn- var-from-def? [x] (println "aaa") 
    (and (map? x) (get x :nextjournal.clerk/var-from-def)))
#'nextjournal.clerk.viewer/var-from-def?
nextjournal.clerk.viewer> (clerk/build-static-app! {:out-path "docs" :paths ["src/genuary/2022/day26.clj"]})
#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

genmeblog10:01:44

nextjournal.clerk.viewer> (var-from-def? 123)
aaa
false

mkvlr10:01:17

ah right, it is being called but there’s more you need to reload

mkvlr10:01:47

not as easy as I thought from the repl

mkvlr10:01:16

but I tried the fix and am pretty confident it’s working…

genmeblog10:01:17

ok, I'll switch to deps then

genmeblog10:01:43

it works, I use it in other projects

genmeblog10:01:56

so yes, I need to switch to that, thanks

genmeblog11:01:50

it's working! thanks a lot 😄

mkvlr11:01:52

great! Thanks for the report

mkvlr11:01:20

we were actually talking about this piece of code and we wondering if it’s safe to call get yesterday 😼

Ash10:01:58

A couple of minor observations when using build-static-app! (version 0.5.346)... • Using :bundle? false nicely generates the individual .html files but with incorrect hyperlinks between them. Is there a sort of root URL parameter that I ought to have set? (Using :bundle? true generated correct intra-page hyperlinks.) Or perhaps the :bundle? false setting isn’t quite public yet. • It opens my web browser at http://localhost:7778/build but nothing is being served from there. Thanks.

mkvlr10:01:03

you can pass a :path-prefix param (with a trailing, not leading slash), e.g. build/

mkvlr10:01:19

and for the links to work, you need a http server

mkvlr10:01:41

(for the :bundle? false option that is)

mkvlr10:01:12

or how do you think the links are wrong?

Ash11:01:50

Thanks @mkvlr:path-prefix "public/build/" is what I needed to get my hyperlinks to work (when using :bundle? false). Although (very minor) build-static-app! still tries to open my web browser at when is what works.

mkvlr11:01:07

I don’t think you want public in your links or do you actually want to serve it from your.domain/public/build?

Ash11:01:43

…as you say, I don’t want public in my URLs but, I was struggling to get to the right value for a :path-prefix. This is what now works for me in my deps.edn:

:aliases {:web-pages   
          ;; To use this alias...
          ;; (1) run a webserver, e.g.
          ;;       python3 -m http.server 7778 --directory public
          ;; (2) and run this alias, e.g.
          ;;       clj -X:web-pages
          ;; (3) once Clerk has finished generating the HTML files
          ;;       it will open a web browser at the 'index' URL for those HTML files:
          ;;         
          {:extra-paths ["datasets"]
           :exec-fn     nextjournal.clerk/build-static-app!
           :exec-args   {:bundle?     false
                         :path-prefix "build/"
                         :paths       ["index.md"
                                       "notebooks/scotgov_datasets.clj"
                                       "notebooks/wikidata_label_first_querying_for_scotgov_agencies.clj"]}}}
Thanks for the pointers 😃

genmeblog13:01:22

@mkvlr as @borkdude pointed out in issue comments, fault was on my side. Saying that I think the change you've made should be reverted since get may work on many other types (unless you expect a map and only map).

mkvlr13:01:09

yeah, in this case I expect only a map, this is a data structure internal to Clerk so I don’t think being defensive hurts here

mkvlr13:01:26

as we’ve seen it can cause problems in real-world code 😼

👍 1
Carsten Behring21:01:16

I noticed that enums in tables get rendered as objects: I this wanted behaviour ?

mkvlr07:01:58

I think this is just the normal Clojure printing, so yes.