Live data from Hacker News

Why I like Clojure

sulami.github.io

11–20 of 155 posts

Re: Why I like Clojure

#11
One (stupid?) thing that annoys me about closure is that native clojure libraries use snake case while java libraries use camel case. You could obviously write a new defn macro to take of all this and make it consistent, but it might have just been a better decision to just make everything camel case, in in Lisp-like fashion.

Also I find Clojure a little dogmatic in regards to mutation, more so than even Scheme. I find Racket to be better designed and more elegant, though currently the performance isn’t as good.

Re: Why I like Clojure

#12
> While OO seems to be out, and FP the new hotness

Funny that. While I prefer FP, and did since I've learned Python, my teachers are really hot about OO, even pushing us to use it in Python projects.

(Looking at projects from previous years, they mostly seemed to use Java. Then also because of browser integration and obviously because of the OO UML Project links ?)

Re: Why I like Clojure

#13

> homoiconicity, meaning code can be represented as a data structure inside the same language > generating strings and passing them into eval like for example in Python Python has become a pinata for language enthusiasts? Python lets you pin a decorator on a function, get the AST (a data structure AFAIK), manipulate it in a sane fashion in Python, compile it, return the result. No string munching eval require I'm all…

You might enjoy this talk- Live Coding a Compiler using Clojure at https://youtu.be/_lMltUNB6Yw?list=PLhYmIiHOMWoEgJEvgkmUe8D0a...

Re: Why I like Clojure

#14
post #11

One (stupid?) thing that annoys me about closure is that native clojure libraries use snake case while java libraries use camel case. You could obviously write a new defn macro to take of all this and make it consistent, but it might have just been a better decision to just make everything camel case, in in Lisp-like fashion. Also I find Clojure a little dogmatic in regards to mutation, more so than even Scheme. I fi…

The macro solution is only solving for the aesthetics of the code and is opening the door to infinite edge cases where it wouldn’t work or could have unintended side effects.

I don’t disagree with you that it’s ugly and sometimes tedious to use Java in Clojure... but that is one of the foundational strengths of the language. It’s also something that you’re hopefully not doing a lot of... so I think the trade off of seeing ugly Java syntax sprinkled in your project is worthwhile.

You’re standing on the shoulders of giants with zero to no penalty as far as interop. I might reframe your mentality to see this as a huge benefit and not something stupid!

Re: Why I like Clojure

#16

> homoiconicity, meaning code can be represented as a data structure inside the same language > generating strings and passing them into eval like for example in Python Python has become a pinata for language enthusiasts? Python lets you pin a decorator on a function, get the AST (a data structure AFAIK), manipulate it in a sane fashion in Python, compile it, return the result. No string munching eval require I'm all…

A python decorator is just a syntactic sugar for :

f = decorator(f)

Afaik, the decorator deals with the internal function as a black box.

But with lisp being a lisp, the macro writer can choose the level of blackboxiness they want to deal with.

Note: I love both Python and Clojure and use them extensively.

Re: Why I like Clojure

#17

> homoiconicity, meaning code can be represented as a data structure inside the same language > generating strings and passing them into eval like for example in Python Python has become a pinata for language enthusiasts? Python lets you pin a decorator on a function, get the AST (a data structure AFAIK), manipulate it in a sane fashion in Python, compile it, return the result. No string munching eval require I'm all…

While you can manipulate Python's AST, you can't do it in a way that looks like adding new syntax.

In Clojure you can write a list comprehension as `(for [x (range 10)] x)`. In Python you can write it as `[x for x in range(10)]`.

Imagine these didn't exist, and you wanted to implement them yourself.

In Clojure this is possible. Its list comprehensions are implemented as a Clojure macro: https://github.com/clojure/clojure/blob/b98ba84/src/clj/cloj...

In Python there are several problems. The first is that you can't easily pull the decorator trick on arbitrary expressions. Not even with a lambda function, at least without doing a lot of work - inspect.getsource doesn't handle those properly.

But let's lower the bar, and replicate `l = [x for x in range(10)]` instead. You can do that with a decorator and an ordinary function.

Then the problem becomes that you can only use existing syntax in the function body. Syntax that already means something else. If you put an ordinary list comprehension in the function body then you get a syntax error when the file is parsed, long before the decorator has a chance to do anything. So you have to make something up yourself.

You might end up with something like this:

  @list_comp
  def l():
      x: range(10)
      x
Or, of course, this:

  l = list(map(lambda x: x, range(10)))
Neither of these are as convenient or readable as real list comprehensions. But if you want those, you're at the whims of the language. You can't just add them yourself.

I don't know how big of a deal this actually is. I've never used Clojure, and I've barely used other Lisps. Expressing what I want in Python is easy enough in practice (but maybe I just don't know any better?). But there's certainly something significant there that Python can't do.

Re: Why I like Clojure

#18
post #11

One (stupid?) thing that annoys me about closure is that native clojure libraries use snake case while java libraries use camel case. You could obviously write a new defn macro to take of all this and make it consistent, but it might have just been a better decision to just make everything camel case, in in Lisp-like fashion. Also I find Clojure a little dogmatic in regards to mutation, more so than even Scheme. I fi…

Clojure being dogmatic is the reason I love it.

Re: Why I like Clojure

#19

> homoiconicity, meaning code can be represented as a data structure inside the same language > generating strings and passing them into eval like for example in Python Python has become a pinata for language enthusiasts? Python lets you pin a decorator on a function, get the AST (a data structure AFAIK), manipulate it in a sane fashion in Python, compile it, return the result. No string munching eval require I'm all…

> get the AST (a data structure AFAIK), manipulate it in a sane fashion in Python, compile it, return the result. No string munching eval require I use both Lisps and Python, and especially after learning to use Lisps I've wanted to do this in Python, so I looked for the ability to do what you describe here. While it is technically possible to do this (like most things) in Python, it is quite the effort and nowhere n…

Thank you, interesting comments, especially switching over to the Hy language for production. I got very excited about Hy, then an update took away a built in “let” and that turned me off a bit. Are there any good directions for patching in the old code supporting “let”?

Re: Why I like Clojure

#20
post #18
post #11

One (stupid?) thing that annoys me about closure is that native clojure libraries use snake case while java libraries use camel case. You could obviously write a new defn macro to take of all this and make it consistent, but it might have just been a better decision to just make everything camel case, in in Lisp-like fashion. Also I find Clojure a little dogmatic in regards to mutation, more so than even Scheme. I fi…

Clojure being dogmatic is the reason I love it.

Agreed. While I don’t always agree with its dogma, without it I don’t think I’d still be using Clojure, yet here I am ten years after first learning it. Clojure is great because it takes a strong stance on how certain things should be done.
Post reply on HN