Fork me on GitHub
Anik Chowhdury08:07:16

hi! I'm noob to clojure. I am using luminus for creating webserver for routing. I want to pass data using route like the url is "http://localhost:3600/test?data=“xxx” " want to get the data which will be dynamically changed.

(defn testing-func
  [{:keys [path-params query-params body-params]}]
  {:status 200
   :body   (str "path params: " path-params
             "\nquery params: " query-params
             "\nbody params: " body-params)}
  (prn "id details:" query-params))

(defroutes home-routes
  (POST "/test/:id" [id] (testing-func id))

here is my code. I know there is lots of mistakes. Can anyone tell me how to get data from routes? Thanks in advance!


your route would be (POST "/test/:id" request (testing-func request))


then if you change your testing func to


(defn testing-func [{:keys [path-params query-params body-params] :as request}] ... )


and then in the body of the function print out the request


(clojure.pprint/pprint request)


now hit it with some POST requests and have a look whats inside the request hashmap


you should find all kinds of goodies in there


if you have anymore queries try #luminus


oh and be aware that doesn't match the url you posted as tryng


so make sure your POST requests go to the right URL


to match the URL you are using it would be (POST "/test" request (testing-func request))


also ? are get parameters not post

David Pham09:07:03

I have been coding with Clojure since a few years (professionally since a 1 year thanks to CLJS). I read this article from Eric Normand and I wondered what it meant to be coding in the functional paradigm? I use pure function, function composition, immutable data (except for atoms) and focus on declaration more than imperative. Do I miss anything in my toolbox?

David Pham09:07:51

(I am really happy to code with Clojure that being said).


Unless I'm not missing some things 😁 :thinking_face:


There is Also the club of lispers, but the group of functional is that imho

David Pham09:07:40

@darioszr I can’t read the first part of your message haha


Aha sorry, let me rewrite it I think I had some typos


1st part: IO handling and states, composition, declaritive code and data thinking is the key to be in the functional club


So IMHO you are already in the club, welcom:clj:


For sure you can improve things, but to me with also immutable data, this all are key factors to be in functional paradigm. But maybe others could express their pov


The functional thinking is imho when you think how to manipulate your data in pipelines or transducers and immutability is also something that Oop people dont get it

👍 8
David Pham09:07:57

Ok, by that definition I am for sure a FP member lol. I still can’t understand why python does not have -> in their language

David Pham09:07:09

Thanks a lot. I really thought I was missing something.


Yw, but IMHO we are speaking on the functional low level of things. To me the functional level can be also improved, like how is à functional system, how components interact in a functional way. Eg understanding persistent data structures, message passing applications this is imho what is interesting on more larger view.


Just citing 2 examples..


How to achieve this with Clojure? Suppose I am getting a string from console. “A B C”. Now I am splitting this string using split function. And trying map each of the sub string to a particular key in map. {:first-name A , :last-name B , :middxlename C}. Now, if I get another console input. I want to append that entry into the existing map. If second console input is “D E F”. Then, resulting map I am expecting is :- { {:first-name A , :last-name B , :middlename C} {:first-name D , :last-name E , :middlename F} } I’have just started getting into Clojure. Any help would be great.


You can right a fn that parses the string into a map like this:

(defn parse [s]
 (->> (clojure.string/split s #" ")
      (zipmap [:first :last :middle])))


(parse "A B C") will return {:first "A", :last "B", :middle "C"}


You can then just maintain a vector and use conj to append to it for each input received.


But I feel like I misunderstood what you want? Does this make sense @parth.12282?

David Pham11:07:03

How I see: it is you can a mutable state but the functions that processes the input should be pure

David Pham11:07:26

(From my experience of re-frame)

David Pham11:07:27

(The funniest piece of documentation)


@jaihindhreddy vector wont let me mutate the state.If i am doing conj with another map as input. I need to store that output somewhere. (As per my limited knowledge)


Is what your working on an interactive cli in Clojure?


i am parsing console commands one after another

David Pham11:07:25

Save the state in a global atom


yup, you'd use an atom. I don't know if the app at hand is an interactive thing where user enters these string, which is when atoms would be right, or if it is possible to get all the inputs at the same time in which case its a simple (map parse strs)

David Pham13:07:59

@darioszr Do you know where I could read about functional systems? What are the guidelines? My understanding is we should apply the same principle as in low level: avoid states, (pure systems? Same input yields the same output)?


The book clojure Applied from @alexmiller discuss it in some chapters. A part of that book, i recommend you the talk of rich; Unfortunately I think our industry isnt that mature, to build f systems' I think building functional systems is our challenge for nowadays. I mean building functional style programs, is for developers sanity of mind 😁


But we should not stop on the micro level, we should extend this in the system level, e.g persistent data structures, channels etc. I'm just starting researching the topic. But this is imho what business people, Users, care 😁


A part of that, we don't have like functional architecture books yet, I don't know if somebody has such book feel free to share


Recently I have bought this book


But they are free online. I think it is a cool book, discussing architectures of OOp mostly software but one can extrapolate some principles... There is also the Haskell compiler there afaik


But it is not written In Haskell for sure 😁


@darioszr I think the book Domain-driven design is very interesting for functional programming, it’s not really about any specific programming paradigm but the books talks about a lot of concepts which go very well together with functional programming


Right which do you mean? Because there are 2 out there


I have heard about that but there are severals


I might read it, I have heard good things about it


it’s worth your while! 🙂 I especially like that it’s not preachy like a lot of other software books, instead it’s like “use this when you think that it makes sense, if it doesn’t, do something else”

clj 4

change :n -> :1


Hi all, I'm searching in the web on a document between data serialization formats différence


I know that Rich and Stuart talked a little on the subjects. If anyone know a good line where it is somehow explained in deep, feel free to share clj lambdalove


(I'm referring to talk of language of system video) where data formats are described


Check out Stuart Halloway's talk on Fressian.


I'm interested in this too. Will post in this thread when I find something interesting.

clj 4

Do you have a link for that talk?


About system found out also this great talk, it talk about great things (link: