9 ms·
Why Lisp? 3 answers
- rayiner 14y agoThree answers are all the same: macros, macros, macros.
- nocipher 14y agoI agree with this answer, but I suspect that this is also why Lisp isn't often a first choice. Meta-programming doesn't figure into language choice discussions as often as it probably should. I distinctly recall wishing for macros in Java a few months ago while working on an Android project -- so much boiler plate for doing so little. I came to the realization that Java uses XML augmented libraries so much simply because Java boilerplate is such a pain to write. It's often easier to build a mini-language on top of XML and use Java to parse and compile it than it is to write the equivalent Java code. I think that alone says something about the efficacy of Java and the benefit of using a language with a more malleable AST.
- duaneb 14y agoI'm usually sceptical about "Why Lisp?" "Practical Common Lisp" offers the confident (and subjective) "You'll get more done, faster, using it than you would using pretty much any other language." Well, this is much better.
- stmartin 14y agoHow is this so much different than using any other language, C or Java or Perl or whatever - with a good set of middleware libraries? I understand the benefit of having the ultimate DSL - if I can call Lisp that due to it's 'fluid' redefining nature, but as for productivity - I think it's a little overzealous to claim huge productivity boosts when comparing to other langs w/good middleware support who've been around for decades...
- hvs 14y agoThese are terrible answers to the question "Why Lisp?" (to which the most obvious answer would be "For what?"). 1) Good ideas? Yes, it did, but many modern languages implement them so it is no longer a reason to use Lisp. Macros? There are numerous arguments on both sides about whether those are good or bad. Needless to say, not enough to justify using Lisp. 2) Your "extension to the language" is my "wtf is this developer doing here?" Consistent syntax is part of what makes a language intelligible to many different people. I don't want to be a human parser to understand code. 3) Thrust/weight... ?. OK, I think your point is that there is little syntax to understand. Unfortunately, that means that context needs to be parsed by the developer because there are few "road signs" that tell me what is going on without reading the whole chunk of code in detail. Finally, I'm not sure what this is in response to (other than it being the eternal question that burns in the hearts of all men) but if it is an argument for using Lisp on a project, it would be better directed at what Lisp has that makes it good for production work in a modern environment. However, in that way, I don't think it is much better than many of the other languages today.
- rayiner 14y agoRe: "for what" I would say that the best answer would be: for rapid development of technically complex programs with small, highly-skilled teams. Re: 1) Many modern languages do implement some Lisp features, but none do so as well as Lisp. I have yet to see a language that mixes functional programming, an elegant and intuitive standard library, meta-programming, and high performance native code incremental compilation in one development environment. E.g. Javascript is full of bizarre quirks and bad semantics, and its REPLs aren't up to snuff yet, even though it has native-code compilers that are up to snuff. Nothing does meta-programming as well as Lisp. LINQ, Caml4p, etc, are ugly hacks compared to Lisp macros which are baked into the compilation pipeline by design. Re: 2) I think you are mistaken in assuming that programmers using other languages don't extend the language. They do, they just do it with external, ad-hoc tools. A great example is LLVM's tblgen utility, which generates native assembler backends from table descriptions. It has its own grammar, own parser, own set of bugs. You can do this stuff in Lisp within the language. When I was still learning the language, I put together a table-driven assembler for x86-64 in about two weeks (http://code.google.com/p/amd64-asm/source/browse/#svn%2Ftrunk http://code.google.com/p/amd64-asm/source/browse/#svn%2Ftrun...). It uses macros to take instruction descriptions and generate encoding functions which are then compiled to native code by the Lisp compiler. It's simple, it uses the parser built into the language, you can't ever forget to run the external tool, and it's totally integrated into the development environment. One hotkey sequence expands the macro and shows you the result right in your editor. An error in a macro is debuggable with the integrated debugger just like any other code (compare to C++ templates, which are basically impossible to debug except through trial and error). Literally no other metaprogramming feature comes close to Emacs+SLIME+SBCL. Re: 3) Lisp doesn't have "less context." It just uses words for context rather than syntax. In C, you see curly braces and you know you have a block. In Lisp, you see the word "progn" and you know you have a block. Lisp is, to a degree, a language for people who think verbally rather than symbolically. The signals are all there--it's just that the signals are words. Lisp is the only language I've ever used (to be fair, I haven't really used Haskell) where I don't feel like the language/development environment is the bottleneck. It's the only one where I don't lose my train of thought trying to remember to remember the idiosyncratic way someone ordered the parameters to an API call, or because I'm stuck writing a few dozen lines of boiler-plate. It and Python are the only language I've used where API's have sensible defaults (Java is absolutely terrible for this) and I'd dare call the standard library "tastefully designed."
- deleted 14y ago[deleted]
- klrr 14y agoLISP is great for learning, here's a tip though. If SICP is too advanced, start with Simply Scheme or The Little Schemer instead.
- muraiki 14y agoAnother good one, although Scheme oriented (like SICP) is How To Design Programs: http://www.htdp.org/ http://www.htdp.org/ The second edition is a work in progress, but it gets you going pretty quickly with graphical programs, so it's a bit less cerebral (and arguably more interesting for many beginning programmers): http://www.ccs.neu.edu/home/matthias/HtDP2e/ http://www.ccs.neu.edu/home/matthias/HtDP2e/
- brudgers 14y ago"Sadly, something essentially killed lisp innovation around the time Common Lisp got standardized" I think it was timing, more than anything else. The movement to create Common Lisp came right on the cusp of several important shifts in computing. The first was from specialized hardware to standardized platforms. Lisp bet heavily on the former as embodied in Lisp machines at the very time that ISA and x86 machines proliferated. The second shift was from command lines to GUI's and the Common Lisp standard lacks facilities for windows and other GUI elements. There is no equivalent of Swing in Common Lisp. At the time it was standardized, Common Lisp just missed the explosion of the commercial internet and the distribution advantages it afforded Java just a few years later. Finally, the way in which the Lisp community tended (and still tends) to shun Microsoft Windows, probably played an important role in limiting its general adoption. After the demise of Lisp machines, the remaining segment of the Lisp community tended toward FOSS partisanship - somewhat unsurprising since RMS emerged from the Lisp community and it was closed source Lisp code which first led him to action. In short, Lisp was both unlucky and placed bad bets relative to the current state of affairs. The ultimate effect of a bias toward FOSS remains undetermined.
- betterunix 14y agoIt was not just "timing" that killed Lisp (if one can even say that Lisp is dead -- I use it in my day-to-day work, and I am not alone). While the world's Lisp hackers were working on lofty AI dreams, the world's Unix hackers were spreading C to every college, university, and business out there. Had an open, portable, low-end OS like Unix been written in Lisp, I suspect the programming world would be a much different place today.
- deleted 14y ago[deleted]
- pjmlp 14y agoThat is what I tend to think. Although this is a bit off-topic rant, I really enjoyed using Turbo Pascal, before C took over in the PC world as well. So thanks to UNIX/C being spread the way they were, better languages got a hard time being accepted in the mainstream. And we are still paying with security exploits C's success. At least static analysis of C code seems to be becoming a common trend...
- xradionut 14y agoWhy Lisp? It's fun to play with when I need a break from work or projects. In the real world work environment I need to write mundane code maintainable by coworkers and clients, so it's not there. In my hobby, C and assembly rule the tight memory spaces of embedded hardware, so Lisp exists in a shared dream-state with Smalltalk and Oberon...
- mratzloff 14y agoFor personal use, sure. For anything else, language choice requires bottom-up campaigning or top-down mandates--Lisp never even enters the conversation, at least in any serious way. Language choice is also heavily dependent on mature third-party libraries, which are in abundance in many languages but not as much with Lisp dialects (unfortunately). Ruby and JavaScript have adopted enough Lisp concepts and in a lot of organizations enjoy enough support that pushing for real Lisp is a touch quixotic.
- kyllo 14y agoI get the impression that Clojure is at least entering the conversation in some places. Some companies that need concurrency control capabilities that they find difficult to implement in Java are starting to use Clojure, or at least considering using Clojure to make certain Java business applications threadsafe. The fact that Clojure runs on the JVM and can be called from inside a Java application makes this easy to do, but in a bottom-up campaigning situation the hard part is convincing management to sign off on your use of the language as an "approved tool."
- mattknox 14y agoWe use Clojure at twitter and I believe that google supports CL as part of the after-effects of buying ITA. At the time I wrote this, clojure didn't exist and ITA was not particularly well-known.
- mratzloff 14y agoYes, Clojure is the exception. From an institutional standpoint, its support derives entirely from the fact that it runs on the JVM (as you pointed out) and can talk to both the company's existing Java code and the vast pool of Java libraries out there. The lesson here is that it was incredibly smart for adoption to target the JVM and CLR. The JVM in particular will almost certainly outlive Java itself as a primary development language.
- jfb 14y agoRuby and JavaScript have adopted enough Lisp concepts and in a lot of organizations enjoy enough support that pushing for real Lisp is a touch quixotic. Alternately, JS and Ruby may have served to loosen people's resistance to useful and interesting language features that are better implemented in, say, CL. Writing either makes me sad, in an "uncanny valley" sort of way.
- mattknox 14y agoNote to any potential readers: I was barely a vertebrate when I wrote this (edit: that must have been 6-8 years ago). I did so because I had selected TinyScheme for a project that I was doing at work and a bunch of people who had never heard of scheme or lisp wanted to know why. I briefly got tired of talking about it (which is rather unusual, to those who know me), and wrote this. I still think that lisp is a great language to learn (although forth is even lighter-weight and about equally powerful), and like clojure a lot for practical work nowadays.
- nnq 14y ago> you can even make your own syntactic extensions, so if infix math is necessary, then you can have it ...in what Lisp and how can one do this?
- betterunix 14y agoIn pretty much any Lisp by using macros. It is a 10 minute exercise in writing a simple parser, or you can just use one of the parser generators out there (plenty for Common Lisp, probably plenty for other Lisps).
- serichsen 14y agoDefine a function that transforms an infix form to a prefix form. Write a reader macro that understands some special character to mean that the following form is an infix form and uses the function above to transform it. Done.
- fogus 14y agoYou could do it in ~15 lines with Clojure: http://www.fogus.me/fun/unfix/infix-src.html http://www.fogus.me/fun/unfix/infix-src.html I suspect most Lisps would require about the same.
- fusiongyro 14y agoAny Lisp, but it turns out to reveal a bunch of Lisp warts. The most obvious one being that no Lisp out there ships with a built-in macro to do this. The subtle truth, though, is that most people who use Lisp start out wanting this and then either give up before they become proficient enough to implement it, or else get acclimated to prefix math and once they are proficient, they don't care anymore. If you were to set out to do this, the first thing you'd have to accept is that the macro is going to look a little weird. For instance: (infixmath 2 + 3 * 4 * (2 + 1)) You're going to want to put spaces between all the terms, every time, because you'd rather have separate atoms for numbers and functions. The next problem you're going to run into is that Lisp doesn't ship with any context-free grammar support akin to Parsec or Yacc. This is the corollary to the point above, that once Lispers become proficient enough to do this they don't want to anymore. Once you're fully enamored with prefix notation, you never find yourself wishing for the kinds of grammar that necessitate this kind of work. (This has a lot to do with why most Lispers hate loop and format too). In other words, you'll be writing your own recursive descent parser from scratch. Once you've written your recursive descent parser to handle infix math, you'll face the next challenge: what to do with the parse tree. The simplest thing to do is just evaluate it. If you were really clever you might be building a Lisp prefix expression as you went and you can just let Lisp evaluate that directly with eval. A part of you will wonder if you should instead generate a compiled function, but then you have to capture the variables properly and it will be a lot more work, but it could become more efficient, since the Lisp compiler would have access to that information and could do better things with it... Anyway, my point is that this is sort of a will-o-the-wisp or mermaid example, because it's intended to capture the imaginations of non-Lispers, but actual Lispers have never actually gotten serious enough about it to make a robust implementation and ship it with the system, because the mindset that values infix math is incompatible with the mindset that produces good Lisp programmers.
- deleted 14y ago[deleted]
- laureny 14y agoThese must have been awesome answers in the late 80's.
- tubbo 14y agoWhy Lisp? 1.) Because you need it. _EOF_
- bonch 14y agoLisp code can be hard to maintain because programmers use it to create their own little worlds.
- pdonis 14y agoI have used Lisp as a hobbyist but always find myself coming back to the same issue: not every data structure is a list. http://blog.peterdonis.com/rants/why-python-not-lisp.html http://blog.peterdonis.com/rants/why-python-not-lisp.html Another way to put it, as I did at the end of that post, is: why should I have to reprogram my brain to fit the language?
- lispm 14y agoIf that's a hurdle for you, then you should not use Lisp. Lesson No. 1: Extend the language. Lesson No. 2: develop taste how to best extend the language. Here are the five missing lines which made you not use Lisp: (defun init-hash-table (data &key (test #'eql)) (let ((hash-table (make-hash-table :test test))) (loop for (key value) in data do (setf (gethash key hash-table) value)) hash-table)) 'why should I have to reprogram my brain to fit the language' That's wrong. Lisp is for those who want to reprogram the language to enhance the brain. If you feel uncomfortable with that mode, then Lisp is not for you.
- pdonis 14y agoHere are the five missing lines which made you not use Lisp Yes, I know the init-hash-table function is easy to write. I didn't mean to imply that the function was complicated, or that writing it was a "hurdle", or that not having the function was what made me not use Lisp. I wasn't talking about one particular function; I was talking about the general fact that, for the programs that I've been writing, the advantages of Lisp did not, for me, outweigh the disadvantages. Your mileage may vary, of course. Lisp is for those who want to reprogram the language to enhance the brain. This is a valid point. I try to use Python this way as well, and so far I haven't run up against a specific case where its limitations compared to Lisp were enough to push me over the edge. If I were to change my mind at some point, it would be because of some way that I wanted to reprogram Python but couldn't.
- kls 14y agoThat's wrong. Lisp is for those who want to reprogram the language to enhance the brain. If you feel uncomfortable with that mode, then Lisp is not for you. I don't know if I would go so far as to say the poster is wrong for feeling that way, but you are correct, Lisp is fundamentally different, and one should really only embark on learning it, if they want to learn how to do something fundamentally different. If one has the mindset of "why should I change" then they are probably going to miss the profound ah-ha many of us got when leaning a Lisp. They are not wrong for feeling that way, but a Lisp is definitely a bad choice for them and will only frustrate them.
- jobeirne 14y ago"To an unusual degree, someone who codes in lisp is on nearly equal footing with the implementer." Working with good developers => kinda cool. Working with average developers => oh my god why.
- dbecker 14y agoI was excited about Lisp for a while, primarily based on all the claims of increased productivity. I started going to Lisp and Clojure meetups while learning, and I was struck how much LESS productive the supposed gurus at the meetups were in Lisp than I am in Python. Maybe that reflects on the language. Maybe these people were posers. But the claims I hear seemed inconsistent with what I saw.
- rayiner 14y agoHow much does your problem domain leverage Python's available standard library? I'm pretty familiar with both, and the former is what I use to write stuff when I don't have a library available that does the work for me. The latter is what I use when I don't really have to do much work to leverage something someone else has already built.
- dbecker 14y agoPersonally, my programming involves heavy use of the scientific computing libraries. But my comparison was for general programming that doesn't use these libraries, and which don't rely especially heavily on the standard library.
- lispm 14y agoThere were a lot of good ideas explored in Lisp - but not always they were first developed in Lisp (for example OOP came from Simula and Smalltalk to Lisp and merged their with Lisp approaches). Many ideas developed in Lisp have not even been reused now. It is buried in computer science reports from 60-90 (which no one reads anymore) and code which has been lost (or is not accessible). Example: Lisp 1.5 from the 60s had a bitmap used for marking objects during GC - Ruby 2.0 just now implemented this thing. One could have read old Lisp implementations from the last 50 years - but this is not how people work. Few people study old stuff and harvest it. The flexibility of Lisp to change the language in multiple dimensions is still valid. There are few languages which provide it in a seamless and built-in way. That's why some people still use Lisp. It's also a thing which limits Lisp: it is more difficult to understand and goes against the coding standards in 'enterprise software development'.
- javajosh 14y agoJavaScript is enough of a Lisp, and it runs everywhere and is attached to a (more-or-less) standard UI environment that is getting increasingly powerful. And if you really like Lisp syntax, and believe in enforced immutability, there's always ClojureScript.
- ianstallings 14y agoThe only reason this site loves LISP is because PG said it was special. What a joke. Sorry to be terse but this whole place is either insane or plain stupid when it goes on about LISP.