This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-25
Channels
- # beginners (33)
- # cider (40)
- # clara (28)
- # cljs-dev (38)
- # cljsrn (5)
- # clojure (197)
- # clojure-greece (1)
- # clojure-italy (7)
- # clojure-losangeles (1)
- # clojure-nl (10)
- # clojure-spec (32)
- # clojure-uk (154)
- # clojurescript (48)
- # core-async (33)
- # cursive (32)
- # datomic (19)
- # duct (1)
- # fulcro (10)
- # graphql (6)
- # jobs (1)
- # lumo (1)
- # mount (6)
- # off-topic (48)
- # onyx (12)
- # other-languages (2)
- # re-frame (77)
- # reagent (19)
- # reitit (4)
- # ring (5)
- # ring-swagger (18)
- # rum (4)
- # shadow-cljs (52)
- # specter (12)
- # tools-deps (47)
I know it's probably almost never used, but is there a good way to unquote and deref an atom in a macro?
(defmacro example []
(let [a (atom nil)]
`(println ~@a)))
The best I've got is
(defmacro example []
(let [a (atom nil)]
`(println ~(deref a))))
or
(defmacro example []
(let [a (atom nil)]
`(println ~(-> @a))))
Something feels wrong about both though.I suppose this was a bad example, but you have a point. I can just redefine the symbol as the derefed version, since the atom's state is created in other let bindings.
Thanks, @michael.gaare.
or (to prevent an XY problem), can anybody suggest a way to only eval
once instead of once per line?
i think i got it.
(defn make-filter
[filter-expr-str]
(let [raw-expr (read-string filter-expr-str)
filter-expr (partial
(eval `(fn [~(symbol "it")]
~raw-expr)))]
filter-expr))
seems to evaluate the predicate once in the closure!spec question: is there some way to make spec consider nil
the absence of a key? When using s/keys
with optional keys, the spec still fails if I include the key with an explicit nil, which causes me to define the key as something that is either nil or a usable thing
(s/def ::key string?)
(s/def ::mymap (s/keys ::opt [::key]))
(s/valid? ::mymap {}) ;; true
(s/valid? ::mymap {::key nil}) ;; false
you have spec/nilable
for that
a little bit better, but it still defines the key as nilable. ideally Iād like to say that nils are OK for optionals
> you can sneak nils into required map keys
well, the idea is to make nilable
only the optional keys (not the required keys). but I understand that this solution might not be ideal for you.
this stops working the moment you have a key that is required in one context, and optional in another
I'm not sure I understand, but isn't what you're doing what's actually working "against the idea of having global reusable specs"?
If you say in one place that ::key
should be a string, but you can pass ::key nil
in another place then (s/def ::key string?)
is not globally true.
The thing is that you want to make ::key
nilable in the context of ::mymap
, but then it's no longer ::key
according to your spec because now it can be nil
You could do something like
(s/def ::key string?)
(s/def :mymap/key (s/nilable ::key))
(s/def ::mymap (s/keys ::opt [:mymap/key]))
which is more verbose but still stays true to the global specs
Yes, this works, but is very cumbersome. Given that Clojure has nil punning almost everywhere Iād expect this to be the default behavior of :opt
e.g., I canāt think of any other area in Clojure where {::key nil}
would be handled much differently from {}
(let [{:keys [a b] :or {a 1}} {:a nil :b 3}]
[a b])
=> [nil 3]
(let [{:keys [a b] :or {a 1}} {:b 3}]
[a b])
=> [1 3]
this would be one case š
I think this boils down to this rationale: https://clojure.org/about/spec#_sets_maps_are_about_membership_that_s_it
I agree with all of the rationale behind spec, thatās why Iām using it. I just slightly disagree with the definition of āoptionalā and nils
and itās not the end of the worldā¦ just results in a bit more friction when introducing spec into an existing codebase
(cond-> {:default "Keys"}
some-val (assoc :some-key (compute some-val)))
is also an option if you have a lot of casesand I can see where you're coming from, it's definitely more verbose
but ĀÆ\(ć)/ĀÆ
āļø
@andre.stylianos come on man, we have good ol' remove-nil-values-from-map
(defn remove-nil-values-from-map [m]
(->> m
(filter second)
(into {})))
no need for cond->
/`as->` + assoc-in
hell imoThere's that š
some?
then
(me too. also empty
and empty?
...)
(into {} (filter (comp some? val)) m)
summing up then?
Hi, I just switched from http-kit to jetty. I have an endpoint that when i request it, i get a "java.lang.StackOverflowError" ... the same endpoint returns fine in http-kit and also, when i repl onto the server and try calling the function directly with the same parameters, it also returns ok. Anyone have any suggestion as to how i would debug this ?
Iāve a question about swap!
. According to the doc:
Atomically swaps the value of atom to be:
(apply f current-value-of-atom args). Note that f may be called
multiple times, and thus should be free of side effects. Returns
the value that was swapped in.
I have println
statements in f
. Thus, strictly speaking the function has side effects, however, it always returns the same value for given input so it should be safe to use it. Am I missing something fundamental here?Thanks for replying @bherrmann Why is that? What could happen to the print statements?
swap might try repeatedly to update the atomā¦ so it is possible for f to be invoked more than onceā¦. if there is contention for the atom.
If two threads are calling swap! on the same atom at the same time one of the callers might have to repeat?
@alexmiller what would be the workflow to get strint templating working in clojurescript? I am willing to work on it but I have never submitted a patch to clojure code š https://github.com/clojure/core.incubator/blob/master/src/main/clojure/clojure/core/strint.clj
if youāre asking about cljs, Iād head to #cljs-dev
however, there is support for some of this stuff in format
and cl-format
(not sure the status of those in cljs)
(I'm actually thinking about this more in a CLJS context so maybe I should ask in that channel)
What analysis are you expecting it to write? If it's anything mutable then how would that work?
@lilactown if the side effect can be done in its own function, that would be my preferred way to handle it. Ask yourself why you need the macro.
In that case it seems reasonable, since you want the form unevaluated I would assume.
with deps.edn, Iām trying to override a git dep with a local dep. My deps.edn looks like this:
{:deps
{org.clojure/tools.analyzer.jvm {:mvn/version "0.7.2"}
seesaw {:mvn/version "1.5.0"}
rakk {:git/url ""
:sha "a4b5717086e66989856a45a1f6e5d04628e6aec3"}
cross-parinfer {:mvn/version "1.4.5"}
org.clojure/tools.deps.alpha {:git/url ""
:sha "d492e97259c013ba401c5238842cd3445839d020"}}
:aliases
{:repl {:extra-deps {org.clojure/tools.nrepl {:mvn/version "0.2.13"}
cider/cider-nrepl {:mvn/version "0.17.0"}}}
:local {:override-deps {rakk {:local/root "/Users/sideris/devel/rakk"}}}}}
but when I do clj -Sforce -R:local:repl -Spath
I see that rakk is coming from git rather than the local dir
This doesnāt work yet
Thereās a ticket for it
thanks!
@alexmiller is it the particular combination of git+local or overriding doesnāt work in general?
@alexmiller also do think in the future there may be a way to say āalso merge this local deps.edn into the main mapā to avoid having to commit machine-specific paths to git such as "/Users/sideris/devel/rakk"
The issue is with changing and comparing versions across coord types
hm, I can imagine how that could be a problem
Iām trying to understand your other question there
And how itās different from -Sdeps
-Sdeps replaces deps.edn, correct? I was looking for something that would merge a snippet into an existing deps.edn
no it merges over the rest
it acts as a final deps.edn in the merge chain
oh sorry, that would work then
> -Sdeps DEPS Deps data to use as the final deps file the word āfinalā threw me off, I thought it meant that it replaces everything
maybe ālastā would be less ambiguous, maybe itās just my brain š
thanks for clarifying
Hello fellow Clojurians, I just wanted to put out a general question for the community. What is the benefit of writing css using garden compared to just writing plain old css in css files?
presumably, b/c itās data and you can manipulate it as data
but if you donāt need to do that, then thatās not much benefit
Yeah that's what I thought, from what I've seen it's typically written in clojure. The downside I see to this is if you want to manipulate it you'd have to do it on the backend. The main benefit I was hoping to get out of it is to have dynamic css within clojurescript, where events would trigger changes in css. However I haven't found a great way of doing so.
hi i'm trying to use java.io.copy to save an html uploaded image to local disk and when i invoke` (copy (io/file tempfile) (io/file "some-dir-name-i-just-invented-because-i-want-a-new-file-here.jpg"))` i'm informed that the destination file doesn't exist. scratches head
@sova just to check, are you calling:
(io/copy (io/file "tempfile") (io/file "new.jpg"))
?@sova I don't think copy creates directories implicitly
but there's a separate method on File that will do that given a File object
i need to have the directories exist already
it works! š
this is an intentional feature btw - for example it can prevent a bad user input from making you create a file on a malicious path
excellent. now this image board will actually work now.
yeah good call. and i'd rather not accidentally create ten thousand directories just trying to see where stuff gets saved
thanks for your help guys. step by step great accomplishments
Out of curiosity, does anyone recognise getting a StackOverflowError java.util.regex.Pattern$BmpCharProperty.match
exception when running (apply str a-large-coll-of-strs)
?
Itās rather puzzling how itās happening. If it helps the coll contains seqs of the file contents from an unpacked zipfile.
I would guess you a regex searching the string after you are constructing it, and the error is being thrown there
it could be an error in something lazy that created a-large-coll-of-strs
Possibly, Iāve got a zipfile and a reducer which pulls out the content of a matching file, so I get a big list of strings. Big being relative, (count coll)
gives me 1004.
(every? string? coll)
gives me true.
so Iām pretty sure I only have strings in there, but (apply str coll)
just throws the exception
Iām more than willing to admit my java interop isnāt great, but Iām really not sure whats up hereā¦
how sure are you that the apply str is what is throwing the exception? do you have a stracktrace with its line number?
apply str doesn't do anything with regexs, which is why I am asking the question about how sure you are
Not certain, thatās why Iām really puzzled. The problem is the error is a stackoverflow error, and I have no idea how to read something that deep
*e
just gives me:
elided at the top as it goes off the terminal
...
[java.util.regex.Pattern$BmpCharProperty match "Pattern.java" 3798]
[java.util.regex.Pattern$GroupHead match "Pattern.java" 4658]
[java.util.regex.Pattern$Loop match "Pattern.java" 4785]
[java.util.regex.Pattern$GroupTail match "Pattern.java" 4717]
[java.util.regex.Pattern$Curly match0 "Pattern.java" 4272]
[java.util.regex.Pattern$Curly match "Pattern.java" 4234]
[java.util.regex.Pattern$CharProperty match "Pattern.java" 3777]
[java.util.regex.Pattern$BmpCharProperty match "Pattern.java" 3798]
[java.util.regex.Pattern$GroupHead match "Pattern.java" 4658]
[java.util.regex.Pattern$Loop match "Pattern.java" 4785]]}
near the top (at the top modula things like reflection) will be the line that caused the error
the point is your error happened a long time before (apply str ...
its just the the computation was delayed until it was realized here
yep, just trying to remember how to do print -> str so I can take the first 200 characters.
(.printStackTrace *e)
my guess, entirely unsupported at the moment, is you are printing the big string out at the repl, and your repl client is actually trying to run a regex on it
@dpsutton Spec would have been a more readable solution.
you can use clojurescript (on nodejs). If you wanted some framework, you could use macchiato https://macchiato-framework.github.io/
I would recommend using learning clojure to get over whatever prejudices your have acquired against the jvm
there is a self hosted clojurescript effort, but I am not sure how much that is used, and there is a clr clojure port which is battling against the static language trend on the clr
Oracle are going to charge for Java SE, the latest developments will be paid for, so over time the openjdk efforts are going to be under a lot of pressure
it sounds like maybe you only read the title on a hacker news link? I see oracle is going to start charging for support of java se releases that are older then what they have stated they will support
openjdk is now the official, canonical distribution -- they start with implementing Java specs in openjdk. It's GPL
Clojure works just fine on the Oracle JVM.
right, it targets 1.6, there's been talk about upgrading to 1.7 for invoke-dynamic but I don't think that's actually on the radar yet
is it the emitted java code or emitted bytecode that targets 1.6. My knowledge of jvm internals is quite thin
bytecode is generated for 1.6, the java is compiled to emit bytecode for 1.6 also
there is no java code emitted anywhere
cljs and clj-clr are both up to date, and both are able to do everything to interop with their host that jvm clojure can do, up to the limits of the host
the difference is that there's less of an ecosystem with tooling and libraries for those platforms
(but cljs comes close)
cljs runs on nodejs, or rhino, or a browser js, there's also planck which self-hosts with OS provided js apis
but most libraries use features only found in a browser or node
clj-clr runs with microsoft's clr or mono
pretty happy about http://www.jenv.be
I set JAVA_HOME
using java_home
, which is sufficient. Example:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export JAVA_HOME
doesn't help you much when you have non-cmd apps that use JDKs. I'd like to look at jEnv at some point.
Currently, I set JAVA_HOME
env variable in ~/Library/LaunchAgents/environment.plist
is there a way i can invoke a function with an optional argument / arity 3 but sometimes 4
something like
(([one two three] ...
([one two thee free] ..))
perhaps?okay. i call this function on a /post command. it has an optional image parameter. i want to do that only when image isn't nil... i don't want to write nearly duplicate functions for slightly different scenarios... so maybe i will just always pass four and have that fourth one sometimes be nil.
turns out just letting it be nil is a great option. haha
Anyone see a problem with picking one naming convention for a project, rather than using language-specific conventions at each layer of your stack? Seems more trouble than itās worth to relate user-id in clojure to user_id in postgres and to userId in frontend (typescript) code.
I know the answer is ādo whatever you want if itās all your codeā. Just interested in other opinions
I don't mind the stack specific convention, because trying to force one can sometimes be much more difficult than it seems, say if something you have no control over is introduced and it needs things to be stack specific convention to work
Related: https://clojureverse.org/t/should-we-really-use-clojures-syntax-for-namespaced-keys/1516 Personally, I favor "portable" over "idiomatic"