This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-10
Channels
- # adventofcode (99)
- # architecture (10)
- # bangalore-clj (1)
- # beginners (65)
- # boot (9)
- # cider (78)
- # clojure (87)
- # clojure-austin (1)
- # clojure-brasil (13)
- # clojure-dev (14)
- # clojure-gamedev (3)
- # clojure-greece (2)
- # clojure-italy (2)
- # clojure-russia (18)
- # clojure-spec (26)
- # clojure-uk (15)
- # clojurescript (62)
- # core-logic (1)
- # cursive (1)
- # datomic (27)
- # emacs (17)
- # fulcro (2)
- # off-topic (44)
- # onyx (25)
- # perun (139)
- # re-frame (40)
- # reitit (2)
- # ring (4)
- # rum (2)
- # shadow-cljs (1)
- # slack-help (14)
- # unrepl (18)
am not sure why you get different behavior there, but embedding a function object in code is not something you should ever do, even though sometimes you can get it to work
yes, that's what I said before sharing that example
I was just making a smaller reproduction of his issue
If your working with a server, like compojure, it seems like you need to call your project functions from a namespace outside the ... project one. For example, i was having trouble evaling my compjure app inside emacs while jacked into my cider repl.
(-> {:uri "/spec/plus"
:request-method :post
:body-params {:x 1 :y 2}}
app
:body
slurp
(cheshire.core/parse-string true))
Results in an error. But
lein repl
user=> (use 'example.handler)
user=> (-> {:uri "/spec/plus" :request-method :post :body-params {:x 1 :y 2}} app :body slurp)
"{\"total\":3}"
is a success.
So two questions.
1. Why does the later work?
2. And how do i get back to using my editor?
as typing in the terminal is a pain. I fee like this is something stuart has talked about before with his "repl driven development".
update: it seems i just need to start the server at the same time. It would be cool if someone would give me a hint why this is, though i can probably guess its because ... actually im not sure. Some components that the repl are calling out to aren't ... idk."an error"
in general, it is a constructor issue, because the compiler generates a call to a no arg constructor for random objects embedded in code
and it's an issue that comes up with ((m)) but not (def f (m)) (f)
ahh! that would explain it
thanks
Is memoize
thread-safe?
I don't know the answer, but hazarding a guess from the source for memoize. memoise uses an atom to maintain the cache, which means any cached value would be local to a thread.
a word of caution: if you have a lot of different return values memoize can eat up all your memory, since it never removes or expires values
@U3L6TFEJF oh wow, haven't expected that! Thank you @U051MHSEK, @U3L6TFEJF a lot
@U3L6TFEJF is correct --- atoms are not thread local (vars are). Apologies for the misinformation, @U879F6GV7
@U051MHSEK no problem
if you are writing performance sensitive code, I recommend something like https://github.com/ben-manes/caffeine instead of memoize
@U3L6TFEJF Thank you, it's useful lib!
I don't know the answer, but hazarding a guess from the source for memoize. memoise uses an atom to maintain the cache, which means any cached value would be local to a thread.
Hi there I am desperate to find a way to retrieve a list of keys from a map. It would be awesome if someone could point me into the right direction. following my map and my function so far:
so I want to filter by the second element of the vector-key and retrieve the values for multiple items
I can't wrap my head around how I could make a partial here or export the anon-func to a function. Any help much appreciated!
so if you run filter on a map, it's not gonna see a map but map entries, which we can treat as two element vectors
advent.day3> (defn is-lib? [lib entry]
(= (second (key entry)) lib))
#'advent.day3/is-lib?
advent.day3> (filter (partial is-lib? "bidi") libs)
([["bidi" "bidi"] 951])
what I want to accomplish is to search in a huge list (like above but bigger) for a set of library-names like "bidi".
mmh...either I don't get it or it is not working... I need a function that I can give multiple names of libraries and that gives me their names and numbers back
so you want to take a set of libraries you care about and filter the list for libraries in that set?
advent.day3> (defn is-lib [desired-libs entry]
(contains? desired-libs (second (key entry))))
#'advent.day3/is-lib
advent.day3> (filter (partial is-lib #{"bidi" "suchwow"}) libs)
([["marick" "suchwow"] 736] [["bidi" "bidi"] 951])
so now is-lib
takes a set of desired libraries and we just ask if it contains the entry
the reader syntax #{"bidi"...}
creates a set. so we ask if the set of libs we care about contains an entry. and filter the list with that
so with a multi-arity function I have to build in this filter-function another map, right?
but this problem is inherently "multi-arity" as you have two variables. the list of libraries and which ones you care about
I am having this large list of libraries and I want to compare some of them by their number of downloads
this is the function that should take a variable number of args and return the corresponding libraries
so the user queries for bidi and suchwow and gets them with their corresponding number of downloads back
seems to be the case of the function above? ([["marick" "suchwow"] 736] [["bidi" "bidi"] 951])
yeah right. I just don't get the additional map over the arguments at the moment...I will try it tomorrow
Any idea how you would get the output from expound to be readable in the repl? I'm using emacs
i got it
the name was like eval-exp-fu-cider-pprint-eval-sexp-inner-list
Hi! Is there an efficient way to use map with a vector and get a vector in the output? Other than (vec (map inc [1 2]))
?
I am starting to dig into spec
and I want to contextualize it for my own understanding. To me, at a minimum, one could use spec
as a type system, would this be valid? However, given that it can do so much more, how does the argument that Clojure does not have types still get asked? In order to get the same functionality in JS, I would be required to use a combination of Flow, Joi and Chance (types, assertions and test data generator respectively)