This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-10
Channels
- # beginners (97)
- # boot (77)
- # cider (7)
- # cljs-dev (47)
- # cljsrn (3)
- # clojure (125)
- # clojure-austin (5)
- # clojure-dusseldorf (1)
- # clojure-italy (4)
- # clojure-russia (91)
- # clojure-spec (80)
- # clojure-uk (54)
- # clojurescript (92)
- # core-async (6)
- # cursive (17)
- # datomic (56)
- # hoplon (7)
- # immutant (3)
- # liberator (3)
- # luminus (4)
- # off-topic (26)
- # om (41)
- # om-next (11)
- # pedestal (3)
- # perun (3)
- # protorepl (25)
- # re-frame (32)
- # reagent (33)
- # ring (46)
- # rum (3)
- # spacemacs (5)
- # specter (82)
- # test-check (16)
- # untangled (8)
- # yada (26)
This is huge. > Writing navigators or higher-order navigators is much simpler now. If you want to write a regular Clojure function that returns an anonymous navigator, you can now do that without sacrificing performance.
@nathanmarz : does the following get the higher level ideas: (transform selector func data), modulo pseudo selectors like LAST and pseudo funcs like NONE, ops as follows: using selector, creates a list of "references" into data for each ref, we fun (func) on it, and put the new value in so old style coding = I need to update this data structure I "drill down" to the pieces I want to modify, update them, and "rebuild everything else" in spectre, I specify the "drill down" with the selector, and specter takes care of rebuilding/drilling down, and thus I need only specify the update function
basically
@qqq: not sure why you call LAST
pseudo, it's no different than anything else
so you're not pointing at the last element of the list, you're pointing at the region after the alst element
i think you're referring to END
location can mean more than a specific value inside a data structure, the empty subsequence at the end of a sequence is a perfectly valid location
manipulating data structures using their inherent substructure is extremely useful and leads to very elegant code
@nathanmarz : I'm sold; specter is awesome. Thanks for your explainations.
no problem
Hi all, my lein repl
is not savvy to a .clj file I added into my /src/clj directory. It shows me plenty of autocomplete options, but not the namespace I just added. Thoughts?
You can specify a sources directory https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L295
You may also need to "require" that namespace to be able to use it.
(use 'proj.core)
OR (require '[proj.core :refer :all])
now you can (foo)
all you like @sova
Actually, I’d go with (require '[proj.core :as pcore])
. It’s a good idea to use namespace aliasing for clarity.
specter is life changing; I don't want to ask individuals to suggest other awesome libs, as that'd clog up the channel -- is there a list of other really impressive ltools? (not so much libraries for handling specific tasks, like db bindings of web servbers; but generic libraries that changes everday clojure development)
https://clojure.org/guides/destructuring <-- when destructuring with {:keys [ ... ]} is there a way to also use an :as field ?
I'm writing a spec. How can I check if something is an atom ? (Perferably reagent/atom should also return true).
@qqq search for "awesome clojure" on github. there are a couple of repos.
is there a way to detect if I'm currently running inside a REPL (as opposed to running a JAR file via java -jar ...
)?
@luxbock .. Use different entry points
My use case is that I want certain functions to exit when ran as a script but I don't want this to happen when I'm playing around in the REPL
@luxbock Use start/stop functions in -main, which would close any resources etc. See mount
i have a fn with two args. One of them must be supplied. i need a default action in a let, similiar to javascript let data = arg1 ? arg1 : arg2
any nice idiomatic way to do that? fumbling through if seems like a lot to ask...
(or arg “default”)
i simplified too much 🙂. i need a transformed arg1 into a [:user/email arg1] and if no arg1 i need [:user/uuid arg2] 🙂
(if arg1 [:user/email arg1] [:user/uuid arg2])
🙂
Clojure has no ternary operator. doesn’t need one
perfect 🙂
still stumbling 🙂
you’re doing fine. keep trucking
@robert-stuttaford or rather Clojure has no if statement 🙂
schooled 🙂
still stumbling!
core.unify hasn't been touched in a while. Is it still recommended over core.logic for little bits of unification when a full logic programming system isn't needed, or should I skip straight to core.logic?
(mount/start) works just fine from repl but not loading any states from lein run or uberjav -main
@luxbock, @h.elmougy: > My use case is that I want certain functions to exit when ran as a script but I don't want this to happen when I'm playing around in the REPL I think the question is more about a design rather than a tool. Regardless what tool you use JVM will exit unless there are threads that are doing something. If you want "functions to exit when ran as a script" they just should not wait for anything (i.e. occupy threads / have servers running, etc.), and the program/JVM will exit. You can run the same functions form the REPL, and depending on whether they use any threads / sync / async they will run and give the control back to the REPL.
I already starting (mount/start) on a separate thread but no defstates marcos called
@h.elmougy, not following. is it related to @luxbock's question. and what is the problem? 🙂
@tolitius (mount/start) works just fine from repl but not loading any states from lein run or uberjav -main
@h.elmougy: (mount/start)
is just a function. if called from -main
, it will start any state that is on a classpath.
@tolitius Thanks it is not started, I got them to start by importing certain states into the core namespace.
@h.elmougy: yep, all you need is to :require
states you care about, so it is visible to the namespace you use them in. same as any other var/function. i.e. https://github.com/tolitius/stater/blob/master/neo/src/neo/app.clj
Where is an appropriate channel to ask for ring help?
#ring
Ha. Thanks.
What's the proper way to generate edn from clojure data? pr-str
can't be it, because (clojure.edn/read-string (pr-str #"foo"))
throws. Or is there no good way to deal with regular expressions in edn?
ghosss not by default: https://github.com/edn-format/edn
if I wrote a data reader that could read them, how could I make sure regular expressions were written with my tag?
sure, but clojure.edn/read-string
can't handle that output, and you can't write your own edn data reader for #"
so it sounds like I have to generate the edn myself instead of relying on anything clojure provides
if it were regular expressions alone, that might not be so bad, but I'm dealing with large data structures that may have regular expressions anywhere within them
I wonder why this is commented out https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/EdnReader.java#L53
I hope I'm not. Some process gives my code some data structure that has regular expressions in it, I need to write it out to edn and have that edn read later. Before regular expressions showed up in the data structures, I could use pr-str
on it and clojure.edn/read-string
would read it just fine. But now that regular expressions showed up, pr-str
's output isn't good anymore, and I don't see how I could tell it to output regular expressions differently. Is there a way to do that?
you'll need to replace the regexes with a custom object which implements the printer protocol I think. it's a little bit of annoyance
https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/analyzer.cljc#L90
@ghosss you can override print-method
for regexes if you don't mind the global change
otherwise https://github.com/greglook/puget is more configurable
I have a clojure data made up of vectors, lists, and maps. I want to update each "leaf node" with "the path to the leaf node", for example
{:a {:b [:apple :orange :pear]
:c [:juice]}
:e [:cat :dog]}
to
{:a {:b [[[:a :b 0] :apple]
[[:a :b 1] :orange]
[[:a :b 2] :pear]]
:c [[[:a :c 0] :juice]]}
:e [[[:e 0] :cat]
[[:e 1] :dog]
]}
^^ what is the simplest way to do this?(defn path-inject
([col] (path-inject [] col))
([path col]
(cond
(map? col) (into {} (map (fn [[k v]] [k (path-inject (conj path k) v)]) col))
(vector? col) (vec (map-indexed #(path-inject (conj path %1) %2) col))
:else [path col])))
=================================== Is there a clojure builtin for the following:
(defn const [f & args]
(fn [& rest] (apply fa rgs)))
looks like constantly
only not quite
What's a better way to express this set of specs? Basically, I need to be able to pass a map specifying a shift or shifts (with an optional count) and an optional follower-shift(s) (again with an optional count).
(spec/def ::shift-shorthand #{:other :out :off :shift})
(spec/def ::shift (spec/and int?
#(> % -3)))
(spec/def ::shifts (spec/or :shifts (spec/coll-of ::shift)
:shift-shorthand ::shift-shortand))
(spec/def ::shifts? (spec/or ::shift ::shifts))
(spec/def ::count (spec/and int?
#(> % 0)))
(spec/def ::counted-shift (spec/cat ::shifts? ::count))
(spec/def ::follower ::shift)
(spec/def ::followers ::shifts)
(spec/def ::followers? ::shifts?)
(spec/def ::counted-follower ::counted-shift)
(spec/def ::rule
(spec/keys :req [(spec/or :shift ::shifts?
:counted-shift ::counted-shift)]
:opt [(spec/or :follower ::followers?
:counted-follower ::counted-follower)]))
Technically, the :other
and :shift
shorthands are defined relative to the shift specified for the rule.
And really the rules should be defined in terms of a single shift (optionally counted) and an optionally-counted follower or followers.
why are you defining ::follower
(all versions) to be the same as ::shift
(all versions)?
A follower is only different for the purposes of these rules in that it's the shift that follows the specified shift.
Basically, we're defining rules like "The same employee works shift 1
five days in a row, and then has a day :off
.
do you need all these levels of indirection? seems like a lot could be defined inline. also there is an int-in-range?
Where :off
references shifts [0 -1]
, corresponding to "unassigned" and "personal time-off request" respectively.
Basically, the user picks a shift from the set of shifts they've defined, specifies a count of however many in a row, optionally specifies the following shifts (what the previously specified shift gets followed by) as either a specific shift, a shorthand (`[:other :off :out]` where :other
is everything that isn't the first shift), or a custom set of shifts that don't include the first shift.
gotta go now but may look at it later if you are still working on it -- IMO yes you can simplify most likely
Thanks, @joshjones.