Echoing back input in uppercase over a socket with Hy, a Python Lisp dialect I think I'd like to learn Clojure eventually, but at the moment am having fun with Hy, a "dialect of Lisp that's embedded in Python." 

(import socket)

(defn echo-upper (sock)
  (.send c (.upper (.recv c 10000)))
  (.close c)
)

(def s socket.socket)
(.bind s (tuple ["" 8000]))
(.listen s 5)
(while True
  (echo-upper (.__getitem__ (s.accept) 0))
)


Python generated from ABS with astor:

import socket

def echo_upper(sock):
    c.send(c.recv(10000).upper())
    return c.close()
s = socket.socket
s.bind(tuple([u'', 8000]))
s.listen(5)
while True:
    echo_upper(s.accept().__getitem__(0))


I'm not worried about not dealing with connections properly etc, I'd just like feedback on using lispy syntax. I'm tempted to do things like ((getattr s "bind") (tuple ["" 8000])) because it looks more like simple Scheme, the only lisp I have a little experience with.

Any thoughts on syntax and style? Any guidelines for dealing with Python APIs in a lispy way, something that apparently happens a lot in Clojure with Java?
I wouldn't use the threading macro here. That's most useful when you want to see the data flow, but you're using c two times in this expression, there's no clear flow that -&gt; could make easier to untangle. It makes it more complicated in this case...

If you'd decouple the receive and the send part, then it'd be different, but then the expression becomes so simple you don't even need the macro:

(let [[received (.recv c 10000)]]
  (.send c (.upper received)))


With the threading macro, the inner part would become (-&gt; received (.upper) (.send c)) - doesn't make it much clearer, either.

What you could do, however, is abstract away the accept -> do something -> close thing into a macro:

(defmacro with-accepted-connection [listening-socket &amp; rest]
  (quasiquote (let [[*sock* (get (.accept (unquote listening-socket)) 0)]]
                (unquote-splice rest)
                (.close *sock*))))

(with-accepted-connection s (.send *sock* (upper (.recv *sock* 10000))))


The above may or may not work out of the box, I just conjured it up. But something similar may make the code lispier and easier to understand the intent later.