beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
zackteo 2021-06-23T03:26:20.445500Z

Is there a sample ring + compojure server I can look at? :o

seancorfield 2021-06-23T03:30:10.446200Z

Something like this @zackteo? https://github.com/seancorfield/usermanager-example/ That's a bit more than just Ring + Compojure but it's a small working app with a DB.

zackteo 2021-06-23T03:36:18.447800Z

That works! Probably a bit more complicated compared to what I need but should be okay

seancorfield 2021-06-24T16:02:34.494300Z

I don't understand what you're asking here, sorry.

seancorfield 2021-06-23T03:37:16.447900Z

Feel free to DM me if you have any Qs about it.

seancorfield 2021-06-23T03:37:22.448100Z

Or ask them here.

zackteo 2021-06-23T03:37:40.448300Z

Will do!

indy 2021-06-23T04:23:20.448700Z

https://grep.app/search?q=compojure.core

salam 2021-06-23T06:07:46.449Z

i'm not sure if there's any convention but here is how i organize my test directories:

❯ tree test 
test
├── acceptance
│   └── shell
│       ├── api_server_test.clj
│       └── cli_app_test.clj
└── unit
    ├── core
    │   └── domain_test.clj
    └── shell
        └── utilities_test.clj

5 directories, 4 files
and i would override the default test alias in deps.edn with {:extra-paths ["test/acceptance" "test/unit"] so that tools like Cursive can find these directories and automatically mark them as "Test Sources Root", which in turn enables other useful Cursive features (e.g., jumping between production and test namespaces, automatically creating test namespaces in the right directories via shortcuts, etc.) this layout also works well with test runners such as Kaocha so that you will be able to run a particular kind of tests by specifying an id that maps to a directory:
#kaocha/v1
{:tests [{:id :unit
          :test-paths ["test/unit"]}
         {:id :acceptance
          :test-paths ["test/acceptance"]}]}

zackteo 2021-06-23T06:37:09.449800Z

Having some difficulty in understanding what I need to do to get a POST working and how to go about checking it. Should I be writing my response as json with clojure.jata.json/write-str

borkdude 2021-06-23T09:26:47.450600Z

@zackteo If you need something even more basic, you can omit compojure completely and build your own router as demonstrated here: https://github.com/kloimhardt/babashka-scittle-guestbook

zackteo 2021-06-28T08:02:45.137700Z

Thank you! @borkdude

2021-06-23T15:43:33.455500Z

does this function already exist? does it have a conventional name?

(defn f
  [g]
  (fn [x] (g x) x))
g side effects

2021-06-23T15:44:03.455700Z

tap?

2021-06-23T15:45:23.455800Z

looks like doto

👍 1
🙏 1
2021-06-23T15:49:17.456100Z

nice, this is it

arielalexi 2021-06-23T18:58:36.457800Z

Hey everyone, I have a problem with require one my files to another ont in the same project. this is how the project looks like :

.
├──src\c\g
      └── do_lib
           ├──views
      	      └── home.clj
           └── assets.clj 
the ns of assets.clj is: (ns c.g.do-lib.assets) I want to require the assets file in the home file so I did: (:require [c.g.do-lib.assets :as assets]) when I try to eval the home ns I'm getting a syntax error Class Not Found Exception then windows path of home.clj file directory on my computer then c.g.do-lib.assets. other requires that been imported don't make a problem. what did I miss ? thank you :)

dpsutton 2021-06-23T19:00:35.458200Z

how is assets.clj a child of home.clj?

arielalexi 2021-06-23T19:01:51.458600Z

by mistake - things change here - let me change it back

dpsutton 2021-06-23T19:03:10.459200Z

typo? c.g.do-lib.assets vs cO.g.do-lib.assets?

dpsutton 2021-06-23T19:03:30.459700Z

hard to tell which is a typo in slack and which might be a typo in your source. c.g vs co.g

dpsutton 2021-06-23T19:04:39.460200Z

can you post the full error message?

2021-06-23T19:07:07.461300Z

what's the ns did you put in home.clj? from the dir tree it should be (ns c.g.do-lib.views.home)

arielalexi 2021-06-23T19:07:46.461500Z

Syntax error (ClassNotFoundException) compiling at (c:\Users\..\my-pro\src\c\g\do_lib\views\home.cljc:0:0). c.g.do_lib.assets

arielalexi 2021-06-23T19:08:59.462100Z

the ns I used for home.clj is (ns c.g.do-lib.views.home)

ghadi 2021-06-23T19:10:44.462400Z

the directory do-lib needs to be do_lib

dpsutton 2021-06-23T19:11:04.463200Z

(c:\Users\..\my-pro\src\c\g\do_lib\views\home.cljc:0:0) it seems to be

ghadi 2021-06-23T19:12:21.464100Z

just double check that namespaces have dashes, and the corresponding files/dirs have underscores

ghadi 2021-06-23T19:12:34.464500Z

It's a common stumbling point

dpsutton 2021-06-23T19:13:19.465900Z

ah, good point. in your tree output it is with a hyphen and in the copied error it has an underscore. These copy paste mistakes can make diagnosing issues quite difficult

arielalexi 2021-06-23T19:14:56.466800Z

the tree output shold look like the directory exactly?

arielalexi 2021-06-23T19:15:59.467600Z

in the directory name it is do_lib but I changed it in the namespace to be do-lib.

2021-06-23T19:17:57.468500Z

so the dir name is already do_lib before ghadi's suggestion?

arielalexi 2021-06-23T19:18:05.468900Z

yes

2021-06-23T19:18:50.469300Z

maybe you haven't saved the file after changing the namespace?

2021-06-23T19:21:45.470400Z

hmm, have you tried to eval the home.clj file directly?

arielalexi 2021-06-23T19:23:32.472600Z

@myguidingstar - reopening and eval the file solved it. thank you all for the help 🙂

👏 1
2021-06-23T19:39:58.475Z

In the clojure core function sort-by

([keyfn ^java.util.Comparator comp coll]
   (sort (fn [x y] (. comp (compare (keyfn x) (keyfn y)))) coll))
I'm not sure i understand the use of the dot here. I understand it to be related to java interopt. Is this a case of Member access ? e.g (.instanceMember instance args)* (.instanceMember Classname args)*

phronmophobic 2021-06-23T19:41:31.475200Z

It's this one: `(. instance-expr (method-symbol args))`*

phronmophobic 2021-06-23T19:42:04.475500Z

Calling the compare method on comp, https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html#compare-T-T-

ghadi 2021-06-23T19:44:39.476700Z

(.doThing obj a b c) == (. obj (doThing a b c)) == in Java: obj.doThing(a, b, c)

👆 1
2021-06-23T19:50:06.477300Z

ah ok, so comp here isn't clojures.core/comp. that was causing me some confusion

2021-06-23T19:50:25.477600Z

I was looking past the params