clojure 2020-05-04

@gretar.magnusson has joined the channel

@andrew.heywood has left the channel

Am i able to merge in a nested map?

(let [col-specs (:col-specs table-specs)
        extra-specs (:extra-specs table-specs)
        col-w-id (merge {:id (default-id-column)} col-specs)]
  (create-table name (hash-map :col-specs col-w-id :extra-specs extra-specs)))
My attempt now resumes in separate stuff and merge them again.

How about update? (Or update-in for deeper nesting levels.)

(update table-specs :col-specs #(merge {:id ...} %))

In this case, I think an assoc-in would be enough (if I’m reading this correctly)? (assoc-in table-specs [:col-specs :id] (default-id-column))

You could also do the following but that might get tedious when there are more default values. It would, however, avoid calling default-id-column if not necessary.

(update-in table-spec [:col-specs :id] #(or % (default-id-column)))

Oh no, it’s a default id

Meta merge is also an option, but I think that would be overkill if you’re only using it for this. https://github.com/weavejester/meta-merge I’d rather go with xsc’s solution

Thank you all

i'm adding a new key into existent data in col-specs

Today’s Monday Madness™. Here’s project.clj:

:dependencies [...
               [clojure.java-time "0.3.2"]
               ...]
and deps.edn:
:deps
 {...
  clojure.java-time {:mvn/version "0.3.2"},
  ...}
and REPL:
(require '[clojure.java-time :as cjt])
Execution error (FileNotFoundException) at user/eval36178 (form-init10994301252492343597.clj:1).
Could not locate clojure/java_time__init.class, clojure/java_time.clj or clojure/java_time.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
But I can see that the jar file is listed in my IDE deps.

ns java-time

there is no namespace clojure.java-time

Oh wow, thanks. Never even occurred to me to check for that.

@rafaeldelboni has left the channel

How difficult would it be for a small clojure project to import and use a locally built scala library?

that really depends on how the scala library exposes itself - if it limits itself to java compatibility and doesn't require inheriting a class, it will be easy

if it exposes scala features in its public api, not easy

it's directly analogous to using c++ from another language - if it sticks to the substrate it's easy, if it exposes things requiring its own features, not easy

Is there any intended use case for (constantly ['x]) vs (partial identity ['x]) ? (ie constantly vs identity) I'm trying to understand what is threshold for Clojure developers to include fundamental constructs into the base language. The more of these almost overlapping functions I encounter the more I'm asking these kinds of questions.

what's overlapping here? You partial throws an exception when there are args while constantly doesn't.

also, as an aside, style wise I'd go with '[x] over ['x]

Sounds good thanks for the recommendation

I've been googling this one a bit and turning up a blank. I have a function I'd like to perform differently when I'm in the development environment (or test) than in production code. Is there some way to def or call it that can accomplish this? Say (defn foo [x] doSomething) (defn ^:dev foo [x] doSomethingElse) or some such?

I do this kind of thing by using with-redefs, including the code that redefines the function in a namespace that is only included in development (:dev profile in lein or alias with clj tools)

👍 1

Ah ok, so just throw a with-redefs in my user.clj or some such eh? Sounds good. I'll give that a try. Thanks!

Hmm this doesn't seem to do quite what I'm after. I've used with-redefs for mocking in tests, etc. But what I'm looking for is to have, for instance, some fn that gets called in my normal code behave differently when I'm in a repl. Example: I have project.core/exit which prints a message then calls a fn that calls System/exit with a status code. I want that system-exit fn to not really call System/exit if it gets called from a dev environment.

If I understand correctly, I can only get a temp redefinition with with-redefs, so this wouldn't change things whenever things get called throughout the code outside of the with-redefs scope. Am I missing something?

Ah, nevermind. Figured out an acceptable way to use with-redefs here. Thanks again!

beware that with-redefs is not thread safe

if you always want the replacement, without any explcit scope, you can use alter-var-root which is actually safer

(though much blunter a tool)

Thanks 🙂 It seems that either works for my limited needs, but I'll keep the non-thread-safeness of with-redefs in mind.

How should my ci/cd pipeline call my Clojure repository's tests? From the command line I can do

Clojure -A:test
=> (require test :as t)
=> (t/-main)
but my experience with automation is that it can be tricky when you are responding to a programs prompts (like waiting for the repl to start, waiting for the require to load). Is there a one-liner that can do all of this? If not, what is the standard way people have their ci/cd call their tests?

from that output seems like you would do clojure -A:test -m test

from man clojure

main-opts
       -m, --main ns-name
              Call the -main function from namespace w/args

Ah thank you @dpsutton this is exactly what I was looking for!

Do aliases handlers defined in project.clj (leningen) require their own deps.edn? I'm running a custom alias command ({aliases {"mycommand" ["run" "-m" "myproject.scripts.core"]}) and I cannot require libraries defined in project.clj

nevermind the above, it was a typo in my config ^

@dan126 has joined the channel

@epr has joined the channel

Hi, we have build a small framework for building static websites in Clojure with hot-code reloading called Volcano: https://github.com/OrgPad-com/volcano. Feedback is welcomed!

👏 2

What are some reasons for using fully qualified keywords as map keys?

spec, more precise automated refactoring, ability to add new information to a map without worrying about clashing key names

cool, thanks

what kind of tools are used for the automated refactoring you are talking about here?

I was thinking of cursive. but fully qualified keys will also make things like sed and grep more accurate

and aliases make them less accurate again :D

eh, cursive or probably clj-refactor.el will know how to deal with aliases. sed/grep it's still more accurate than non-qualified, and aliases are usually used quite consistently

I have been tring to write clojure for less than 5 months now, I just bumped into this idea of namespaced keys while reading clojure.spec docs... Seems a little weird to me to be honest. Do you use it or the regular personally? @noisesmith @bfabry? Do you guys think this is something used a lot "out there"?

> aliases are usually used quite consistently you hiring ? :D

it's not used a lot in existing codebases but it's gaining traction. it's kinda a thing people realised later on "hey this is actually a really good idea we should do it more"

I used namespaced keywords before spec, I found them randomly while reading documentation and found that they helped with the dog/bark tree/bark problem - different domains use the same key to mean very disparate things and I wanted to know the difference

😀 1
☝️ 2

aaaah... @noisesmith that makes sense

which is exactly why spec uses them - letting different domains use their own meaning for bark, by namespacing bark

when you don't have namespacing, you get conflicting conventions (see every C lib foo, that defines each function as foo_x foo_y etc. etc...)

Coo, Thanks guys. Don't you think it's wonderful that I can talk to you like this? 😆

the internet is a wonderful thing

@franklineapiyo If you use the next.jdbc library for accessing a database, you'll find it returns hash maps with qualified keywords, so you can tell :person/id from :address/id in query results, for example.

@rmoss has joined the channel

Anyone know how to get the request headers from a compojure.api GET request?

(context "/base" []
    :tags ["base"]
    (GET "/me" [& req]
      (let [response (me req)]
        (println req)))) ; // req is empty

Can you try (GET "/me" req ..... - I don't think you need to wrap the request in a vector

wowzers. that did it

I dont know how I didn't think of trying that 🤯

Thats great thanks. I've been persuing the compojure.api docs all day, but completely overlooked the base compojure (non .api) docs

Thanks for the help

👍 1

@germank has joined the channel

Hi everyone I have a few years experience with Clojure/Clojurescript and now I passionate about contributing to an open-source project. I like to be a free help for the community but I don't know which project is the best fit for me and besides that, I don't know Where to begin and who to email and ... I become grateful if you give me your guide Thanks in advance Shima

What are the clojure projects and tools you like to use? Maybe you could start by looking at the issues in those github repos

@tajoddin.shima cross-posted to #beginners as well and I asked the same question there (and made the same suggestion).

We prefer folks not to cross-post because of duplicated questions and responses.

I use clojure and clojurescript for implementing an algorithmic trading in stock market I mostly like debugging complex bugs specially because those are related to logical bugs(not concurrency like other languages) I used timbre, Clojure core libraries, Component, onyx, Aero, reframe, shadow-cljs, ... @jjttjj

You're right I'm sorry and wouldn't do that again:pray: @seancorfield

NP. I deleted the question/thread/response from #beginners so we can continue here instead.

👍 1

I'm not very familiar with most of those projects (beyond Clojure core/contrib which have a different contribution process to many of the community libraries)... I used to follow Onyx early on but ended up not using it so I stopped following it.

It has 80 open issues and some of those look like very interesting bugs to try to reproduce and solve...

Do you mean the bugs list in Github? Or does they use backlog somewhere? @seancorfield It would be my first contribution, sorry if my questions are very trivial

But take a look at any of the OSS projects you've used and see what open issues they have in their GitHub repo. If you're not familiar yet with contributing to GH projects in general, some projects have a CONTRIBUTING doc that provides additional guidelines for that specific project, but you'll want to have a read through the (excellent) GitHub help docs which walk you through the whole cloning/forking/pull request process as well.

Some projects actually mark issues with some sort of label to indicate suitability for first time contributors.

If you ran into things you felt were usability or documentation issues with any of the projects you used, that's also a good place to get started by creating a new issue to describe the problems you encountered along with suggestions for improvements and see how maintainers respond.

(and on the Pull Request workflow mentioned above, there are projects out there which may not consider a PR if there hasn't already been an issue created to discuss the problem and various possible solutions)

Contributions aren't just code as well.

👍 1

@gerred Yup, I said that in the main channel -- as a project maintainer, contributions to documentation are particularly valuable!

I am not an expert at this but maybe this could help http://open-source.braveclojure.com/

👍 1

Just a list of some opensource clojure(script) projects. You might be interested in one.

👍 1

(I'll repeat my response from #beginners for the benefit of others here) It's often easier to start contributing to projects you've already used and are familiar with. Also worth bearing in mind that "contributing" takes many forms and a lot of projects desperately need help with either documentation or testing -- I know as an open source maintainer myself, I am always really happy when someone contributes improvements to the documentation (that make it easier for more people to use my projects).

👍 7

@sikavica has joined the channel