7 ms·
I have honestly tried many many times to read books/tutorials for getting started in LISP. I know there are many LISP inspired languages and Clojure is one of t
by maxpert 9y ago
I have honestly tried many many times to read books/tutorials for getting started in LISP. I know there are many LISP inspired languages and Clojure is one of them. Where LISP throws me off is the excessive use of parenthesis, up-to the point my mind can't keep track of them anymore and IMHO language uses it's comprehension abilities. I am still struggling and pushing hard to learn it; hopefully I can get over it and experience the most powerful language. Any good starting projects/ideas I should try doing in LISP/Clojure etc. to help me out?
- hellofunk 9y agoThe parenthesis disappear from your thoughts after a few days, especially if you are using a proper editor with a feature like paredit. Clojure improves on this compared to other lisps because it uses brackets and squiggly braces instead of parenthesis for a lot of its syntax, making that aspect much easier to read. Just stick with it, you will see it is a non-issue after you get started in earnest.
- vbuwivbiu 9y agofunction.(x,y,z) (function x y z)
- civility 9y agoI happen to like Lisp (well, Scheme at least), but I think a better comparison would be: let a = 123, b = 456, c = 789; # more code vs: (let ((a 123) (b 456) (c 789)) ; more code ) In many cases outside of function calls, there are more parens.
- hellofunk 9y agoAnd in Clojure: (let [a 123 b 456 c 789] ...) Clojure syntax was designed with a clear and deliberate attempt to remove many of the parenthesis from lisp syntax. This is just a part of the greater design goal of offering very concise and elegant syntax in general, which is one of the reasons I keep coming back to it.
- civility 9y agoYep, Clojure made some nice improvements (still 4 parens, however), but I just can't get excited about the JVM.
- hellofunk 9y ago> (still 4 parens, however) My example has 2 parens. Even if you're not excited about the JVM, ClojureScript is particularly productive for front end development, where I genuinely love it tremendously.
- technion 9y agoThe JVM does solve the distribution problem that's heavily frustrated me with other platforms. I can create a great tool in Ruby for example, but asking a computer illiterate to run it in Windows isn't going to happen. You can however hand that person a .jar from Clojure and ask them to run it.
- megaman22 9y agoAssuming they have Java installed. Which, in my experience, is less and less likely as time goes on, for random samplings of non-developer Windows boxes.
- kuschku 9y agoNot anymore! Java now can link JVM, runtime, and your own modules into a bundle that just works and runs everywhere. On Linux, you’re even able to compile most of it into a single binary.
- megaman22 9y agoGood to know. Does it tree-shake to cut down irrelevant stuff out of thefinal package?
- 9y ago
- deleted 9y ago[deleted]
- vbuwivbiu 9y agowell, ok but the comparison is moot when you consider that dense lets are rare in Lisp
- TeMPOraL 9y agoWell, a more accurate comparison would be like this: { let a = 123, b = 456, c = 789; # more code } Because Lisp let explicitly defines its scope, while the first example inherits the scope from whatever it is embedded in.
- vbuwivbiu 9y agothat should have been object.function(x,y,z) or function(x,y,z) - typo and it's too late to edit
- rixed 9y agoLast time I checked there were not more parenthesis in lisp than parenthesis+brackets+curly brackets on other languages. If you need the visual differences between those various kind of parentheses, many lisps and schemes allows to use and mix any of those. If you are confused because the parentheses are not in the usual place, then I think you are trying to solve problems that are too trivial if such a tiny bit of syntax get all the attention. Or, that you are trying Lisp on problems that are not a good fit. Obviously, lisp (or ML, for that matter) shines at manipulating symbols, not bytes. I do not personally believe that lisp is, in general, "the most powerful language", but there is a problem where it can be said that it is the most powerful language: it's to write a Lisp interpreter. Maybe that's the good starting project you are looking for? If so, I can't recommend enough the book "lisp in small pieces".
- hellofunk 9y ago> Last time I checked there were not more parenthesis in lisp than parenthesis+brackets+curly brackets on other languages. This is true a lot of the time. Also, commas don't exist in Clojure. So you might have this in a C-like language: if ((foo > bar) && (bar > boo)) { doSomething(a,b,c); } else { doSomethingElse(d,e,f); } And in Clojure: (if (> foo bar boo) (doSomething a b c) (doSomethingElse d e f)) Another interesting side effect is that in C-like lang, one my say that due to precedence rules, (foo > bar) does not need the parenthesis since && is lower precedence. Yet, if you weren't sure, you'd have to take a short break and go look that up to be certain. Most devs will just keep the parenthesis instead of take that little break, or they will write them in anyway for readability. In Lisp, precedence rules are never an issue because all operators and functions are applied the same way. So the parenthesis might seem cumbersome at first, but they quickly make syntax quite a lot simpler.
- DigitalJack 9y agoCommas are whitespace in Clojure. You can use them if you want to, it's just not idiomatic.
- 9y ago
- kazinator 9y agoUse an editor that helps balance parentheses and automatically indents Lisp code. If the indentation is consistent with the parentheses (very easy to maintain with a decent editor) then you can mostly ignore the parentheses and just look at the indentation. Break big functions with deep nesting into smaller functions. (Like in any language). If you have to page up and down several screenfuls to check whether multiple blocks are at the same indentation level and under the same parent, maybe the function is too big.
- sn9 9y agoParentheses aren't an issue if you write Lisp in Emacs.
- hellofunk 9y agoYou don't need emacs for good parenthesis control. The same tools emacs uses for this are available in about a dozen editors at least. Vim, Atom, Cursive/IntelliJ, Eclipse, Sublime Text, it's pretty common in most good editors.
- platz 9y agoUnderstanding programs with recusion requires actually programming with recusion that many devs just aren't exposed to. It's just not the dominant paradigm
- yogthos 9y agoExplicit recursion is rarely used in FP, and it's often a code smell. It's almost always better to use higher order functions instead. The advantage is that you can implement a particular transformation once, check for edge cases, and reuse it from there on. You also end up with declarative code that talks about what it's doing without distracting your with implementation details. Clojure has a rich set of functions for manipulating data such as map, filter, reduce, and so on. There are also libraries such as Specter https://github.com/nathanmarz/specter https://github.com/nathanmarz/specter that allow you to declaratively transform complex data. I highly recommend watching this https://youtu.be/rh5J4vacG98 https://youtu.be/rh5J4vacG98 short video to see how it works.
- grayrest 9y ago> Where LISP throws me off is the excessive use of parenthesis There's a standard way to indent lisp (the emacs way, which everybody copies) and as long as it's indented properly you read it like a whitespace significant language (Python, F#, etc). Clojure is a bit easier to read than other lisps because it uses [] for vectors, arguments, and assignment blocks and {} for maps and sets. Gives the code a bit more texture. People writing lisp day to day use an editor feature to automatically keep parens balanced (Paredit, Parinfer). Not required since there's a learning curve but it makes editing smoother if you're going to write lisp full time. A text editor that highlights the opening paren when the cursor is on the closing one (pretty common feature) is all you really need.
- j_m_b 9y agoIt also uses fewer parens than other lisps. Clojure let statement (let [foo "bar" baz "qux"] foo) => "bar" Scheme (let ((foo "bar") (baz "qux")) foo) "bar" So in addition to additional symbols for notating vectors, map, etc, it uses fewer parens in general.
- didip 9y agoYou just have to indent them the same way you'd indent curly braces. The harder part about lisp is actually recursion. Surprisingly, there aren't a lot of programmers who can follow recursion naturally. (loop exists in lisp but recursion seems to be the common idiom)
- ZenoArrow 9y ago>"The harder part about lisp is actually recursion. Surprisingly, there aren't a lot of programmers who can follow recursion naturally." All examples of recursion I've ever seen in Lisp follow a similar structure... * First section checks if recursion is finished. If so, return final result (or final element of full result if returning a list). * Second section performs an action or two on the inputs. * Third section calls the function again with revised inputs. In many ways it's just a do while loop with different syntax.
- xfer 9y agoNot true; loops exist (as a macro) because recursive functions(that naturally correspond to loops and iterations) are harder to read because they hide the logic of termination conditions. Fortunately we are using a powerful language, that lets us transform natural loop syntax to a recursive function.
- Sharlin 9y agoIn my experience you rarely need recursion in Clojure, to the point that it's unidiomatic to use it. For 95% of your looping needs you use combinators, and for the rest there are the loop macros.
- hellofunk 9y agoI would say nearly all my loops are either map or reduce. That's it.
- keymone 9y agothat was literally my story as well until i tried Clojure. i think convenient data literals is the top reason i could stick with it and properly learn a LISP. immutable to the core, nice concurrency primitives, trivial access to the whole java ecosystem - those are just cherries on top. try using Atom with Parinfer plugin. i vehemently disagree with people trying to push emacs on Clojure/LISP newcomers. having to learn a possibly completely alien editor to be effective programming LISP is another big thing that pushes people away.
- ACow_Adonis 9y agoIf you've done lisp for a while, you don't try to match the parentheses. Firstly, you have an editor that matches them up for you. Secondly, you read via indentation and whitespace. And since just about the only thing defining the syntax of lisps is the list structure, the editor also parses and can take care of that relatively automatically too. I found it took about 6-12 months of exposure, and then your brain just tweaks/snaps/breaks magically one day, they all disappear, and then you no longer see them :P
- blunte 9y agoTry once more. Pick a small project and just try and try again until you get it written. Tip #1 - spend more time in the repl than in the editor. The repl lets you figure out and grok the small things. Tip #2 - compose the small things into bigger things. (And if you find yourself composing too many semi-complex expressions into on big expression, feel free to take any smaller grouping of expressions and turn them into a function. You may start out very disoriented; but if you keep trying, at some point after trying (perhaps for a few evenings, consistently) it will just suddenly click. It's a wonderful feeling to suddenly get it. One last tip - Everything is really just this pattern: open paren, operator, some number of parameters/data, close paren. I'm not a Lisp teacher, so I may be stating this inaccurately, but it's just that simple. The pieces may look like more than what I just described, but they are really that simple. And on the topic of "too many parens", compared to Javascript, C/C++, Java and many other languages, you'll find about the same number of them. They're just arranged differently (and more uniformly in Lisp). Better yet, because they're so uniform, you can completely ignore/forget about the end of big expressions with their )))). Ignore it. Use an editor that matches braces, (I like rainbow color matching). And now, a warning. If you take the time to really learn Clojure, there's a good chance you'll love it. Then you will find that in most companies, you won't be able to use it unless you sneak it in. Then you'll end up in Elixir because it "looks like" Ruby, and because everyone bought into Rails. But you'll still wish you were using Clojure.
- TeMPOraL 9y ago> And on the topic of "too many parens", compared to Javascript, C/C++, Java and many other languages, you'll find about the same number of them. Exactly. Even more, if you start counting {}, <> and []... Also, before someone says "but prefix notation!", all mainstream languages are prefix too everywhere except math. That is, frob(barify(foo, bar)) is prefix notation, and equivalent Lisp is achieved by just shifting the opening paren to the left of the operator name (and dropping commas, thanks to the uniform syntax): (frob (barify foo bar))
- cutler 9y agoAdoption of Elixir is no higher than Clojure. Slightly lower, I'd say. The bigger danger of loving Clojure is going back to working with OOP. Clojure can seriously damage your tolerance for OOP and in today's job market that's a real handicap.
- nnq 9y agoYou're trolling. You never "use your mind" to keep track of parentheses in any language - you use the editor's features for this, and read code structure by indentation like any sane human being does (also, it helps that I touch mostly Python ;) ...but for other languages you just configure your editor to reformat you code on every save or on linting). Everyone can get over "parenthesis madness" after configuring their editor properly and a few days of habit. Also, once you learn about "paredit mode" editing, if you like it, parens become a superpower, because you're not "typing code" anymore, you're just using your editor's shortcuts to edit the abstract syntax tree as a tree object that it rightfully is, not an ugly bucket of "code text"... If you're sincerely not trolling, then Lispers will be glad you don't join in and come and soil their codebases with miss-indented or unnecessarily over-nested because of bad structure code...
- sd34 9y agoI'm also happy that the industry isn't infected with the smugness of talentless coders called "lispers" who have done almost nothing but claim to be the most productive ever.
- nnq 9y agoI'm not a "lisper", just didn't dismiss Lisps because of parens :) I'd be happy to be able to do my coding in Go and Python but with a lisp syntax and some of the features enabled by it... I don't like it that most of the otherwise awesome programming languages had to be purposefully handicapped in terms of syntax and syntax-related features simply because they have to appeal to the mythical "Average Joe Coder" that dismisses things simply because they are "weird" or "can't keep track of them in his mind" (when the whole point of those features is to "outsource" certain things away from your mind and into the tools/language, and "cheat" by "stealing" some extra manifest-IQ points in the process and be able to write code "above you mind's limit"). There's tons of wasted effort writing "code intelligence" and "static analysis" and other related tools for languages with hostyle syntax. And tons of auto-refactor, auto-code-rewriting etc. tools that could exist and make work with legacy apps 1000x easier, if the languages we use would not have "features" to make the actual writing of such auto-coding tools prohibitively expensive...
- swlkr 9y agoYou should try parinfer for your editor, that should help with the parens
- maxpert 9y agoDownvotes for asking? :/
- chrisoakman 9y agoI'm sorry your original question has been downvoted. I think it's a perfectly reasonable experience report and question. I replied here: https://news.ycombinator.com/item?id=15527041 https://news.ycombinator.com/item?id=15527041
- yogthos 9y agoClojure code actually ends up having less parens, and others symbols than most languages. Here's an example comparison with Java https://labs.ig.com/lines-of-code-matter https://labs.ig.com/lines-of-code-matter >The only difference in readability is that the Java version has a lot more parentheses.
- klibertp 9y agoI wrote a blog post on the issue: https://klibert.pl/posts/tools_for_lisp_syntax.html https://klibert.pl/posts/tools_for_lisp_syntax.html I'm linking it because it has a couple of screenshots, which I think works better than just reading a description of how it should look like.
- chrisoakman 9y agoHi :) I feel your pain here and just wanted to let you know how common this is for programmers who initially try out Lisp for the first time. As others have alluded to, I promise this initial "parenthesis shock" goes away rather quickly as you read and write Lisp code. In my direct experience, I have hired junior developers straight out of a coding bootcamp who were able to pick up ClojureScript in their first week using Sublime Text with no editor extensions. In other words: you can definitely do this; it's not magic. I would strongly encourage you to check out Parinfer [1]. Parinfer makes indentation "significant" so you never have to worry about "closing the parens". Basically, if you can handle Python or CoffeeScript indentation, you can handle Lisp. There are no hotkeys to learn and it is available in most common editors today. For a first project I would recommend rewriting something you have already written and are familiar with. That way you can focus on just the language and not worry about the problem domain or "how to solve it". Just do a 1-to-1 port of something you've already done and compare how the two solutions are the same or different. I'm sorry you are being downvoted and being told to "just use emacs" or "use the REPL more". IMO, these are not helpful suggestions for someone new to the language. Good luck. You won't regret learning Clojure. One of the best things I have ever done for my career. [1]:https://shaunlebron.github.io/parinfer/ https://shaunlebron.github.io/parinfer/
- cutler 9y agoAn editor plugin which supports color-coded parens makes the parens problem disappear.
- mmargerum 9y agoI read 2 books, watched a training video, and watched a Rich h. Video if I needed inspiration, but it didn’t completely click until I just wrote a small app in it. Just build a script in it to learn. Break your code up into defs and tiny functions to understand what you are trying to do and then put it all together into a function. The only parallel I have professionally is when I try to write very complex sql