This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-17
Channels
- # bangalore-clj (1)
- # beginners (23)
- # boot (141)
- # cider (68)
- # cljs-dev (29)
- # cljsjs (1)
- # cljsrn (11)
- # clojure (150)
- # clojure-austin (3)
- # clojure-berlin (1)
- # clojure-france (2)
- # clojure-greece (13)
- # clojure-italy (5)
- # clojure-russia (49)
- # clojure-spec (15)
- # clojure-uk (45)
- # clojurescript (152)
- # code-art (1)
- # core-async (75)
- # cursive (12)
- # datascript (2)
- # datomic (90)
- # dirac (5)
- # emacs (10)
- # garden (1)
- # hoplon (52)
- # instaparse (4)
- # juxt (2)
- # lein-figwheel (2)
- # lumo (47)
- # mount (94)
- # off-topic (20)
- # om (21)
- # onyx (14)
- # parinfer (19)
- # pedestal (3)
- # protorepl (13)
- # re-frame (5)
- # reagent (20)
- # slack-help (10)
- # spacemacs (8)
- # specter (57)
- # unrepl (11)
- # untangled (3)
- # vim (1)
- # yada (1)
@facundo If you are interested in Expectations, we have an #expectations channel here...
Any recommended resources for error handling best practices? Vague question I know, just testing the waters
what is the point of datascript/datomic's query lanauge? I feel that given a :find .... :where .... with n clauses, I can convert it into a for loop with n clauses -- so there must be some additional power of the datalog query langauge that I'm missing
user=> (split "Some words to split" #"\s+")
["Some" "words" "to" "split"]
suppose I wanted not only the words, but also the spaces between the words, (in case words are separated by more than one space) -- is there a way to get this also?@qqq yes, you can basically convert a datalog into nested for loops, however, it's often slower since Datomic's datalog is set-based, meaning it can remove duplicate results ending in less joins required by subsequent clauses. Also, recursive queries are almost impossible to do with nested loops.
Speaking of datomic, datalog, and sets, I came across http://aosabook.org/en/500L/an-archaeology-inspired-database.html the other day
@qqq You can use lookbehind:
boot.user=> (str/split "These are some words" #"(?<=\s+)")
["These " "are " "some " “words”]
Not sure if that’s quite what you want but I suspect a combination of that and lookahead should work...
Oh, nice!! I hadn’t run across that before.
Ah, and it matches both beginning and end… very useful!
Oh, @qqq I'm assuming you wanted the spaces as separate elements, rather than what @seancorfield did.
And here’s me aiming for something complicated like this:
boot.user=> (str/split "These are some words" #"(?<=\s+)|(?=\s+)")
["These" " " "are" " " "some" " " “words”]
Mine would break out each space as a separate match:
boot.user=> (str/split "These are some words" #"(?<=\s+)|(?=\s+)")
["These" " " "are" " " " " " " "some" " " " " " " " " "words"]
“I have a problem… I think I’ll use a regex” … and now you have two problems!
Is it becasue it matches things that have zero or more spaces before or after them, and the spaces have that, i.e. at least zero spaces surrounding them?
Is there in Clojure any way to get access to bindings from parent scope? E.g. like
(let [a 1]
(let [a 2]
(print (super a)))) ;; => 1
(let [a 1]
(let [a' a
a 2]
(print a'))) ;; => 1
(I guess the question is really: what is the situation where you are shadowing a binding but still need access to the previous binding?)
actually my knowledge where clojure use dynamic and where lexical scopes not full yet, so, yes, question about access to lexical parent scope (I guess, we can't deal with shadowed dynamic value, right?)
you can access the value from a parent scope, as long as you have not shadowed it
if you shadowed it, and don't have an alias in scope, there's no sane way to access the parent scope directly
thanks. Here another example which not clear for me:
user=> (let [p 1] (eval '(print p)))
CompilerException java.lang.RuntimeException: Unable to resolve symbol: p in this context, compiling:(/tmp/form-init5764583318142605948.clj:1:19)
so we can't eval lexical scoped symbols?eval doesn't use your lexical scope
it's easy to work around by using a function and passing an arg
(that is, if you actually need eval, generate a function, and pass in the lexical bound value)
there's no macro there
that's just a quasiquote
(but yeah, quasiquote can help too)
+user=> (let [a 0] ((eval '(fn [x] (println x))) a))
0
but quasiquote is just a sugar for building up a list that happens to have your local value in it
+user=> `(foo bar baz 22)
(user/foo user/bar user/baz 22)
Hi, folks How to call function from another namespace at application launch? For example, I want to make registry of record constructors, then find constructor by key:
; namespace A
(ns A)
(def registry (atom {}))
(defn register [key creator-fn]
(swap! registry assoc key creator-fn))
; namespace B
(ns B
(require '[A :refer [register]]))
(defrecord MyRecord [a b c])
(register :my-key #(->MyRecord %1 %2 %3))
When I load my program using repl registry in A is empty. It populates only when I re-evaluate B file in repl. @armed You can use ((resolve 'some.namespace/some-symbol) argument)
to invoke a function after loading its namespace.
@stuartsierra thanks, I'll try
is there a wrapper where I just provie the [result input] form, and it creates a tranducer for me automaticlaly, with ([] (xf)) ([result] (xf result))
https://github.com/clojure/clojure/blob/010864f8ed828f8d261807b7345f1a539c5b20df/src/clj/clojure/core.clj#L6575 seems different from what I want
(defn make-fn [f]
(fn [xf]
(fn
([] (xf))
([result] (xf result))
([result input] (f xf result input)))))
is there anything similar to the make-fn ?transducer returning one item is: (xf result item)
returnint 2 items is
(-> result
(xf item1)
(xf item2))
now, supposed I need to return a list of items, is it
(reduce xf result lst)
this just seems like a weird use of reducethere's unicode, parameterized by mood
interesting, how about
(apply concat (for [ ... ] .... ))
is there a way to simplicy this? I know about mapcat
but I want to use for instead of map
@qqq most of the time you can avoid the concat with for
oh weird, it macroexpanded my '
but then I guess you can do (for [el coll x (f el)] x)
rather than (apply concat (for [el coll] (f el)))
Say, is there any way to get a list of vars out of a namespace in the order they were defined in the file? (Looking for something similar to (ns-interns)
but maybe returning a sorted map)
@timgilbert you can use the :line
metadata of each var
Oh, good idea, thanks!
@spei: yeah, often times, the function doesn't ahve a name, and is multiline, and I want to write it inline, instead of defining it elsewhere
@spei: so it's genrally (map/for, where list = very short expr function = multi line so for just tends to look better than map, atleast to me
but for can do what mapcat does, just by adding a clause in its binding block
@timgilbert be careful about using a sorted map (or set) because you can in principal have 2 vars share the same line e.g (do (def foo) (def bar))
or (declare baz qux)
I guess this also means if you want order of definition it is ambiguous in these cases from the metadata 😞
I'll keep it in mind, thanks @danstone. For my use-case it shouldn't be a problem; I'm making kind of a mini DSL based on defns, and it's code we're writing ourselves, so I can use pull request mockery and shaming to ensure we have at most one defn per line
Ha, but yeah, good point about :column
@qqq you can write a fairly cannonical looking multiline map by
(map
(fn [x]
(f x))
coll)
Hello. Does anyone know why uberjar may be built successfully without aot but throw java.lang.ClassNotFoundException
with aot (3rd party dependency)?
my guess is some variant of http://dev.clojure.org/jira/browse/CLJ-1544
@hiredman i thought there's a startup penalty without aot to make what aot actually does
there can be, you can look at http://dev.clojure.org/display/design/Improving+Clojure+Start+Time
I think you’re imagining things… I can’t think of any changes between 1.8 and 1.9 that would affect that? I haven’t noticed any speedups (although we moved to 1.9 a long time ago so my memory may be hazy).
Hey everyone. Just wanted to say thanks for being awesome!
@nooga @seancorfield there were some minor changes to seq & destructuring and update-in
perf - it’s possible these would have a little boost. And CLJ-1423 does have some nice benefits for apply
.
but it seems unlikely any of that would be very noticeable in compilation
@alexmiller @seancorfield yeah, I must have imagined this :(
is there any way to get the ns of a namespaced map? or, is there an online 1.9 repl i can use to experiment?
+user=> {:foo/bar 1}
#:foo{:bar 1}
+user=> {:foo/bar 1 :foo/baz 2}
#:foo{:bar 1, :baz 2}
+user=> {:foo/bar 1 :foo/baz 2 :quux/morp 3}
{:foo/bar 1, :foo/baz 2, :quux/morp 3}
@mobileink a namespaced map is just a convenient read/print syntax, it isn't a typeright, my use case is, it would be Nice if i could use the map's ns to drive processing.
but the map doesn't have an ns - the reader form for a map can...
@mobileink I guess as a hack you could check pr-str
and see if it starts with #:...{
and extract the ... if so - but it's not a property of the map itself
you chould do something like (apply = (map (comp namespace first) some-map)) to determine if every key in a map has the same namespace
bja but the keys don't have to be things that can have namespaces
yes, this will inevitably lead to confusion, i suppose. but it doesn't really matter if a namespaced map is a map with a namespace or not. we can in fact use #:foo to namespace the keys of a map. it would be easy enuff to iterate over the keys to discover a common ns, if there is one, but i was hoping clojure had an op that would save me the trouble.
in the general case they don't, but I'm assuming that in the case of the person who wants to drive processing off the namespace of keys in a map, they are keywords with namespaces
@bja: fyi the idea (just an idea at this point) is that the user can use #:foo{...} to select the foo implementation that interprets the map. all keys are kws, which may be different for different nss.
@mobileink you could pretty easily do this via a multimethod with the dispatch function being (fn [m] (when-let [namespaces (map (comp namespace first) m)] (when (apply = namespaces) (first namespaces)))
i'm just getting started with spec. is there a way to specify that all keys in this map must be namespaced either :foo or :bar?
I'd probably write it such that I validated a schema of {s/Keyword s/Any}
, but you can do the same thing with spec (I just don't know how to use spec yet)
@mobileink How about (symbol (subs (first (clojure.string/split (str :foo/bar) #"/")) 1))
?
anyone use the cursive ide here? after an intellij update i can't type in the REPL input windowpane any more--the tooltip says "This window is read-only". Any ideas?
@a2_himmel There's a #cursive channel that's pretty active - I can follow up with you there
@shaun-mahood yeah, just found that and moved the question there
Dumb question Fridays. Is there a simple way to start a REPL into an existing java process? Meaning, we are running sth like
java -classpath blah.jar blah.core
, now is there a way to connect a REPL to that running process?@erichmond you have to do something to explicitly have clojure start a repl either through using the system property (read on start up) https://clojure.org/reference/repl_and_main#_launching_a_socket_server or calling the function https://clojure.github.io/clojure/clojure.core-api.html#clojure.core.server/repl
longer answer is no, but if you happen to have debugging enabled, you might be able to do it
hiredman / tanzoniteblack Thanks guys! for some reason I thought I had done this in the past (3+ years ago), but it must have been a fever dream
https://github.com/wirde/swank-inject is an older swank project that uses the java debugging interface to inject a repl
I am not sure if a modern project to do it exists, but a similar approach would work to start the socket repl
Do you guys know off the top of your head if there is any appreciable performance hit to spawning a REPL from the process as tanzoniteblack suggested above?
actually, it sounds like after java 5 the java debuging interface is always enabled, so something like swank-inject could just work
at my last company, we tended to have any running servers start a repl that was only connectable from the local machine (i.e. through port forwarding) as part of their normal process. Never seemed to have any effect on performance (ignoring the effect on performance you might cause by running code in that repl)
but was incredibly useful when we did happen to need to debug a production issue
obviously such things should be treated with incredible caution in production 🙂