Fork me on GitHub

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


your macro should return a form that when evaluated returns a function object


yes, that's what I said before sharing that example


I was just making a smaller reproduction of his issue

Drew Verlee01:12:46

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}}
    (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)
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.


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)


my guess would be (foo) followed by *1, doesn't actually get compiled to bytecode


ahh! that would explain it

New To Clojure09:12:37

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.


wait, what? AFAIK atoms are not thread-local


but yes, it keeps the values in an atom so it is thread-safe


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

New To Clojure11:12:47

@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


if you are writing performance sensitive code, I recommend something like instead of memoize


it has a bunch of different variants of retention and much better performance 🙂

New To Clojure12:12:32

@U3L6TFEJF Thank you, it's useful lib!

replied to a thread: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.


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


so calling key in your filter won't work


although on second thought i was thinking keys so perhaps it does


@timok what do you mean create a partial or export the function?


advent.day3> (defn is-lib? [lib entry]
               (= (second (key entry)) lib))
advent.day3> (filter (partial is-lib? "bidi") libs)
([["bidi" "bidi"] 951])


let me see...


you answered yourself the partial...export the function means make it a second function


(def bidi? (partial is-lib? "bidi"))


or (defn is-bidy? [entry] (is-lib? "bidi" entry))


what I want to accomplish is to search in a huge list (like above but bigger) for a set of library-names like "bidi".


what is missing from this solution


I have to understand it ... let me see


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


how can I give above functions multiple arguments?


so you want to take a set of libraries you care about and filter the list for libraries in that set?


exactly! thanks by the way for your help so far


advent.day3> (defn is-lib [desired-libs entry]
               (contains? desired-libs (second (key entry))))
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


awesome! thanks! I am trying to make this filter as a function...let me see


so with a multi-arity function I have to build in this filter-function another map, right?


i'm not sure i follow


what is the signature of the function you are envisioning?


do you want it to take the collection and return the "good" ones?


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


thank you!

Drew Verlee21:12:11

Any idea how you would get the output from expound to be readable in the repl? I'm using emacs

Drew Verlee21:12:00

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]))?


Gosh, I'm getting blind. Thank you!


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)