clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
Mark Wardle 2021-04-20T07:43:03.308100Z

Hi all. Is it possible to use an alias in a git coordinate in deps.edn? This impacts the way I structure my projects and git repositories. I’m increasingly finding use of deps permits greater modularity - and increases my ability to use a single repository for different purposes - e.g. via aliases - so that repository can be used as a library or a standalone domain service. That’s instead of having two repositories ‘my-cool-library’ and ‘my-cool-server’, I have ‘my-cool-project’. This works really well. e.g. see my https://github.com/wardle/clods service - which can be run as a HL7 FHIR server or simply embedded as a library - and in the latter’s case not drag in dependencies. But, there’s one snag. What if I want to use some of the server code (e.g. some ring handlers) in another project? Is it possible to reference an alias when using a git coordinate? I cannot see that it is. So the options are 1. Build a maven package for the different aliases 2. Use separate code repositories ‘-library’ ‘-server’ . 3. Ask whether others might think referencing an alias (or aliases) to configure what is included in a git coordinate in deps.edn might be useful? Or am I doing this wrong?

Mark Wardle 2021-04-20T08:26:16.317200Z

To explain: I’m working on assumption that the repository is business domain orientated - and the aliases are technology orientated. It means greater composability and ability to flex/adapt eg spin out a dependency of a wider project to its own managed service vs use as a library when starting out. So being able to slice and dice along what are orthogonal boundaries is helpful. For example, I am building a graph API across multiple repos - but the resolvers should logically be in the repo to which they relate - I combine the graph resolvers or I combine as libraries. But the core library shouldn’t drag in dependencies on graphs as that’s just one prism through which to view that domain. Having a tiny ‘xxx-graph’ repo is IMHO worse than a graph alias which switches on that “prism”.

borkdude 2021-04-20T09:04:16.317600Z

There is a #tools-deps channel for this

👍 1
Mark Wardle 2021-04-20T09:15:37.318100Z

Thanks! Didn’t see that. I’ll ask there.

restenb 2021-04-20T11:56:43.319400Z

is there some standard HTTP request timeout built in to the ring-jetty-component, or underlying jetty server? i'm experimenting with some long lived requests, but the server (which runs jetty via @weavejester's ring-jetty-component) boots my requests before any timeout I've actually programmed in happens

jumar 2021-04-20T13:21:14.320300Z

Nothing I know about. What exactly happens in your case?

restenb 2021-04-20T15:52:01.321800Z

i'm reading clj-http docs on async requests and a bit unclear on whether sending a request with :async truewill still block the calling thread or not?

restenb 2021-04-20T15:52:35.322500Z

experiments with sending many requests in a go block suggests it does, only 8 can be waiting at a time

restenb 2021-04-20T16:03:55.323800Z

^ disregard this, it returns a CompletableFuturewhich is indeed blocking. i'll have to run this on a separate thread pool

2021-04-20T16:11:11.324100Z

it depends on how you use the CompletableFuture

2021-04-20T16:11:28.324500Z

you can attach callbacks to it instead of derefing it

2021-04-20T17:08:56.324900Z

The docs on GitHub says it returns an Apache BasicFuture. Are the doc wrong or are you not using clj-http?

2021-04-20T20:54:23.325900Z

Hey fam, qq — is there a more idiomatic way you’d suggest writing this:

(defn wrap-around [tokens i]
  (let [left-el-idx (dec i)
        right-el-idx (inc i)]
    (concat
     (take left-el-idx tokens)
     (list (list (nth tokens i)
                 (nth tokens left-el-idx)
                 (nth tokens right-el-idx)))
     (drop (inc right-el-idx) tokens))))

(comment
  (= (wrap-around '(neg 3 * 2 + 1) 2)
     '(neg (* 3 2) + 1)))

2021-04-20T20:54:54.326800Z

(basically, given a list, i want to update a part of a list, to wrap, a range of inner elements)

2021-04-20T20:56:22.327400Z

the code would be much more readable if you used [x y z] instead of (list x y z)

2021-04-20T20:57:16.328400Z

(concat (take ...) [[(nth tokens 1) (nth tokens ...) (nth tokens ...)]] (drop ...))

seancorfield 2021-04-20T20:57:17.328500Z

I think using split-at might help too?

seancorfield 2021-04-20T21:02:19.331600Z

(defn wrap-around [tokens i]
  (let [[left right] (split-at (dec i) tokens)
        [l t r & right] right]
    (concat left [(list t l r)] right))))

❤️ 3
ghadi 2021-04-20T21:05:26.331900Z

it's idiomatic to add a docstring

ghadi 2021-04-20T21:05:44.332300Z

#1 recommendation

2021-04-20T21:05:46.332400Z

oo, nice. Thanks team!

ghadi 2021-04-20T21:06:03.332700Z

"update a part of a list" not semantic

👍 1
ghadi 2021-04-20T21:06:40.333500Z

is this op specific to tokens or lists of anything?

2021-04-20T21:10:09.335200Z

https://gist.github.com/stopachka/4957d20625f689a30df68c6108855e0b#file-play-clj-L66 ^ more context friend challenged me to write a “natural language calculator” of sorts in clojure. He thought our immutable data structs would make it harder to do…will show him >:)

👍 2
🧮 1