clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
Jakub Holý 2020-10-22T10:54:06.486500Z

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!

✅ 1
souenzzo 2020-10-22T12:40:41.487600Z

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

2020-10-22T13:24:14.487700Z

(take 1) ?

2020-10-22T14:01:20.492900Z

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?

Benny kach 2020-10-22T14:03:43.493600Z

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 kach 2020-10-22T14:04:05.493900Z

how can i achieve it?

alexmiller 2020-10-22T14:04:10.494100Z

keys*

alexmiller 2020-10-22T14:05:04.494900Z

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

2020-10-22T14:05:16.495Z

Got it!

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

👍 1
alexmiller 2020-10-22T14:05:36.495500Z

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

Benny kach 2020-10-22T14:06:11.495900Z

oh wasnt aware this channel exists. thanks a lot!

Benny kach 2020-10-22T14:54:51.496500Z

@alexmiller is there any docs/examples for this?

alexmiller 2020-10-22T15:01:57.497100Z

there is a (non-function) example in the guide https://clojure.org/guides/spec. doc: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html#clojure.spec.alpha/keys*

alexmiller 2020-10-22T15:03:07.498200Z

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 kach 2020-10-22T15:03:48.498600Z

amazing! much appreciation!

alexmiller 2020-10-22T15:04:01.499Z

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

Benny kach 2020-10-22T15:06:45.499400Z

after defining these, isnt this operation should fail?

(register-metrics :abc "123")

alexmiller 2020-10-22T15:08:48.000100Z

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

Benny kach 2020-10-22T15:08:55.000300Z

oh

Benny kach 2020-10-22T15:09:16.000900Z

so is there a way to allow only these keys?

alexmiller 2020-10-22T15:09:57.001800Z

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)

slipset 2020-10-22T16:53:22.003Z

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

alexmiller 2020-10-22T17:00:28.004Z

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

👍 1
emccue 2020-10-22T17:13:53.005600Z

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

emccue 2020-10-22T17:14:14.006100Z

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

emccue 2020-10-22T17:15:18.007300Z

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

emccue 2020-10-22T17:16:59.008600Z

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?

alexmiller 2020-10-22T17:19:05.009300Z

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

alexmiller 2020-10-22T17:19:57.009800Z

there are degrees of resistance to change

alexmiller 2020-10-22T17:20:58.010700Z

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

alexmiller 2020-10-22T17:22:18.011700Z

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

alexmiller 2020-10-22T17:23:20.012300Z

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

2020-10-22T17:45:29.016Z

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

2020-10-22T17:50:09.018Z

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

2020-10-22T17:51:15.018900Z

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

2020-10-22T17:59:58.020200Z

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

2020-10-22T18:00:48.020300Z

https://docs.oracle.com/javase/specs/

2020-10-22T18:01:13.020500Z

https://smlfamily.github.io/sml97-defn.pdf

theeternalpulse 2020-10-22T19:03:28.022700Z

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?

2020-10-22T19:43:05.024700Z

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

2020-10-22T19:44:01.026200Z

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

2020-10-22T19:47:10.028Z

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

theeternalpulse 2020-10-22T20:15:32.029Z

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

theeternalpulse 2020-10-22T20:16:03.029700Z

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

schmidt73 2020-10-22T21:05:04.029900Z

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.

schmidt73 2020-10-22T21:05:21.030100Z

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:

schmidt73 2020-10-22T21:05:44.030200Z

seancorfield 2020-10-22T21:55:23.032100Z

@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?

seancorfield 2020-10-22T21:56:08.032400Z

Yup, that looks like it should work https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L408-L413

🙏 1
schmidt73 2020-10-22T21:58:07.032800Z

@seancorfield you're my savior!

schmidt73 2020-10-22T21:58:17.033200Z

thank you so much 🙂

seancorfield 2020-10-22T21:58:44.033800Z

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

schmidt73 2020-10-22T21:59:20.034400Z

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

seancorfield 2020-10-22T22:02:35.036Z

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 😐

seancorfield 2020-10-22T22:03:22.036500Z

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