Since it seems that `deftype` is bare-bones, I've been attempting to sub-class PersistentVector with `gen-class`.
In a file 'DangerousVector.clj', I have the following:
(ns DangerousVector
"A vector class that inherits all of Clojure vector behavior, *except* when in
the function position, concatenates the first vector with the trailing vector."
(:gen-class
:name DangerousVector
:extends clojure.lang.PersistentVector))
(defn -invoke
([& vecs]
(do
(println "-invoke called")
(apply concat vecs))))
My intention is to create a new class called 'DangerousVector' that extends clojure.lang.PersistentVector and over-rides the super-class' `invoke` method with a new one that concatenates the vector in the function position with any trailing vectors.
When I compile at a fresh REPL with
blah> (compile 'DangerousVector)
I see the following files generated in directory 'target/classes/dangerous/'
DangerousVector$fn__7418.class
DangerousVector$_invoke.class
DangerousVector$loading__6812__auto____7416.class
DangerousVector__init.class
I am *barely* able to inspect the contents of these files; approximately half the contents are promising-looking strings, with the other half un-renderable characters.
This invocation appears to do something useful
(. DangerousVector (create (cons 1 (cons 2 '(3))))) ;; => [1 2 3]
but when I query its type
(type (. DangerousVector (create '()))) ;; => clojure.lang.PersistentVector
I don't get the expected 'DangerousVector'.
Furthermore, the invoke function doesn't appear to be over-riden.
;; typical `nth` behavior
(let [v (. DangerousVector (create (cons 1 (cons 2 '(3)))))]
(v 2))
;; => 3
;; not the expected `concat` behavior
(let [v (. DangerousVector (create (cons 1 (cons 2 '(3)))))]
(v [:a :b :c]))
;; => Unhandled java.lang.IllegalArgumentException
;; Key must be integer
(Based on this 17-year old chart
https://github.com/Chouser/clojure-classes/blob/master/graph-w-legend.svg I focused on clojure.lang.PersistentVector, but I had the same problems trying clojure.lang.LazilyPersistentVector.)
At this point, I've hit a wall, and would appreciate corrections and suggestions. Thanks.