This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-26
Channels
- # aws (1)
- # aws-lambda (16)
- # beginners (8)
- # boot (2)
- # cider (4)
- # cljsrn (9)
- # clojure (137)
- # clojure-italy (3)
- # clojure-russia (39)
- # clojure-spec (34)
- # clojure-uk (33)
- # clojurescript (44)
- # core-logic (11)
- # cursive (27)
- # data-science (16)
- # datomic (52)
- # duct (1)
- # emacs (1)
- # figwheel (2)
- # fulcro (90)
- # graphql (3)
- # hoplon (7)
- # lambdaisland (2)
- # leiningen (23)
- # lumo (1)
- # off-topic (1)
- # om (40)
- # onyx (44)
- # re-frame (116)
- # reagent (3)
- # shadow-cljs (87)
Woah, alright, that’s a lot to take in and process, haha! Thanks for all the input guys! I think I know how I’m going to approach the testing/refactoring for this!
what's the right way of dealing with clojure.edn/read-string reading strings as symbols? e.g.:
(type (clojure.edn/read-string "f8f2b6b3-39b8-4e76-a9f0-fa4a65ee225a")) -> clojure.lang.Symbol
; and I want it to be read as a string
reading foo
as a string is not edn, so trying to get a library for parsing edn to do it is a fools errand
so that's what I'm saying, I have no way to know that this "{}" is a map until until it's "read"
I want: "{}" to be read as map; "[]" to be read as vector; "foo" to be read as "foo" -> string
you will have other problem as well, because not all uuids are going to be valid symbols
that's my point - I don't care about symbols - I want to parse maps and vectors and take everything else as strings
look, the request wraps params like this,
{"customer-account-id" "f8f2b6b3-39b8-4e76-a9f0-fa4a65ee225a",
"filter" "{:date {:from nil, :to nil}, :search nil}",
"sort" "[:settled-at :desc]"}
on the server side I need to turn it into "normal' hash map
a) need to keywordize keys - that's easy
b) need to uwrap maps and vectors - what's the easiest way of doing that?I suspect you could (try (let [v (edn/read-string s)] (if (or (vector? v) (map? v)) v s)) (catch Throwable _ s))
I think I got slightly better idea.
(defn read-string*
"reads-string by parsing only maps, vectors, keywords and leaving everything else as-is.
Because `(type (clojure.edn/read-string \"foo\"))` => clojure.lang.Symbol"
[v]
(let [r (s/conform (s/or :r map? :r vector? :r keyword?) (read-string v))]
(if (= r ::s/invalid) v (second r))))
Bear in mind that if read-string
throws an exception, you won't get back the original string -- in case v
is not valid EDN.
That would leave you with maps/vectors where the strings actually were EDN maps/vectors and leave you with the raw string everywhere else.
that is well formed edn, strings are quoted, you can process it with edn/read-string then walk it making whatever changes you want
anyone have a go-to way of debouncing? in cljs i just use the google closure debounce fn, but i can't find anything for clj
is it an unofficial law in clojure that the first argument, if possible, be a collection? in order that things work nicely with swap!, update, update-in
@qqq Rich answered this here https://groups.google.com/forum/#!topic/clojure/iyyNyWs53dc
I tend to almost always order my arguments from least to most variable
why does that make sense given: 1. clojure doesn't have nice partial application and 2. ppl generally optimzie for ->, ->>, update, swap, ...
I’m that weirdo that really like partial
but mostly it’s just because I can keep track of my args cognitively easily with that heuristic
weird; I don't think there's a single partial code in my code, I tend to use #(... %1 ... ), maybe I need to learn how to use 'partial' in clojure
For whatever reason my visual parser hangs on that literal lambda syntax. I’ll always either reach for partial or fn unless I’m writing throwaway
update-display (partial display-error-in-zone errorzone)
show-user (comp update-display alert-box auth/unify-response)
from a let binding. Then i can just call show-user
on all of the callbacks. I unify the repsonses, turn them into the alert box map required and then update-displayDid anyone bring re-natal
with hot reloading to run? It all seems to work except the hot reloading
@alpox you need to disable the hot reloading feature in the react-native devtools; figwheel comes with its own hot reloading
all the RN packager sees is a stub that includes the JS requires; figwheel does the rest
@pesterhazy ah alright, i’ll give it a try, thanks! I’m using intellij now and i’m not quite sure with what command i best start it. With the react-native
task? Thats the only one which opens the app in my simulator.
lein figwheel
and react-native run-ios
or ... run-android
should do the job
Hmm since i’m working with intellij tasks and not the command line - i guess i’ll have to run both tasks - a leiningen task and a react-native one
don't forget to run re-natal use-figwheel
once before that
forget about intellij for a minute and do it from the command line
you can build shortcuts for your IDE when you know it works
an IDE is only sugar for the command line
@pesterhazy That i know, i’m usually more of a command line guy 🙂
intellij will work fine as an editor though
You should look at Spacemacs. http://spacemacs.org — Terminal based or GUI. But powerfull. --end of commercials--
@scknkkrer I just moved to intellij from spacemacs - for the good for that everyone working on the coming project can use the same environment
Well, older people have a hard time to learn a very new environment with less GUI than they are used to 😄 but yea, emacs is great
Emacs is older than me. Maybe, older than you too. March 20, 1985 It’s birtdate. But, no problem if you return us back. Your real home. 😂
@scknkkrer Thanks 🙂
>>> The original EMACS was written in 1976 by David A. Moon and Guy L. Steele Jr. as a set of Editor MACroS for the TECO editor.
I’m very new to the clojure environment, so i hope i won’t struggle too much. I want to take a go with react-native and fulcro. Hope I won’t run into too many problems 😄
@pesterhazy thank you 🙂
emacs was the first real program to use windows - which is why emacs terminology for windows and frames and such is totally different from all the apps that came later (and closer to how windows actually work in the real world)
#emacs is probably a better place for this discussion
I have a piece of clojure data, representing hiccup. I need to go through the hiccup, andechange every ocurance of: :on-click :foo1 ==> :on-click (get kw->func-map :foo1) :on-click :handler2 ==> :on-click (get kw-func-map :handler2) Is there a standard way to do this ?
this is the best I have so far:
(def kw->func {})
(def sample-data
[:div
[:svg {:on-click :foobar}]])
(defn conv-function [x]
(if (and (map? x)
(:on-click x))
(assoc x :on-click [:lookup (:on-click x)])
x))
(clojure.walk/postwalk conv-function sample-data)
@qqq I understand if the map?
check is there for clarity, but it’s redundant - :on-click
will only return non-nil if it can be looked up (I guess there’s a corner case of sets, but there’s nothing in hiccup that knows what to do with a set containing a keyword that I know of)
also, for that general flavor of thing I have when-pred (defn when-pred [p? x] (when (p? x) x))
(:on-click (when-pred map? x))
good call on the map? // I may keep it for stylistic reasons as a "type sig" of "this is a map", but I agree with you that it's redundant
@qqq you can do that transformation much more precisely and efficiently with specter
@nathanmarz: I agree. The problem I have with specter is that: 1. I can implement postwalk from scratch [so I understand it] 2. to this day, I haven't managed to implement a mini-specter from scratch, so it's still very magical to me
@qqq did you look at https://github.com/nathanmarz/basic-specter ?
that's basically the original implementation without any of the optimizations that came later
@nathanmarz: not until now; 30 lines is impressive; will look into it
essentially still how it works, especially transformation
the transform implementations are still the same for the most part
ALL
uses protocols to dispatch on each type, and esp. for maps uses a different implementation per map type
and then there's the inline compilation / caching system that removes most of the navigator composition overhead
that stuff doesn't matter when it comes to what's actually going on when you do transform – basic-specter captures that aspect
right, I realize it doesn't change semnatics, I'm just curious what issues you ran into and how you overcame them
the inline compilation / caching stuff was extremely hard, optimizing the individual navigators was just a lot of digging into esoteric details of Clojure
ALL
, MAP-VALS
, MAP-KEYS
were the most work to optimize
when specter outperforms idiomatic clojure code it's usually due to those navigators
I'm seeing a weird problem with reading the new namespaced maps in a repl. I get this error in both a bare lein repl
and boot repl
:
user=> (defn foo []
#:a{:b 1})
#_=> #'user/foo
user=> (defn foo []
#:a{:b 1}
)
#_=>
user=> java.lang.RuntimeException: EOF while reading, starting at line 1
clojure.lang.LispReader$ReaderException: java.lang.RuntimeException: EOF while reading, starting at line 1
java.lang.RuntimeException: Unmatched delimiter: )
clojure.lang.LispReader$ReaderException: java.lang.RuntimeException: Unmatched delimiter: )
it's the same exact code except the second version has a newline after the namespaced map. Can I bother someone else to try this code in their repl and see what they get? I'm on clojure 1.9.0-beta3
I would like to try it in a bare (non lein/boot) clojure repl, but I'm on ubuntu and the installer only works for macos right now
ok, so I tracked ^this down to being a problem with how the text is being read from the terminal
it’s in the reply / nrepl layer right?
you can use a bare repl by downloading the jar and running it with java, you don’t need deps to reproduce
(oh - wait - the latest jars need deps, never mind)
yeah @noisesmith I just followed the new instructions to get a bare clojure repl on linux and I do not see the problem there, only in lein/boot
you can also make a project with only clojure.core as a dep and no code, and make and run an uberjar
or lein trampoline repl
definitely not a terminal thing
it’s a known thing in reply
(unless coincidentally something else is causing the same error)
is it this issue? https://github.com/trptcolin/reply/issues/168
I’m not certain, but it certainly looks like the issue, yes
and for anyone following along it looks like the real issue isn't in reply, but actually one more dependency level down in sjacket: https://github.com/cgrand/sjacket/issues/25
Is there a way to simplify:
(and (map? x)
(get x [:rewrite :on-click]))
There is no guarantee that x is a map.so that means you want false instead of nil?
user=> (get "pretty much anything" [:rewrite :on-click])
nil
I've run into an interesting bug at work with an Apache Storm topology in Clojure. One of the bolts takes, as a :param, some seed data from a dB. This data, consisting of two queries, is done inside a pvalues expression, returning a map with two key/value pairs - one for each query essentially. Now, pvalues is implemented as a future if I'm not mistaken, and as such will cache its value for subsequent derefencing. The behavior I'm seeing is that upon a Storm restart we're getting old, stale data from this pvalues. It seems to be under circumstances when the topology is restarted round-robin with individual nodes restarted in a rolling fashion (hence the topology is never 100% off). So, could the pvalues 'state' be passed from a supervisor to another one? Curious if anyone else has run into a similar issue. We have a work-around, consisting of a complete take down of Storm and then a restart but... I guess that's SOP 🙂
it uses zookeeper, zookeeper is for sharing small values between processes for IPC
typically one will create “ephemeral nodes” that disappear if nobody is using them
there’s a program called zkCli
that lets you explore the data in zookeeper as if it were a file system
@noisesmith thanks, I'll check that out. It's easy enough to reproduce 🙂
I wouldn’t be surprised if there was a command of workflow to clean-slate the Storm state
can I print the address of a variable, or something which I can easily use to compare it with another instance later?
@mnewhook if you var quote an argument, it’s the container and not the thing in the container. This only works for vars (usually owned by namespaces) and does not work for local bindings, which are immutable
+
is the function bound to clojure.core/+
, #'+
is the var that currently holds that value
a convenient thing is that if you call a var, the var looks up it’s own contents and calls that for you; for values that aren’t being called you can use deref
, the shorthand @
, or var-get
you can also look up a var by symbol via resolve
, or look it up using the bindings set up in a specific namespace with ns-resolve
- a tricky point is that ns-resolve doesn’t look up a var in a specific ns, it looks up a var using the rules that would be used in that ns, which includes bindings created by require, refer, use, etc.
it’s like 3 lines of interop, max, you don’t need a lib
ya, this is our sha1 framework:
(DigestUtils/sha1Hex
(str "classic_"
pcoll-name
"_"
(pr-str key-obj)))
(assuming you're in a project that already pulls in apache commons for one of the million reasons that you might)
yeah - that github gist works if you aren’t using commons, but most apps probably have commons already