my curiosity about Lisp dialects finally got the better of me (for the second time! over a decade ago young kas bounced off of Common Lisp) and I’m currently reading Brave Clojure
so far it feels like I’ve entered an alternate timeline where some language other than C got to define what modern syntax should look like, and it’s pretty disorienting. but I bet I can get used to that part in time, and I actually think all the parenthesis look pretty cool
hm okay one thing that’s confusing me right off the bat is how to ask the question “what can I do with this data?”
like for example in Python, if I have a string:
some_string = "foo"
and I want to know what I can do with it, I can type some_string. and neovim will show me a list of all of the methods on the str class, so I can see that it’s possible to .split() a string or use it to .join() something. and it will even show me the docstrings for all of those methods as I scroll through them, so I know exactly what each of those methods does
but in Clojure if I have a vector, I’m not sure what I can do to get a list of functions that can do something to that vector
hm I found the API reference but it seems to just be a totally unorganized dump of lots of functions, in alphabetical order. that’s not exactly helpful if I’m trying to figure out how to get the nth element of a vector, or how to convert a string to lowercase
ohh this is more like it! still not ideal, but this is so much more organized than the API reference
so one of the things that drew me to Clojure and fascinated me about it is the concept that it has “almost no syntax”. I felt like I would be able to reason about Clojure’s syntax very simply and intuitively despite how strange it looks at first glance, and that felt like a pretty cool and unique advantage. but now that I’ve dived a little deeper into the language I honestly feel like saying that Clojure has “almost no syntax” is just sleight of hand
the thing is, Clojure has plenty of syntax. it’s just that that syntax is called a “special form” or a “macro”. but syntax is syntax. you can’t tell me that this syntax for defining a function:
(defn func-name
"docstring"
[arg-a arg-b & args]
(code here))
is any simpler than this syntax:
def func_name(arg_a, arg_b, *args):
"""docstring"""
# code here
to me it’s actually harder to reason about and understand, because of how weird it is compared to any other language I’ve used before
plus Clojure’s syntax often requires you to keep track of strange things like “okay is this an even-numbered argument or an odd-numbered argument? is this the third or fourth argument? oh that’s right this is destructuring the map which means that the syntax is backwards” which constantly trips me up
anyway idk I’m feeling pretty disillusioned about Clojure. it looks so cool and mysterious and sophisticated on the outside, and the concept of macros that execute at runtime is so cool, and everybody talks about how elegant it is. and maybe my lack of experience with the language is just making me jump to conclusions about it. but it just doesn’t feel like that good of a language to me. it feels like something that was designed in the past before we had figured out what makes a language easy to read and easy to write
@kasdeya I do not know Clojure much, but I predominantly use Common Lisp. There is definitely syntax and rules in both, and you do have to look up a bunch of functions (I have a copy of the lisp hyperspec downloaded to my laptop lol, cause I have to look up stuff all the time). I like the syntax for usage, it is more readable to me with parens and then the convention of making a bunch of different functions helps me understand what the code does. But defining functions and macros can be relatively confusing.
(And the paired arguments only matter with keywords in lisp, to let you specify a keyword and value together. So it is kinda nice once you get used to it. Not at all sure about clojure though.)
@Shivaekul it’s interesting to hear your thoughts, as someone who uses Lisp so much! I guess at this point I can safely say that no Lisp dialect is going to click for me, but I do still find the concept of code-as-data pretty cool. now that Rust (which has a seemingly similar, compile-time macro system) is getting so popular, I hope we’ll see more languages take this kind of approach
@kasdeya Honestly a lot of things didn't click at first, and some of it still doesn't. For CL at least part of the awesomeness, but also part of the downside, is that you have a ton of freedom in how you want to do things. But it makes it very easy to get overwhelmed, because there is no "best" way. A lot of the dialects are a bit more opinionated, but I think one of the benefits of lisps are still the freedom to customize things. So more how do you fit the language to you, than how do you fit to the language. So I wouldn't rule them out entirely, but also no pressure to continue with them either, all about what makes sense to you :)
It is awesome that Rust has macros, and I think Rust has a lot of other benefits too. It seems like Rust has done a lot of things right, and look forward to people continuing to develop and derive inspiration from it as well!