This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-10
Channels
- # aws (3)
- # beginners (186)
- # boot (25)
- # cider (2)
- # cljsrn (57)
- # clojure (161)
- # clojure-boston (1)
- # clojure-dusseldorf (11)
- # clojure-italy (5)
- # clojure-russia (20)
- # clojure-serbia (1)
- # clojure-spec (10)
- # clojure-uk (16)
- # clojurescript (207)
- # community-development (86)
- # core-async (2)
- # cursive (40)
- # datascript (1)
- # datomic (2)
- # editors (5)
- # emacs (8)
- # funcool (1)
- # gsoc (2)
- # hoplon (2)
- # jobs (5)
- # leiningen (3)
- # liberator (18)
- # luminus (18)
- # off-topic (106)
- # om (2)
- # onyx (5)
- # pedestal (7)
- # powderkeg (7)
- # re-frame (7)
- # remote-jobs (1)
- # ring-swagger (4)
- # rum (5)
- # slack-help (1)
- # untangled (11)
- # yada (48)
the cond needs to be inside the () of the let form
right now it isn't
so it doesn't see the x that let binds
it's seeing the old x (if it can find one at all)
I don't understand why it needs to be inside the let if it doesn't modify what I assign x to
nothing can see x if it isn't inside the parens of the let
that's why let exists, to create a local scope
And you should probably indent the (:require
form hanging off that ns
form. With the atom editor I'm using, for instance, it would automagically drop the :require to the top level and wrap a closing parens around (ns bob
.
@john there was a tweedle-dee / tweedle-dum situation on my team where one person would indent things totally wrong, and the other used an editor that auto-indented, and end up automatically re-parenthesizing in ways that broke the code
like working in a madhouse I swear
it's a broken "feature" of the parinfer version in the ide I'm using, for sure. Linting my code is one thing. Changing how it works is another.
speaking of work, is there a room in here specifically for job postings and requests? or do people ask around in random rooms?
@matan @ghadi if you use weavejester/environ
you can in fact put your configuration in a map, either in your project.clj
or in profiles.clj
and the loading and parsing of that map is handled for you. If you keep profiles.clj
in your .gitignore
then you can avoid accidentally checking in the maps, and in deployment use environment variables to configure instead. This is a plus if you’re a “12 Factor App” shop. I think environ is well worth a look. In addition, I wrote a library on top of environ called “defcon” which adds a few more conveniences that I happen to prefer, like ability to cast the values to a type (i.e. integer, float, bool), the ability to supply default values, and the ability to declare mandatory config variables that must be set.
tried
(deref (future (Thread/sleep 1000) 0) 990 5)
on the REPL and got 0
. could anyone explain me why?This might seem like an odd question but when is it appropriate to use a multimethod over a conditional branch like if/else? It seems possible you could always dispatch to a type. The big trade offs seem to be: if/else branch conditions can be changed at run time. Multimethods are organize the code in a better mental model.
@felipe-campos timing precisions are not guaranteed
In core.async (not relevant here) the timer granularity is explicitly coalesced to 10ms intervals
Most repls automatically refer it in the user namespace
But if you switch to something else, it's not available
@ejemba kind of a limited subset of clojure oriented towards data https://github.com/edn-format/edn
if you want a data interchange format that has EDN's semantics but JSON's reach, look at Transit. Also designed by Rich Hickey..
How can I use replace
to change a character on a string for different characters? Like if I want to replace t
in "test"
by a
but the e
by i
and get "aisa"
?
what is everyone using to write clojurescript tests? .. something akin to the figwheel experience would be great.
@vitruvia You might want to take advantage of clojure’s list-processing tools for that instead, for example (defn tr [s] (apply str (map #(condp = % \t \a, \e \i %) s)))
I found a solution using partition and reduce here: http://stackoverflow.com/questions/9568050/in-clojure-how-to-write-a-function-that-applies-several-string-replacements
“For each character in the string, if it’s a t replace it with a, if it’s an e replace it with i, otherwise use the original character.”
As a one liner it’s less readable, just a sec
When you use map
on a string, it iterates through each character in the string, and passing it to the function. The function in this case is a condp
, which is like a case
statement in other languages.
so it’s basically matching the current character against the first character of each pair, and if they’re equal, it returns the second character of each pair. If none of them match, it returns the original character
(tr "test")
; ==> “aisa”
@vitruvia there is clojure.core/replace and clojure.string/replace . The first one is generic and can take a map of replacements, the latter is specific to strings.
and almost anytime you see condp =
you could replace it with a hashmap
in this case: (get {\t \a \e \i} % %)
but yeah, use regex instead
no, sequence functions return sequences
and the elements of a string are characters
so you get a sequence of characters back
this bot…
=> (replace {\e \a \l \p} "hello")
(\h \a \p \p \o)
=> (apply str (replace {\e \a \l \p} "hello"))
"happo"
with regexes you stay strings, and everything will be ~100x faster
the bot is /clj - but as you have seen it’s a bit buggy
ello guys i need help 1. have backend done in spring and i wanted cljs on frontend i am extreme beginner so i want to ajax-cljs that backend and use reagent to show that response i managed to make a button that sends ajax to the backend and it write to console.log can someone help me write something in browser? Like data.name or something? how do i do that?
why cant i just do this (first @response) when i put ajax-cljs response to atom to get first element of that response which is
what’s the type of the result @lepistane is it a JS array or is a ClojureScript vector/seq?
yeah, print it using (js/console.log ...)
.. this will help make it clear if its a JS object or a Clojurescipt one.
@verma this is what i got printed function (meta,cnt,shift,root,tail,hash){ this.meta = meta; this.cnt = cnt; this.shift = shift; this.root = root; this.tail = tail; this.hash = hash; this.cljs$lang$protocol_mask$partition0$ = 167668511; this.cljs$lang$protocol_mask$partition1$ = 8196; }
beginner question about clojure concurrency constructs and jvm concurrency: what’s the general kind of concurrency construct I want to reach for if I need to puts 100s of long running blocking operations in flight?
cljs.core.PersistentVector {meta: null, cnt: 4, shift: 5, root: c…s.c…e.VectorNode, tail: Array(4)…}
@lepistane feels like you should be doing (reset! resp ..)
in your handler
function .. and not right after GET
since it may be async?
you are most likely setting response to what (GET ...)
returns (some JS representation of async operation)
didnt i do that with new handler? (defn handler [response] (reset! resp (js->clj response :keywordize-keys true)))
it does work. finally!! AHHAHA i am so happy thank you!! btw how did u learn all that where how when any resources that you could recommend?
(-> input-mapping :headers-mapping :gold-tags)
is that a nice way to destructure a nested map? do you typically do it differently?
kind of follows the structure of the map in a linear order, compared to nested extraction
@matan I mostly try to do that, with some->
so I bail out in case something returns nil
, I think this is supposed to be pretty fast as well compared to (get-in...)
can't wait for clojure.spec/clojure 1.9's validators, to make validation and extraction more tightly integrated
I am trying to read in a file line by line and apply a transducer to each line of the file. Here is my code:
(defn file-contents [fpath]
(line-seq (jio/reader fpath)))
(def clean
(comp
(filter #(= (first %) "*"))
(drop 6)))
(defn apply-transducer [f r v]
(if (empty? r)
(conj v (clean (char-array f)))
(recur (first r) (rest r) v)))
So I am using the http://java.io/reader function to read in the file and converting that of a sequence of each line
However, if I call apply-transducer
on the seq using the clean
transducer, I get this: [#object[clojure.core$filter$fn__4808$fn__4809 0x2e5bde32 "clojure.core$filter$fn__4808$fn__4809@2e5bde32"]]
calling a transducer like a function will return a reduction function .. so not really a cleaned output
you can use sequence
function to do this: https://clojuredocs.org/clojure.core/sequence
(sequence (comp (remove #(str/starts-with? % "*"))) (line-seq file))
.. something like this?
verma: that should work, but the comp
is a noop
and really, it makes more sense to just use remove
directly, sequence isn’t helping here
@matan: have you looked at "literal" destructuring with :keys
? see https://gist.github.com/john2x/e1dca953548bfdfb9844
(sequence (remove #(clojure.string/starts-with? % “*”)) [“hello” “*world” “this” “*is” “test”])
use the fully qualified name or perhaps require it first
@verma That isn't quite what I am looking for. I am starting with a lazy seq, and I had my comp in the wrong order
so what is your use case? You want the third element of the fifth element of the first element of a list?
I have crazy long structure, and using get-in
for pulling values from it. I met persistenlist in it, and my get-in
got broken
`{:POS {:source ({:ISOCurrency "USD", :requestorID nil})},
:altLangID "?",
:availRequestSegments
{:availRequestSegment
({:hotelSearchCriteria
{:criterion
({:hotelRef
({:chainCode nil,
:chainName nil,
:hotelCode "123",
:hotelName nil}
{:chainCode nil,
:chainName nil,
:hotelCode "345",
:hotelName nil}),
:position nil,
:radius nil,
:refPoint (),
:stayDateRange nil})},
:roomStayCandidates
{:roomStayCandidate
({:guestCounts
{:guestCount ({:ageQualifyingCode nil, :count 1})},
:roomAmenity ()})},
:stayDateRange {:end "2017-08-17", :start "2017-08-15"}})},
:echoToken "?",
:primaryLangID "?",
:version 1M})
I mean, you don’t really need transducers here, but if you want them in there, you can have (comp (map #(subs % 6)) (remove #(str/starts-with? % "*")))
does clojure have a builtin function for counting ocurrences of an element in a string or sequence or do I need to build my own?
@vitruvia (frequencies "122333")