This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-22
Channels
- # architecture (9)
- # beginners (90)
- # cider (98)
- # cljs-dev (23)
- # cljsrn (4)
- # clojure (101)
- # clojure-brasil (3)
- # clojure-dev (48)
- # clojure-italy (15)
- # clojure-losangeles (3)
- # clojure-russia (12)
- # clojure-uk (17)
- # clojured (1)
- # clojurescript (141)
- # community-development (15)
- # core-async (1)
- # datascript (12)
- # datomic (18)
- # docker (3)
- # emacs (1)
- # events (1)
- # figwheel (1)
- # fulcro (57)
- # graphql (4)
- # javascript (9)
- # jobs (1)
- # lein-figwheel (1)
- # leiningen (1)
- # lumo (1)
- # off-topic (68)
- # om (9)
- # om-next (3)
- # onyx (4)
- # parinfer (6)
- # pedestal (14)
- # portkey (2)
- # proton (1)
- # protorepl (19)
- # re-frame (57)
- # reagent (46)
- # ring-swagger (12)
- # shadow-cljs (167)
- # slack-help (5)
- # specter (18)
- # sql (1)
- # uncomplicate (3)
- # unrepl (1)
What are your opinions of evil mode for emacs and CIDER/Clojure? Some cursory googling tells me some people love it and others find it conflicts with important hot keys.
@mpcarolin It works fine with spacemacs, though it's hard to get stuff like Sayid to work without understanding more than I know about it
There's #editors and #spacemacs and #emacs channels in case you want more specific feedback (since this isn't really a Clojure question).
What do you mean by "unrequire"?
You can ns-unmap
and ns-unalias
all the public symbols in a namespace... is that what you mean?
there's a bug in the autoocmplete library if you require a namespace with an alias of user
. so i want to write a test and to do so i need to require a file with that alias. and if possible i'd like to "unrequire" after the test
you also need to do one more thing: you have to remove the namespace from the *loaded-libs*
ref, using require
checks this cache and if it’s in there, it won’t load your namespace
What about any side-effects of loading the ns? What about defonce
where the ns has been require
d twice -- what would "unrequire" once do? what would "unrequire" twice do?
(facts "about resolving namespaces"
"can resolve a namespace aliased as user"
(require '[compliment.context :as user])
(fact "found the aliased namespace"
(resolve-namespace 'user *ns*) => (find-ns 'compliment.context)))
was just wondering if it was a thing. it's all pure so no side effects. just wondering if it was possible to tidy up after myself
Well, require
is inherently not pure...
And that's Midje isn't it? shudder
Yeah, it crept into clj-time
as a way to test/check the expressions in the readme and I've been trying to extricate us from it ever since...
@dpsutton FWIW this is what tools.namespace does to ensure a namespace is removed so it can be loaded again: https://github.com/clojure/tools.namespace/blob/master/src/main/clojure/clojure/tools/namespace/reload.clj#L15-L19 may not be elegant, but may help unblock your test
That does nothing for any side-effects of loading the namespace tho'...
It's not blocking. I was just wondering if there was a simple solution. All I really want is for the ns interns to report that there is a namespace called 'user' and that one be resolved over the user name space
But PR is in and unless the author has any complaints I'm good. Thanks for the suggestions and ideas though everyone
But the tools namespace stuff looks cool. I was reading about agents in Alex's recently released book tonight
is there a way to create a namespace whose sole purpose is to export defs, for example, to create
i think people use https://github.com/ztellman/potemkin#import-vars for that
to create a qq.clj whose sole purpose is to export some functiosn from q/a.clj , q/b.clj, q/c.clj, q/d.clj, etc ...
is there a (clojure|java) lib that does username normalisation/filtering according to rules such as what's described here: https://www.b-list.org/weblog/2018/feb/11/usernames/ ?
I hate his suggestion that emails should be stripped like that. There's plenty of email servers that wouldn't route those to the same place. Plus it's a feature that I can sign up multiple times with different emails, not a bug.
I personally use <mailto:[email protected]|[email protected]> all the time, I hate it when it's rejected
I ended up porting it quick&dirty: https://github.com/mpenet/thorn
Hi everyone. Is there a function to get the namespace part of a qualified keyword? That is, (ns-part :test/key) => "test"
yes, namespace
🙂
try name
too
Do you guys know a Clojure library that provides REPL helpers similar to the ones in Elixir ? https://hexdocs.pm/iex/IEx.Helpers.html
Take a look at this library - https://github.com/bhauman/rebel-readline
I'm already using https://clojuredocs.org/clojure.repl, but the functions are more basic (both in term of information and layout)
any idea why this isn't working:
=> (def T true)
=> (case true T "true" false "false" "else")
"else"
@ido The case here is doing the same as (= true 'T)
the little '
means this is being treated as a symbol.
You can use condp
instead if you like:
(def T true)
=> #'user/T
(condp = true
T "true"
false "false"
"else")
=> "true"
yea, also match
works:
=> (require '[clojure.core.match :refer [match]])
=> (def T true)
=> (match true T "true" false "false" :else "else")
"true"
To serialize a Clojure data structure that can later be read by clojure.edn/read-string
, would I just use clojure.core/pr
?
@patrkris before handing a data structure over to pr-str
it is your responsibility to ensure every element within it converts to edn correctly, just fyi. It catches me out.
I have a quick question/comment on clojure.java.jdbc using a SQLite database. When I do an insert, I get back a result of the form {:last_insert_rowid() 5}
. I can pull the id want out using (get result (keyword "last_insert_rowid()"))
, but it really feels like there shouldn't be those parentheses in that result keyword. Anything I can do about that?
clojure.java.jdbc has the ability to pass in a function that is then used to map the column names sql sends back to map keys
@jlfischer Unfortunately each different database returns generated keys in a different way so it's hard for clojure.java.jdbc
to do something generic to just return the key value itself (PostgreSQL helpfully returns the entire inserted row, for example, and some databases don't return generated keys at all). I tend to do (-> (jdbc/insert! ...) first vals first)
for DBs that I know will return a ResultSet containing one row with a single key/value pair for the key. In MySQL, you can shorten that to (-> (jdbc/insert! ...) first :generated_key)
but SQLite is not so amenable...
(I could write a utility function for that but then I'd need to require/refer it everywhere so the inline ->
is less work)
What's the best way to update a value within a nested vector? Should I be using something like (update-in [["a" "b" "c"]["d" "x" "f"]] [1 1] "e")
? (and before you say it, yes, I know this code errors )
update fns take a function, not a value: (update-in [["a" "b" "c"]["d" "x" "f"]] [1 1] (constantly "e"))
assoc is better as mfikes said
I was trying assoc-in
initially. Glad I was on the right track. Thanks for the input
When using`clojure.core.memoize/ttl`, is there a way to get the "age" of the cache? Or the time the data was cached?
@alexmiller @mfikes In that particular instance, using (constantly "e")
with assoc-in
puts the reference to the function instead of the actual value "e"
into the nested vector
Ah, that's weird. I was sure I tried that before
Must have had a type
Thanks Mike 👍
hiya! regex one. trying to pull multiple words out of a parenthesized group. but I only get one
;; input: (re-find magic-regex "foo bar baz DELIM")
;; desired output: [_ "foo " "bar " "baz "]
it’s something, but I bet someone else can offer something better:
=> (re-seq #"([a-z]+)\s(DELIM)?" "foo bar baz DELIM")
(["foo " "foo" nil] ["bar " "bar" nil] ["baz DELIM" "baz" "DELIM"])
probably better as a two-step process:
=> (map #(re-seq #"\w+" %) (clojure.string/split "foo bar baz DELIM qux abc 123 DELIM" #"DELIM"))
(("foo" "bar" "baz") ("qux" "abc" "123"))
two-step may or may not be a good choice for my specific case. I was trying to build something on top of pure regexes (as opposed to computations)
javascript has this handy shorthand where if the key of the map happens to be the same as the value, you can write { thing }
instead of { thing: thing }
. Is there a similar shorthand in clojure?
could probably do something with a reader tag but map literals right now need an even number of expressions
this is a thing I copy-paste a lot: https://github.com/amalloy/useful/blob/develop/src/flatland/useful/map.clj#L9
but maybe like a reader literal can parse #my/map [:key val symbol :other key] etc. and expand it into a map literal, but clojure maps can have more types as keys than js ones.
@gtrak yeah I use a simplified version of that
(cmd)user=> (defmacro keyed [& vs] (into {} (map (juxt (comp keyword name) identity)) vs))
#'user/keyed
(ins)user=> (keyed + * -)
{:+ #object[clojure.core$_PLUS_ 0x180da663 "clojure.core$_PLUS_@180da663"], :* #object[clojure.core$_STAR_ 0x340da44c "clojure.core$_STAR_@340da44c"], :- #object[clojure.core$_ 0x37052337 "clojure.core$_@37052337"]}
for some reason I find being able to make a macro with 0 quoting quite pleasing
related
(cmd)user=> (defmacro locals [] (into {} (map (juxt (comp keyword name) identity)) (keys &env)))
#'user/locals
(ins)user=> (let [a 0 b 1] (locals))
{:a 0, :b 1}
that one felt like black magic when I figured it out haha
all of those years of c++ and i’m still disconcerted by the idea that changing what feels like a variable name changes data
locals
invalidates some common sense clojure expectations about scope and explicitness which makes it feel spooky
but hey I use it as a debugging tool, debugging tools are allowed to be evil because they shouldn’t even get checked into git