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!
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?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 :gaugehow can i achieve it?
keys*
syntax of s/keys
, but is a regex spec that will match a sequence like that
Got it!
(let [api-methods '[foo bar]]
(map (comp methods deref resolve) api-methods))
(fyi, for future probably better to drop in #clojure-spec )
oh wasnt aware this channel exists. thanks a lot!
@alexmiller is there any docs/examples for this?
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*
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]))
amazing! much appreciation!
I'm assuming you have concrete metric keys that you want to spec
after defining these, isnt this operation should fail?
(register-metrics :abc "123")
keys
(and keys*
) are "open map" - additional keys are allowed
oh
so is there a way to allow only these keys?
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
I have not gotten a good read from Herwig on what he believes are things to be finished/figured out before doing so
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"?
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?
I don't think there is a simple answer to that
there are degrees of resistance to change
in the collection api, generally the interfaces are the surface area (IPersistent*, traits like Indexed, Counted, etc, finer-grained op interfaces like ILookup)
from a compiled Clojure pov, things like RT and Reflector are things we generally only grow to support back binary compatibility
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
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 queryseems 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:
@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?
Yup, that looks like it should work https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L408-L413
@seancorfield you're my savior!
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 🙂 )