4 ms·
As a non-lisp programmer, what scares me away is the syntax. I don't think I could ever wrap my head around the (admittedly succinct) examples I see online, bec
by m0th87 17y ago
As a non-lisp programmer, what scares me away is the syntax. I don't think I could ever wrap my head around the (admittedly succinct) examples I see online, because it takes so much effort for me to figure out what's going on in even a few lines of code. Comparatively, I was able to understand what was going on in most python scripts before I knew the language. Is this something that just takes a while to get down? Or are some people just naturally prone to the syntax?
- PieSquared 17y agoThe reason this syntax scares you is simple: it's different. At the very root, Python syntax is nearly identical to Java, C, etc. The syntax of Haskell, OCaml, etc, is a deviation from that of Python, Java, etc, but not an incredibly significant one. Perhaps you may find that the syntax of these languages scares you but you think you could probably learn it after a bit of mind-wrangling. Lisp, on the other hand, is old. It was developed over 10 years before even C came to being! So the syntax is completely different, and requires you to actually learn it instead of just assuming that your knowledge of other programming languages will pull you through. In summary, it's not a fault in you. It's just that you are used to C-derived and influenced syntaxes, but not to Lisp; and the syntax of Lisp is different enough that you need to actually learn it. Here's a crash course: (f a b c) is the same as f(a,b,c). '(a b c) is kind of like ["a", "b", "c"]. '(1 2 3) is just like [1,2,3] (defun x (a b c ...) ...) defines a function x(a,b,c). (+ 1 2 3) is just like +(1,2,3) = 1 + 2 + 3 (setf x 5) is just like x = 5 '(a b ,c) is just like ["a", "b", c] if L is equal to '(1 2 3), then `(10 20 ,@L) is like [10, 20, 1, 2, 3] Now, to be honest, I just showed you nearly 100% of the 'syntax' Lisp has. The rest is already understanding the language (knowing how to def. functions, how to do loops, etc). By the way, what you might find interesting is that I once showed this to a friend of mine who knew nothing about programming. I showed him how to write a basic program in Java (with a few subroutines and a loop), then how to do it in Lisp. He exclaimed, "Argh! If I can do it like this, then why do I need all those fancy weird words like public and void and what not and braces and... eugh!" Sorry for that longish post, I hope you found it at least a bit informative. ;)
- tel 17y agoAlso: Until you start getting into the most complex (and powerful) aspects of lisp, the last two lines of syntax are rarely used. You get get a very long way without understanding them, but once you do lisp will become one of your favorite languages.
- m0th87 17y agoVery useful! I suppose I was wrong to say the syntax is confusing, because lisp is so syntactically minimalistic. But when I look through lisp code, I can't determine anything with respect to scope. Take, for example, the code in pg's A Plan for Spam: http://www.paulgraham.com/spam.html http://www.paulgraham.com/spam.html (let ((prod (apply #'* probs))) (/ prod (+ prod (apply #'* (mapcar #'(lambda (x) (- 1 x)) probs))))) It took me several minutes to weed through this code. Part of that is because I didn't know what, say, apply did, and had to look it up. That's not an issue because you have to do that when learning any new language. But I had to carefully inspect the source bottom-up and break it apart because I couldn't tell what the arguments are on each function call. An IDE that does block highlighting would help a lot, but even then it feels overwhelming, because it only helps me inspect the block that my mouse cursor is currently on. I guess what I'm saying is, I feel as if the syntactical constructs in other languages are necessary for me to be able to quickly parse a language.
- silentbicycle 17y agoLisp code is almost always written on multiple lines, with an editor that automatically indents everything. Code in a more familiar language (C?) would also look incomprehensible if ten lines were all smushed together on one. I let Emacs indent that, and it came out like so: (let ((prod (apply #'* probs))) (/ prod (+ prod (apply #'* (mapcar #'(lambda (x) (- 1 x)) probs))))) You still have to learn the idioms (it's a different language!), but it's not just a jumble of parenthesis. Prefix notation takes some getting used to for arithmetic, but that's neither here nor there. You probably have a bundle of idiosyncratic operator precedence rules memorized (quick, does 3*4+5 equal 27 or 17?), and Lisp doesn't use those, preferring to consistently use parenthetical nesting for everything. See also: http://img264.imageshack.us/img264/1397/lispnd7.png http://img264.imageshack.us/img264/1397/lispnd7.png
- lsb 17y agoEveryone says that the parens melt away, and it's true. However, using the language means the syntax, semantics, std lib, and community. So it's ultimately a very personal choice.
- megaduck 17y agoDisclaimer: I'm still a total lisp newbie, take all of this with a grain of salt. As I see it, the biggest hurdle to learning LISP isn't the syntax per se. Lisp's syntax is so simple, it's easily learned in a matter of minutes. The whole language basically boils down to lists and dotted pairs, and lists can be boiled down to dotted pairs if you squint at them the right way. The real obstacle for newcomers is that you have to completely rewire your brain. The vast majority of us were taught programming with BASIC, C, Java, or something similar. With those languages, programming is like following a recipe. Do step a, then do step b, etc. Moreover, imperative languages use a familiar "verb" and "noun" paradigm. That's natural and intuitive to most of us. With lisp, everything gets turned on its head. Everything happens at once. Code is data. There's no syntactic sugar because there's no syntax. You have to completely relearn how to look at computers and programming, and start over as a child. It's incredibly rewarding once you start having those "aha!" moments, but there is a decent-sized conceptual hurdle for people that are used to procedural programming languages. It seems that the majority of the lisp community suffers from the curse of knowledge. For experienced lisp people, lisp is so natural and intuitive that it's hard to understand why other people have such trouble with it. The OP is correct, lisp could really use more resources to bridge the gap between lispers and the outside world.
- viraptor 17y agoI see it a bit differently. I had to learn enough lisp to port some small application I needed to python. The result is basically this: I don't have any problem learning the syntax - I didn't have anything against ml-s, haskell and others either, even though I started with pascal. But what do I gain by using lisp seriously? I can do easy prototyping in python; safe, functional code in haskell; serious multiprocessing in erlang; fast tight-loops in c; nice oo in either python, c# or java, etc. etc. Why exactly should I spend more time with lisp? What does it help me achieve? Python right now is basically lisp + community from what I can see. Sytax doesn't even matter that much. If I need to rewire my brain to feel natural with a language that doesn't give me any new possibilities... then what's the point? I need those wires to understand haskell, sorry ;) I just need some balance - I can change the way I write my code, but tell me what do I get in exchange... and then tell me how is it better than doing the same in any other language.
- geocar 17y ago> Is this something that just takes a while to get down? Yes. You can practice in python reading this: [f,b,(),q,[1,7,q],[q],[q,r,6,1]] > Or are some people just naturally prone to the syntax? Lisp "code" is just a data structure (largely: nested lists). It's not the syntax that bothers you, it's dealing with complex data structures. You can see for yourself that they bother you no matter the actual syntax because the above form is python, and it bothers you as well. People who seem to pick up lisp quickly, simply have a better- rather, a more compatible background. If they lack your particular impetus, they might already be comfortable with complex data structures. Yes: People can be predisposed to "getting" lisp, but I doubt it is a genetic thing. > it takes so much effort for me to figure out what's going on There's nothing going on. In python, there's an invisible stratum between the code you write and the code the computer executes. You don't usually see the substrate, and if you aren't paying real close attention, you might often forget that it is there. Lisp simply lacks that invisible layer. If you can't get past the complex data structures bit, there are other languages that lack that stratum that use very simple data structures: Forth, for example.