Fork me on GitHub

question- how would I translate the following into clojure?

socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

  public void call(Object... args) {
    socket.emit("foo", "hi");


I’m thinking reify or proxy


proxy might work better


I would prefer reify to proxy in most cases. See this thread and answer by @kushalp for why:


How can I read the first part of this [:debet {:account "cash", :amount 100}] so I need :debet as output


I’m not sure I understand your question, but if you literally want to get :debet out of it, it’s (first [:debet {:account "cash", :amount 100}]). If that’s not what you’re asking, please clarify.


Is there some good practice on primary key’s type?. I have seen in many examples the use of an UUID instead of a auto incremental integer. Is this related to concurrency?


If anyone is interested, I found a good explanation here: In short, they provide “uniqueness” along multiple databases and tables, which can be pretty useful in some situations. Also, they hide information about the amount of information that resides inside a table (I am not sure why this could be a good thing).


@rcanepa: If you choose to use auto increment ints or bigints attacker may guess the id's of the next entry. This opens for some attacks that are not possible by choosing random ids like UUIDs


They might also guess the ids of existing database entries


@sveri: Thanks for the input on this. I wasn’t aware of those risks.


@rcanepa: Yea, np. It's a rat race. I think such common knowledge should be bundled into libs or frameworks so that newcomers don't have to deal with it immediately.


@eggsyntax: you are right . That is working but when I have this

(def transaction  [ {:debet :account "cash" :amount 100 }} { :credit {:account "bank" :amount 100}} ]
then this is not working : (first (first transaction) )) I see then [:debet {:account "cash", :amount 100}] instead of just :debet


@roelof: That's not valid clj, though. Is the second closing squiggly brace on the first map a typo? Or did you intent an opening squiggly before the first :account?


@eggsyntax: I think the last ) is a left-over from closing the function


so it will be (first (first transaction) )


No, I mean in the def. Will you reshape that into valid clojure & repost?


oke, sorry : then it will be (def transaction [ {:debet {:account "cash" :amount 100 } } { :credit {:account "bank" :amount 100}} ]


maybe that is the problem


OK. Note that in your original post you had [:debet ...], and here you have {:debet ...}. That is, you've changed the vector to a map.


If it were a vector, (first (first transaction)) would work fine.


If you want it to be a map, it gets a bit more awkward, but you could do (first (keys (first transation))).


It feels to me like maybe you haven't quite clarified in your mind what you're trying to represent.


Thanks the keys are working


@eggsyntax: im experimenting what is the best way to represent


If you want the transaction to consist, by definition, of a debit and a credit, I'd consider something like

(def transaction {:debit {:account "cash" :amount 100}
                  :credit {:account "bank" :amount 100}})


Then you don't have to pull out the name :debit, because you know it'll contain a debit, so you can just do (:debit transaction) to get the info about the debit.


@thanks , I will try your suggestion


I am attempting to create an app that I upload a file to and read its contents before doing other things. I am getting the parameters back from my uploaded file and I am unsure how I would read the uploaded file from ring.middleware.multipart-params. The parameter map of a sample uploaded file is as follows: {:file {:size 70, :tempfile #<File /tmp/ring-multipart-4755435914544293619.tmp>, :content-type text/csv, :filename request_temp.csv}} 1. Do I use the :tempfile key or the :filename key? 2. Is there an extra step that I am missing?

Chris O’Donnell23:12:00

@kyle_schmidt: it looks to me like you should use the :tempfile key, as its value is a File object.


@codonnell: I was trying that and it wasn't cooperating. I'll keep experimenting.


Does make any sense to use protocols to define CRUD operations on different models/types? Or I will gain nothing because I will just move complexity from one place to another?… I am learning about multimethods and protocols and I am trying to come up with a situation in which they may useful.


In other words, what question do I need to ask myself to evaluate if polymorphism will be useful in a particular case?