nextjournal

mkvlr 2022-01-28T08:58:11.499459Z

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

genmeblog 2022-01-28T08:58:59.991139Z

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

🙏 2
genmeblog 2022-01-28T09:06:01.903659Z

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

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

genmeblog 2022-01-28T09:08:25.164989Z

Then, l add toString:

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

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

genmeblog 2022-01-28T09:10:29.316729Z

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

genmeblog 2022-01-28T09:13:17.518259Z

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]"]

genmeblog 2022-01-28T09:13:54.510049Z

Now, generating html causes the exception:

genmeblog 2022-01-28T09:13:59.275599Z

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

genmeblog 2022-01-28T09:15:01.758399Z

I belive it's something with state / caching

genmeblog 2022-01-28T09:19:03.289729Z

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):

genmeblog 2022-01-28T09:27:33.560969Z

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

mkvlr 2022-01-28T09:28:54.872839Z

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

🙏 1
mkvlr 2022-01-28T09:45:01.387869Z

I can generate a static app fine

mkvlr 2022-01-28T09:45:23.987689Z

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

mkvlr 2022-01-28T09:47:07.980719Z

ok, yeah, I can reproduce

genmeblog 2022-01-28T09:47:58.658389Z

no-cache seems to work

mkvlr 2022-01-28T09:48:02.982849Z

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

mkvlr 2022-01-28T09:48:32.084209Z

can you make an issue with your code?

genmeblog 2022-01-28T09:48:43.596979Z

yes, sure!

mkvlr 2022-01-28T09:48:55.926239Z

thank you!

genmeblog 2022-01-28T09:49:01.248379Z

thank you!

genmeblog 2022-01-28T10:05:49.060859Z

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

mkvlr 2022-01-28T10:19:46.446429Z

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

genmeblog 2022-01-28T10:20:23.306029Z

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

mkvlr 2022-01-28T10:20:35.943679Z

(in-ns 'nextjournal.clerk.viewer)

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

mkvlr 2022-01-28T10:20:44.904299Z

maybe easiest to try this in the repl

genmeblog 2022-01-28T10:26:27.122719Z

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

genmeblog 2022-01-28T10:27:02.033889Z

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

genmeblog 2022-01-28T10:30:44.063709Z

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

mkvlr 2022-01-28T10:32:17.930159Z

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

mkvlr 2022-01-28T10:32:47.917199Z

not as easy as I thought from the repl

mkvlr 2022-01-28T10:33:16.328569Z

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

genmeblog 2022-01-28T10:33:17.426649Z

ok, I'll switch to deps then

mkvlr 2022-01-28T10:33:25.529219Z

does https://github.com/RickMoynihan/lein-tools-deps work?

genmeblog 2022-01-28T10:33:43.095229Z

it works, I use it in other projects

genmeblog 2022-01-28T10:33:56.199889Z

so yes, I need to switch to that, thanks

genmeblog 2022-01-28T11:05:50.358869Z

it's working! thanks a lot 😄

mkvlr 2022-01-28T11:11:52.402329Z

great! Thanks for the report

mkvlr 2022-01-28T11:12:20.691589Z

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

Ash 2022-01-28T10:21:58.533549Z

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.

mkvlr 2022-01-28T10:29:03.477839Z

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

mkvlr 2022-01-28T10:30:19.976799Z

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

mkvlr 2022-01-28T10:31:41.791559Z

(for the :bundle? false option that is)

mkvlr 2022-01-28T10:39:12.681209Z

or how do you think the links are wrong?

Ash 2022-01-28T11:09:50.763379Z

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.

mkvlr 2022-01-28T11:11:07.744119Z

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

Ash 2022-01-28T11:44:43.871129Z

…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 😃

genmeblog 2022-01-28T13:01:22.504739Z

@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).

mkvlr 2022-01-28T13:24:09.198829Z

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

mkvlr 2022-01-28T13:24:26.026699Z

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

👍 1
2022-01-28T21:06:16.247159Z

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

mkvlr 2022-01-29T07:56:58.145669Z

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