Fork me on GitHub

@hiredman Any examples of impure functions that you have used memoize on before? If the memoized thing is doing read-only behavior from a database that is never or slowly changing, I suppose memoize could be used there to improve performance and give the correct results (perhaps even past the time it gives up to date correct results, if you aren't careful).


I don't use memoize all that much, I think the last place I used it maybe spun up a thread to do something and return a core async promise-chan, but I don't entirely recall. What came to mind immediately was lein used to use memoize internally on tasks to stop them running multiple times


Hello, I would like to create lein-plugin for myself for esier deploy cycle. I try to use clojure/tools.cli but when I tested.. with “-h” flag not works the program.. if I use “-e” everything ok.

(def cli-options
  "all optional and positional"
  [["-e" "--helps" "Help me"
    :default false]
   ["-u" "--sudo" "Configure passwordless sudo"
    :default false]])


sb$ cd ../devops && sudo lein install && cd ../test-project/ && sudo lein devops -h
Created /Users/sb/Desktop/devops/target/devops-0.1.0.jar
Wrote /Users/sb/Desktop/devops/pom.xml
Installed jar and pom into local repo.
Main function called from Leiningen from original docs

Arguments: ([& args])
sb$ cd ../devops && sudo lein install && cd ../test-project/ && sudo lein devops -e
Created /Users/sb/Desktop/devops/target/devops-0.1.0.jar
Wrote /Users/sb/Desktop/devops/pom.xml
Installed jar and pom into local repo.
Lein-devops Leiningen plugin helper

   Usage: ${0} (-h | -S | -u | -k | -s | -d [docker_ver] | -a [docker_ver])

  Usage: (you can add in project.clj)
  Example: :devops {:server-ip ""}


any idea how to fix it? is that possible or good example how to use -h option with tools.cli?


I used with lein install and added to a new pure project.


@sb I don’t see -h as an option in your code.


I modified to -e, before this was -h. I added tests for this code.. “validate-args cli-options” and come back a normal response. So, I don’t know what is really the problem..


Other characters.. works fine.. just problem with the “h” character.. when run the plugin (lein devops -h).


I’m trying to make something remove based on two criteria:

(remove (and (comp #{"one"} :id) (comp #{"two"} :other-id)) '({:id "one" :other-id "two"}))
(remove (and (comp #{"one"} :id) (comp #{"two"} :other-id)) '({:id "not-one" :other-id "two"}))
=>() ;; should return '({:id "not-one" :other-id "two"})
i’m not surprised that this doesn’t work; i think it’s only comparing :id because and is evaling and returning the first comp. (i only picked and because it semantically fits what i want; do this and do this)


Your predicate isn't a function

☝️ 4

point taken of course. i have not figured out how to write what i want. i want an expression that accepts a list of maps and removes them if they match two kv-pairs. but to be pedantic, it is a function! (and thing thing) returns thing, which is a function.

user> (and (comp #{"one"} :id) (comp #{"two"} :other-id)) 


this does it, but is verbose:

(remove (fn [{:keys [id other-id] :as m}] (and (contains? #{"one"} id) (contains? #{"two"} other-id)) ) '(  {:id "not-one" :other-id "two"}))

👍 4

(remove #(= {:id "one" :other-id "two"} (select-keys % [:id :other-id])) '({:id "not-one" :other-id "two"}))
Does this satisfy your requirements?


that does in that case! thanks. a requirement i didn’t say but that i have, is that i actually need it to support a set of values (hence my (contains #{“one”}), which easily supports more values. thanks though, i forgot about select-keys

👏 4

You can remove the contains call and just invoke the set

👍 4

i was looking in the docs for something like juxt. I want to be able to say

(foo (comp #{"one"} :id) (comp #{"two"} :other-id))
where foo means “give as input the same to each”


yeah, that would be useful. you could use something like:

(defn juxt? [f g]
  (let [ps (juxt f g)]
    #(apply and (ps %))))


that’s pretty cool! i get “can’t take value of a macro” : (. but i see your point!


cljs.user> (every? identity ((juxt (comp #{"one"} :id) (comp #{"two"}  :other-id)) {:id "one" :other-id "two00"}))
cljs.user> (every? identity ((juxt (comp #{"one"} :id) (comp #{"two"}  :other-id)) {:id "one" :other-id "two"}))


i'm not sure code golf helps here though


every? identity juxt is good. and yeah agreed with your comment. thanks!


@U0HJ4RAGY i think you want every-pred

=> (remove (every-pred (comp #{"one"} :id) (comp #{"two"} :other-id)) [{:id "not-one" :other-id "two"} {:id "one" :other-id "two"}])
({:id "not-one", :other-id "two"})


’s it! thank you very much


no problem!


nice! I think I've discovered every-pred once before and promptly forgot it :d


hahah, fair enough


there's also some-fn, which is like the 'or' version


so if i run an assert function in the repl and it does not give me an exception, does that mean it passed. it is returning nil which is why i wanted to clarify. nil means it's all good in this instance?


what do you mean by an assert function?


cool. i probably should have re-read the docs and asked here before I refactored my function 3 times. lol


(assert (= "Hello, World!" (greeting))) kind of thing

Mario C.20:08:51

Something mysterious is happening and I can't quite understand why.

Mario C.20:08:23

I have two projects Project A and Project B that both use another project called Project C

Mario C.20:08:17

Project C uses a utility (:import org.apache.commons.codec.digest.DigestUtils)

Mario C.20:08:07

In Project C there is a function that calls a method* (DigestUtils/sha1Hex "Mario")

Mario C.20:08:09

If Project A calls that function, everything succeeds and I get the expected result: 8e7d820ad9d3323edb541a72da4912148cb9c0c2

Mario C.20:08:31

If Project B calls that function, it hangs and does not return anything.

Mario C.21:08:43

Project C is defined as (defproject project-c "0.1.1-SNAPSHOT")


I bet lein deps :tree in Project A and Project B would show the difference

Mario C.21:08:02

How would I use that? I am not familiar with lein deps :tree

Mario C.21:08:30

Running those command for both Project A and Project B give me different results

Mario C.21:08:20

If I add a println in Project C. Both Project A and Project B reflect that.

Mario C.21:08:14

@noisesmith I think I caught it with lein deps :tree


NP - I could have been more verbose and said the difference in behavior must reflect different dependency versions etc. but glad you saw the issue

Mario C.21:08:17

[project "0.1.1-SNAPSHOT" :exclusions [commons-codec]]

Mario C.21:08:20

What does that mean? ^


it means that you won't use commons-codec, even if something you depend on depends on it


usually exclusions are useful on a specific dep (saying "I don't want the version of this that foo/bar asks for") - an exclusion at the top of your project says "I won't provide this dep at runtime even if something says it needs it"

Mario C.21:08:06

Okay so in my Project C I am using a certain version of commons-codec that I want to use. In Project B I have some dependencies that seem to depend on an older version of commons-codec. How can I resolve this issue?


usually listing C before the conflicting dep will sort that out, otherwise you can add an exclusion to the specific dep asking for something different, and/or ask for the specific version that B wants


lein help sample has examples of using exclusions