Fork me on GitHub
Jakub Holý (HolyJak)10:10:06

update: I was wrong, I can override a protected method with proxy . Just my code was wrong. Hello! Is there any good way to dynamically create a subclass and override a protected method? (Namely doAppend of I believe I cannot use proxy because the method is protected. Unless I am wrong, I must use gen-class but since I want to do this at runtime, inside REPL, I would somehow need to manually trigger compilation....? Thank you!

✅ 3

Many times in my code I write something like (first (sequence xf-ast [html])) There is something that "transduce one element"?


(take 1) ?


I have a list of multimethods that I want to enumerate their implementations for, but I can't quite get the right incantation for this. I've tried the following:

;class clojure.lang.Symbol cannot be cast to class clojure.lang.MultiFn 
(let [api-methods '[foo bar]]
  (map methods api-methods))

;class clojure.lang.Var cannot be cast to class clojure.lang.MultiFn
(let [api-methods '[foo bar]]
  (map (comp methods resolve) api-methods))
For each of the above I get the exceptions shown above them. Anyone know how to resolve these correctly?


Got it!

(let [api-methods '[foo bar]]
  (map (comp methods deref resolve) api-methods))

👍 3
Benny kach14:10:43

hi, i need to add spec to a function with kwargs.

(defn register-metrics
  [& metrics]
the call to this function should look like
(register-metrics :counter "poop" :gauge "bar")
so every odd index in the given args should be one of :counter or :gauge

Benny kach14:10:05

how can i achieve it?

Alex Miller (Clojure team)14:10:04

syntax of s/keys, but is a regex spec that will match a sequence like that

Alex Miller (Clojure team)14:10:36

(fyi, for future probably better to drop in #clojure-spec )

Benny kach14:10:11

oh wasnt aware this channel exists. thanks a lot!

Benny kach14:10:51

@alexmiller is there any docs/examples for this?

Alex Miller (Clojure team)15:10:07

but it would be something like:

(s/def ::counter string?)
(s/def ::gauge string?)
(s/fdef register-metrics :args (s/keys* :opt-un [::counter ::gauge]))

Benny kach15:10:48

amazing! much appreciation!

Alex Miller (Clojure team)15:10:01

I'm assuming you have concrete metric keys that you want to spec

Benny kach15:10:45

after defining these, isnt this operation should fail?

(register-metrics :abc "123")

Alex Miller (Clojure team)15:10:48

keys (and keys*) are "open map" - additional keys are allowed

Benny kach15:10:16

so is there a way to allow only these keys?

Alex Miller (Clojure team)15:10:57

you can s/and tighter constraints if you need to (but note that the function itself doesn't have those constraints - passing extra stuff is allowed)


@alexmiller any plans on releasing a non-alpha version of data.xml ? I see you were in the repo recently

Alex Miller (Clojure team)17:10:28

I have not gotten a good read from Herwig on what he believes are things to be finished/figured out before doing so

👍 3

I know the only documented part of the clojure java api is IFn and , but what other parts of clojure are "effectively final"?


Like, clojure code often uses IPersistentMap in order to dispatch on protocols


and I remember reading in the ticket for adding var-args inference that some degree of the reflector api needs to stay stable so already compiled code doesn't break


Like if, say, I was super duper unemployed and living in my parents basement but was also looking for ways to be more productive - what parts of java-clojure are needed to be a "compliant" implementation of clojure?

Alex Miller (Clojure team)17:10:05

I don't think there is a simple answer to that

Alex Miller (Clojure team)17:10:57

there are degrees of resistance to change

Alex Miller (Clojure team)17:10:58

in the collection api, generally the interfaces are the surface area (IPersistent*, traits like Indexed, Counted, etc, finer-grained op interfaces like ILookup)

Alex Miller (Clojure team)17:10:18

from a compiled Clojure pov, things like RT and Reflector are things we generally only grow to support back binary compatibility

Alex Miller (Clojure team)17:10:20

and then there are core types like Keyword, Symbol, Var, etc..


my impression (which is not based on much) is rhickey is resistant to the idea of having a more formal definition of clojure, which makes it very difficult for alternative implementations to exist. without some more formal definition of "clojure" the only why to determine if something is clojure or not is to ask rhickey


this already comes up with clojureclr and clojurescript to some degree. clojurescript is, to my mind, very different from clojure, different enough to be a different thing, but some people (and I think rhickey may be one of them, not sure, but I have heard it expressed by people that would know his mind on the subject better than I) insist that it is clojure


I think that "clojure" has a runtime, "clojurescript" dosent Kind of we can implement "clojurescript" on JVM or "clojure" in JS But with this definition in mind, the reader conditional that currently use :clj to "macro time" in :cljs turns wired.


Depends what you mean by runtime


Cljs does have a big pile of support code, the main difference is the support code for cljs is a mix of clojure and clojurescript, the support code for clojure is a lot of java


By runtime I mean something like a stateful singleton that hold things like keyword cache and threads.


not sure what threads has to do with it


and clojurescript does its best to cache keywords


which kind of implies clojure is the intersection of clojure and clojurescript, which leaves out a lot of what I associate with clojure


if you haven't seen the definition of standard ml(which is very high level), or the jvm spec(more of a bit bashers spec) they are both real neat


I'm toying with datalog using datalevin and am wondering about some modeling questions. I've defined a schema for a value to have a "many" cardinality, of course it can only accept unique attribute values, but I want to test out modeling multiple of one attribute with the same value, for example an :order/item that indicates amount. How would that be done with datalog?


I can't speak to datalevin specifically, but the value doesn't actually play in to it


Many or not depends effects what happens when a triple has the same entity and attribute


If an attribute isn't many, then for a given entity you will only have one value for that attribute, if it is many then you can have many


I tested out this model

{:db/id -8  :invoice/id 3888 :invoice/item -1}
                {:db/id -9  :invoice/id 3888 :invoice/item -2}
                {:db/id -10 :invoice/id 3888 :invoice/item -4 :invoice/amt 2}
where I have the :invoce/item as a ref to an items list, and just keep an amt as a seperate attribute, defautling in the query


seems to work, but I'd need a good lookover at some datalog material which seems hard to find specific to modeling the data.


I am adding a couple of database generation scripts to my project and I don't want them to be part of the main build process as they are only ran once. I decided to create a separate profile for each script. However, when I run lein with-profile generate-gene-db uberjar I get two jar files: guidescan-web-2.0.jar and generate-gene-db.jar where the latter is the standalone version.


I expected that each jar would be named per the profile, but it seems only one of the two are and I dislike this behavior. Here is my profile.clj for reference:

seancorfield21:10:23 I'd have to go digging in the Leiningen source to be sure, but I think that it always builds the (thin) JAR based on the project name and version, even when it is building an uberjar. Maybe there's a setting to specify the name of the thin JAR too? :jar-name perhaps?


thank you so much 🙂


(I wondered if you could set it to nil to stop it generating the JAR but that just defaults back to project-version.jar 😞 )


yes the thin version might not get very much use, but that is okay, at least the names are consistent enough for my liking


I just confirmed that it builds the thin jar first and then uses that when it builds the standalone jar -- and you can't use /tmp/scratch.jar because it requires relative paths (from target) and you can't use scratch/scratch.jar because the relative folder scratch must exist inside target. Sigh 😐


(which all just makes me glad I don't use Leiningen any more 🙂 )