Fork me on GitHub
#clojure
<
2020-10-22
>
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 http://logback.qos.ch/apidocs/ch/qos/logback/core/AppenderBase.html) 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
souenzzo12:10:41

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

Zor13:10:14

(take 1) ?

markbastian14:10:20

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?

markbastian14:10:16

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)

slipset16:10:22

@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
emccue17:10:53

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

emccue17:10:14

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

emccue17:10:18

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

emccue17:10:59

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

hiredman17:10:29

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

hiredman17:10:09

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

souenzzo00:10:56

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.

hiredman01:10:46

Depends what you mean by runtime

hiredman02:10:27

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

souenzzo02:10:37

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

hiredman04:10:32

not sure what threads has to do with it

hiredman04:10:21

and clojurescript does its best to cache keywords

hiredman17:10:15

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

hiredman17:10:58

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

theeternalpulse19:10:28

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?

hiredman19:10:05

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

hiredman19:10:01

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

hiredman19:10:10

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

theeternalpulse20:10:32

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

theeternalpulse20:10:03

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

schmidt7321:10:04

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.

schmidt7321:10:21

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

@henri.schmidt 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?

schmidt7321:10:17

thank you so much 🙂

seancorfield21:10:44

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

schmidt7321:10:20

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

seancorfield22:10:35

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 😐

seancorfield22:10:22

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