beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
AJ Jaro 2020-11-29T00:39:51.012900Z

We used to have it integrated but never used it. If you have specific questions I can look in our archives if you'd like. Just let me know

2020-11-29T01:49:33.013500Z

REPL driven development question… When I want to test a line in a function that depends on an argument without calling the function, what do you do to provide a value for the argument? Do you just throw in a ‘def’ or is there a better way?

2020-11-30T19:37:04.057800Z

also, with code that exists already, it's often useful to insert a tap> call into the defn, then use an add-tap function that captures values for experimentation

2020-11-30T19:37:24.058Z

this is my "stethascope" for examining internals of a running system with legacy code

2020-11-30T20:05:16.058600Z

I haven’t ventured into debugging running/deployed code. Tap is new to me, I’ll read about it. Maybe @seancorfield will cover such wizardry in his upcoming talks? Thanks for the suggestion.

seancorfield 2020-11-30T21:13:53.059200Z

@dcreno I will make sure I cover that (since I use Reveal alongside my editor to show all tap>'d values).

👏 1
st3fan 2020-11-29T02:22:40.013800Z

I would do a let - doesn’t def create global scope?

st3fan 2020-11-29T02:23:54.014Z

What I often do is pull the line out of the function, and execute it in the repl, wrapped in a let

st3fan 2020-11-29T02:24:04.014200Z

Doesn’t always work of course

seancorfield 2020-11-29T02:28:04.014400Z

@dcreno Put a (comment ,,,) form immediately after the function. Then put (def addend 4) inside that comment and evaluate the def, then you can eval any form inside the function.

👍 1
seancorfield 2020-11-29T02:28:45.014600Z

That way you're not modifying the "production code", but your scratch code stays visible and available in your code for future use.

seancorfield 2020-11-29T02:29:25.014900Z

And maybe attend one of my online talks in December/January https://corfield.org/blog/2020/11/24/talks-clojures-superpower/ 🙂

2020-11-29T02:29:35.015200Z

Thanks! I know it’s a bit of a silly question but I figured there was a common way.

2020-11-29T02:30:00.015400Z

I like the (comment …) version.

seancorfield 2020-11-29T02:30:08.015600Z

"Rich Comment Form"

seancorfield 2020-11-29T02:30:27.015800Z

(because Rich Hickey does this too)

seancorfield 2020-11-29T02:35:18.016Z

(and definitely not a "silly question" -- getting to a really efficient RDD workflow is something that a lot of people struggle with, because it's not like how you work with other languages)

👍 1
yubrshen 2020-11-29T05:06:37.018600Z

How can fix the error:

clojure -M:uberjar
Compiling yubrshen.unique-errors ...

Compilation of yubrshen.unique-errors failed!

Could not locate yubrshen/unique_errors__init.class, yubrshen/unique_errors.clj or yubrshen/unique_errors.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
I'm use an app template from: https://github.com/seancorfield/clj-new Here is the related alias for :uberjar:
:uberjar {:extra-deps {seancorfield/depstar {:mvn/version "1.1.128"}}
            :main-opts ["-m" "hf.depstar.uberjar" "unique_errors.jar"
                        "-C" "-m" "yubrshen.unique-errors"]}
It seems that I may need somehow to install unique_errors.jar? Thanks!

Brian Chevalier 2020-11-29T06:51:06.018900Z

What are the file/folder names used? It looks like a classpath error. Your namespace yubrshen.unique-errors includes a dash which is okay, but your filenames should uses underscores, replacing the dashes.

Lukas 2020-11-29T16:41:26.021300Z

Hello everyone, is there a way to get the query result without the brackets?

(d/q '[:find (pull ?e [:commit/rev])
         :in $ $date
         :where
         [?e :commit/date ?date]
         [(> ?date $date)]]
       @conn date)

;; => ([#:commit{:rev "25ed6cb"}]
;;     [#:commit{:rev "02a760a"}]
;;     [#:commit{:rev "61df934"}]
;;     [#:commit{:rev "d6524ab"}])
Like this but without the extra step.
(->> result
       (reduce (fn [acc e] (conj acc (first e))) '()))

;; => (#:commit{:rev "4e2cce7"}
       #:commit{:rev "13c57d1"}
       #:commit{:rev "8a3fd52"})

oxalorg (Mitesh) 2020-11-29T16:49:30.022300Z

@lukas.block you can try doing this if it helps:

(map first result)
;; or
(->> result
     (map first))

dpsutton 2020-11-29T16:55:11.025300Z

I believe there’s a way to do it in the query without extra work afterwards

Lukas 2020-11-29T16:57:30.025400Z

hey thank you. The reduce was just an, I have to admit overly complicated example, for an extra step

st3fan 2020-11-29T18:24:11.027300Z

What is a good tool to ‘make 150 http requests (random order) with N workers’ ? Should I reach out to java.util.concurrent?

st3fan 2020-11-29T18:48:35.028500Z

Going to do now with what I am familiar with .. java.util.concurrent.ExecutorService but I am interested in learning more about clojure.async which also seems to be able to do this

st3fan 2020-11-30T14:10:42.044600Z

That looks very nice. I'll take a peek.

Ben Sless 2020-11-29T20:32:44.029200Z

Client libraries like httpkit allow you to pass an optional thread pool (number of workers). You can then use core.async's async-pipeline to control the number of inflight requests

st3fan 2020-11-29T20:34:07.029400Z

I need to investigate that. Right now I have a simpler approach:

(defn ping-endpoints [endpoints]
  (let [pool (Executors/newFixedThreadPool 8)
        tasks (for [url endpoints] #(ping-endpoint url))
        futures (.invokeAll pool tasks)]
    (for [f futures] (.get f))))

st3fan 2020-11-29T21:25:46.029900Z

I wish I could just keep all data in memory and not bother with databases

uosl 2020-11-30T21:08:50.059Z

Isn't this basically datomic?

zackteo 2020-11-29T21:38:58.030400Z

Apparently the 4clojure server is down hmmm

zackteo 2020-11-29T21:41:02.032200Z

Anyway, am doing qn 39 have a solution to make my own version of interleave but is there a way I can remove vector ? Like by changing concat to something else?

(defn leave [a b]
  (when (and (not-empty a) (not-empty b))
    (concat (vector (first a)) (vector (first b))
            (leave (rest a) (rest b)))))

2020-11-29T21:42:41.032300Z

You don't care if your data disappears when the power goes off?

2020-11-29T21:43:19.032500Z

I believe quite a few databases are good at keeping recently used data cached in RAM.

dpsutton 2020-11-29T21:45:13.033Z

I think you can use list* there

zackteo 2020-11-29T21:46:51.033900Z

yeap list works too but was wondering if there's a concat that doesn't require elements to be in some form of collection

dpsutton 2020-11-29T21:48:18.034200Z

List* is that

dpsutton 2020-11-29T21:49:01.035300Z

Distinct from list. Often you’ll see lazy-seq cons cons leave

zackteo 2020-11-29T21:49:12.035600Z

oooo! yeap it works

zackteo 2020-11-29T21:52:39.036600Z

Also does anyone understand why mapcat vector works as a replacement for interleave ?

zackteo 2020-11-29T21:55:50.037400Z

Okay nvm I got it, but I never knew that map applies the f to the first item of each coll then the second items and so on

dpsutton 2020-11-29T22:04:39.038Z

yeah its a neat feature of map. other languages need a bespke map2, map3, etc