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?