You are not logged in.

#1 2009-01-05 09:47:43

ihavenoname
Member
Registered: 2006-01-09
Posts: 198

Lisp: What is it good for?

I've been reading a lot about Lisp lately. By that I mean a lot of people saying how great Lisp is and how it supports things that no other language does (read: it's the most powerful language as defined by paul graham).

Mainly when a discussion erupts it goes:
a: Lisp is the most powerful language ever. Lisp macros are <insert adjective meaning the they are unparalleled followed by a small explanation>
b: Well you can do similar things with ruby macros and lambda functions <or c++ templates etc.>
a: You won't understand Lisp's power unless you actually get to know it.


which leaves the rest of us going..huh??? If something like Lisp macros is the main reason why Lisp is great and I don't know exactly what the scope is then the question then follows, why should I learn it.

*Basically what I am wanting to know is this: is lisp worth my time?
I mean for  someone who wants to program things that are useful and not JUST theoretical things.
Don't get me wrong I'm sure it's a great language. I'm just wondering why is "better" than something like C++ or ruby for those people who keep advocating it. An important aspect of this is if it is really that powerful then how come it hasn't caught on.

* I mean something like java is invented and it catches on like wildfire.
* (but a lot of people say java is not really a good language, maybe that is something else I'd like to hear about).

*Also does Lisp contain all the necessary/useful libraries etc. Like a gui toolkit, a network interface, threading, sql etc.

If not then doesn't having to "re-implement" such features actually translate to more work than using C++ and working around it's "deficiencies" compared to Lisp?

*Speaking of C++ what functionality do Lisp macros have the C++ templates not have, and are those functions used often?

I have placed * in front of the issues I'm most interested in hearing about.

For reference as to some of the things I have been hearing about Lisp here is a link to the site of one of the biggest lisp advocates I've read from (he makes several good points especially in the areas where he discusses how lisp helped his start-up succeed).
http://www.paulgraham.com/lisp.html


Thanks for the input.
Disclaimer:
This is mostly posted to hear some of the peoples ideas. I post here because I consider the Arch users/forum to contain a larger percentage of more "hard core" developers/"hackers" if you will as opposed to say an OpenSuse Forum which is like to have a higher percentage of average users with little computer knowledge.


In this land of the pain the sane lose not knowing they were part of the game.

~LP

Offline

#2 2009-01-05 10:25:13

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

Re: Lisp: What is it good for?

Disclaimer: I don't know how to write Lisp. I never came around to actually learn it, but I get along with functional languages and can mostly read it. (In other words: I'm not the best source about macros and language specific features.)

Adoption of Lisp has one big problem: It's relatively hard to grasp the concepts at first. It's like learning to program for a second time, because you have to think differently and need a certain higher understanding of some abstract concepts, which don't exist in conventional languages.

Example for a conventional program:

int factorial(int n) {
    int fact = 1;
    for (int i=1; i <= n;i++) {
        fact *= i;
    }
    return fact;
}

Example for a functional program:

F(0) = 1
F(n) = n * F(n-1)

Now take Java: It's similar to C++, with which most programmers were (moderately) familiar. I.e. it's little learning effort and you don't need a math degree to write programs that work. Heck, I can read Java and I've never learned it, it has got the familiar syntax and I would feel right at home writing code without having to worry about freeing memory, have a nice library, ... .

Anyway: Learning different programming paradigms is worth your time. Once you learned about side effects, see elegant solutions to problems in functional languages, you'll become a better programmer in any language.

Learning Lisp on the other hand is a different thing: The power of Lisp is in creating "domain specific languages" and programs which would take many thousands of lines in conventional languages, become small and seem easier. Lisp is a general purpose language - you use it to create a tool to solve your problem, not to solve the problem itself. This is what it makes so powerful.

My take: Learn Scheme (a small Lisp dialect) and play with it. Also get to know Haskell and Erlang. And then use the right tool for the right job. You're familiar with Java? Have a look at Scala, too.

Offline

#3 2009-01-05 11:36:04

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: Lisp: What is it good for?

First, as wuischke said, learning a new paradigm helps you in whatever language you choose to code.

Second, I don't know C++ templates, but it seems to me that they allow you to use the same code to different data types (or classes). Macros can do a lot more than that.

A book that I recommend to start learning lisp is Practical Common Lisp. In one of the first lessons, A simple database, it shows a macro that searches the database.

(defmacro where (&rest clauses)
  `#'(lambda (cd) (and ,@(make-comparisons-list clauses))))

I know it looks cryptic, but this two lines allows you to search the database for a specific album using any information stored in the database.

(where :artist "Bob Dylan")
(where :artist "Beatles" :album "Abbey Road")
(where :ripped t)

You could do this using polimorphism, of course, but macros allow you to do much more in less time. Macros can be used to create flow control structures (like while, for, if), too.

At last, I think that what you really learn with lisp is to code bottom up. As the author of On Lisp (great book, also) says, lisp is a language that when you think "I wish lisp had an operator that would do this", you can write it and it'll be as if it was part of the language. So you build your app from bottom, from the simplest functions, to the top, the real user interface.

Last edited by andre.ramaciotti (2009-01-05 11:37:10)


(lambda ())

Offline

#4 2009-01-05 17:34:11

ihavenoname
Member
Registered: 2006-01-09
Posts: 198

Re: Lisp: What is it good for?

thank you. That is all pretty good info. What are some if the main problems with lisp though? Are there any situations where you would want to use C++ instead of lisp??


In this land of the pain the sane lose not knowing they were part of the game.

~LP

Offline

#5 2009-01-05 23:12:58

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Lisp: What is it good for?

ihavenoname wrote:

*Basically what I am wanting to know is this: is lisp worth my time?
I mean for  someone who wants to program things that are useful and not JUST theoretical things.

Yes, moreso than any other language.

Don't get me wrong I'm sure it's a great language. I'm just wondering why is "better" than something like C++ or ruby for those people who keep advocating it. An important aspect of this is if it is really that powerful then how come it hasn't caught on.

It did catch on. Lisp was (relatively) huge back in the AI days. Then when AI crashed, Lisp went down with it.

*Also does Lisp contain all the necessary/useful libraries etc. Like a gui toolkit, a network interface, threading, sql etc.

If not then doesn't having to "re-implement" such features actually translate to more work than using C++ and working around it's "deficiencies" compared to Lisp?

Keep in mind that there are currently many dialects of Lisp and many implementations of each. Historically there have been many more, but the currently active ones are Common Lisp, Scheme, and Clojure. CL and Scheme have libraries for the things you mention, and can also load C code. Clojure runs on the JVM and has access to all Java's libraries.

Lisp's library situation isn't ideal overall though. Sometimes it is necessary to write a library or make bindings to some C library, and for small programs this can be more work than using a C++ library and writing your program in C++. For large programs I can't imagine that Lisp wouldn't come out ahead.

*Speaking of C++ what functionality do Lisp macros have the C++ templates not have, and are those functions used often?

Everything and anything. Templates provide the ability to plug in a few type names and numbers into a predetermined block of code. Lisp macros are passed the entire text of their arguments, freely rearrange it with regular Lisp code, and spit out code that is probably but not necessary based on the arguments. It's not a question of what they provide, but of what you feel is necessary to do with them. Generally they are used for implementing new iteration constructs (DOTIMES, DOLIST), domain-specific languages (in the "standard library" yet more iteration constructs: DO, LOOP), variable binding constructs (Gary King's BIND macro), and in general abstracting away something you'd rather not type multiple times. Most Lisp programs or libraries include at least a few macros. I believe Emacs Lisp code uses quite a few macros where programs in other dialects might use functional programming. Scheme code is likely to use fewer macros and more FP, because Scheme and Schemers are obsessed with that kind of thing. Common Lisp is somewhere in the middle.

Lisp's main strength is that it is a multiparadigm language with fully programmable semantics. There's a meme going around that it's a functional language, but it's not entirely accurate. While Lisp *does* include first-class functions, higher-order functions, closures, anonymous functions, and so on, it also includes at least five iteration constructs, its own version of goto, an object system complete with multiple inheritance and multiple dispatch, and anything else you're interested in adding. Its macros mean that when you've got code that's awkward to write, you can abstract it away once and for all. And on top of that, development in Lisp is interactive. You can compile functions as you go and test them from the prompt without writing scaffolding and such.

ihavenoname wrote:

What are some if the main problems with lisp though?

Lisp's problems fall into two categories: support issues and image problems.

While C programs, for example, are compiled then distributed as binaries, Lisp programs generally require a working Lisp implementation to be on the end-user's computer. This is becuase every Lisp program has full access to the compiler, and can compile new functions into itself at runtime. Good for programming, but awkward for distribution (OTOH, people install 350 MB of GHC to run Xmonad. A Lisp is more like 3 MB – 30 MB). And since your program needs to work on whatever Lisp the user has, programs are generally distributed as source. This is a problem for some people. Also people need to have a Lisp that runs on their machine, which may or may not be a problem.

As for image problems: It's funny looking to C programmers. The library situation is not amazing. Lisp implementations have historically been the OS, so they're still a little insular and don't yet integrate as closely as one might like with the OS they're running on. A lot of programmers have no contact with Lisp except for a semester or a couple of weeks writing strange recursive programs, and come away with a poor impression of it.

And of course a given dialect of Lisp has its own array of design problems, like any language. I would say that they are rarely severe, partly because of good design and partly because Lisp is so programmable that you aren't stuck with something you hate like you are in C++.

Are there any situations where you would want to use C++ instead of lisp??

Me? No, none at all. If I were programming close to the metal I might use C instead, but never C++. If my C program had to do something interesting, I'd probably embed a Lisp in it.

Last edited by pauldonnelly (2009-01-05 23:29:44)

Offline

#6 2009-01-05 23:27:34

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: Lisp: What is it good for?

Hijacking a little bit this topic, is there a way to compile common lisp code to machine code? I don't remember being able to do it with any common lisp implementation on arch's repositories. If there isn't for common lisp, is there to scheme?


(lambda ())

Offline

#7 2009-01-05 23:30:08

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Lisp: What is it good for?

andre.ramaciotti wrote:

Hijacking a little bit this topic, is there a way to compile common lisp code to machine code? I don't remember being able to do it with any common lisp implementation on arch's repositories. If there isn't for common lisp, is there to scheme?

SBCL and CMUCL compile to native code.

Last edited by pauldonnelly (2009-01-05 23:33:17)

Offline

#8 2009-01-06 00:40:49

quetzyg
Member
From: /home/quetzyg
Registered: 2006-08-03
Posts: 129

Re: Lisp: What is it good for?

Take a look at this OSnews article.


ZzZz...

Offline

#9 2009-01-06 03:09:48

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Lisp: What is it good for?

quetzyg wrote:

Take a look at this OSnews article.

Ugh. There's a reason I didn't list newLISP up there with CL, Scheme, and Clojure. The only remotely good thing it does is the implicit indexing. Although I must admit, trying to convince people that using reference counting instead of a real GC is a good thing takes some balls.

Offline

#10 2009-01-06 05:07:29

dsr
Member
Registered: 2008-05-31
Posts: 187

Re: Lisp: What is it good for?

pauldonnelly, how does Common Lisp compare to Scheme? I've heard that CL has a better library (no clue what that means though) and that Scheme is better suited for functional programming because the compiler is guaranteed to implement tail recursion, among other things. Is that accurate?

I can see the appeal of CL, but as for Scheme, I would assume intuitively that a pure functional programming language (as in one in which all functions are referentially transparent) like Haskell or a functional language where side effects can be isolated fairly easily like OCaml would be preferable to Scheme when functional programming is your main concern. So when is Scheme advantageous, in comparison both to languages like Haskell, OCaml, and Erlang and to CL?

Offline

#11 2009-01-06 05:40:19

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Lisp: What is it good for?

dsr wrote:

pauldonnelly, how does Common Lisp compare to Scheme? I've heard that CL has a better library (no clue what that means though) and that Scheme is better suited for functional programming because the compiler is guaranteed to implement tail recursion, among other things. Is that accurate?

To some degree.

Scheme has come a long way towards being an industrial-strength programming language in recent years, and that includes a large number of libraries. Perhaps what you heard was that CL has a better standard library, meaning functions that are guaranteed to be in a CL implementation. That's mostly true (I have not counted), although serious Scheme implementations come with quite a few extensions. For example, I don't belive that any R*RS has yet included CL-style macros, preferring so-called "hygienic" alternatives, but at least one Scheme has implemented CL macros anyway, since they're darn useful and easy to use.

Scheme has three properties that make it pretty good for functional programming: it has a single namespace for functions and variables (it's a Lisp-1; CL is a Lisp-2), meaning that any local variable can be called as a function, it guarantees tail call optimization (TCO), and functions can be passed as parameters with no extra syntax.

Scheme:
(define (foo) 3) ; This function returns 3.
(define (call-fun fun) (fun))
(call-fun foo) => 3

CL:
(defun foo () 3)
(defun call-fun (fun) (funcall fun))
(call-fun #'foo)

As you can see, CL requires a few more words to do the same thing, although this is mitigated by FLET, which defines local functions which can be called regularly. If you do this a lot, it may be significant to you. The other side of the coin is that in CL I don't have to worry about defining variables with the same name as my functions, but in Scheme I do. Personally, I prefer CL's position, but opinions vary. Some people think that Lisp-1s are "cleaner" and like that a lot. Although CL doesn't mandate TCO, most Lisps offer it, although it may need to be specifically enabled. If recursion is your thing, you can find a CL that will let you write your iteration recursively. Personally, I'd just as soon use DO or LOOP.

At this point, I'd say that CL vs. Scheme is largely a matter of taste, with Clojure looking pretty exciting for a number of reasons. I feel that CL sticks closer to what has historically been the "Lisp Way": good multi-paradigm support and macros. Scheme has a functional programming world view that it's pushing, to my perception. Functional programming is great, but I'd prefer to keep it as one tool in the bag.

dsr wrote:

I can see the appeal of CL, but as for Scheme, I would assume intuitively that a pure functional programming language (as in one in which all functions are referentially transparent) like Haskell or a functional language where side effects can be isolated fairly easily like OCaml would be preferable to Scheme when functional programming is your main concern. So when is Scheme advantageous, in comparison both to languages like Haskell, OCaml, and Erlang and to CL?

Scheme allows easy isolation of side-effects. Pattern matching is really what I would say a language needs to be serious about functional programming as a way of life, since it's crucial to elegantly writing recursion, and Scheme does not yet include it in the standard, AFAIK. I feel much the same as you: while Lisp appeals to me, I prefer CL over Scheme, and for heavy FP I would look at another language.

Offline

#12 2009-01-06 06:15:09

dsr
Member
Registered: 2008-05-31
Posts: 187

Re: Lisp: What is it good for?

Thanks for the informative (and commendably unbiased) explanation. If I do get around to learning a Lisp dialect, CL sounds like my best bet  (although I do have to take another look at Clojure even though it seems to push the FP paradigm a la Scheme). I think my first priority, though, will be to learn a functional programming language (I'm leaning towards Haskell.

Offline

#13 2009-01-06 07:55:05

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

Re: Lisp: What is it good for?

pauldonnelly, thanks a lot for your explanations. This made things clearer for me.

If you permit a personal question: From your comments in the forums I consider you very knowledgable about many programming topics, may I assume this is your occupation? Yesterday I spoke with my professor about Lisp and functional programming languages and he considered them only to be widely used in few rare research positions. Do you work with Lisp? Do you believe there's a demand for functional/Lisp programmers?

Offline

#14 2009-01-07 06:04:57

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Lisp: What is it good for?

wuischke wrote:

pauldonnelly, thanks a lot for your explanations. This made things clearer for me.

I'm glad I could help.

wuischke wrote:

If you permit a personal question: From your comments in the forums I consider you very knowledgable about many programming topics, may I assume this is your occupation? Yesterday I spoke with my professor about Lisp and functional programming languages and he considered them only to be widely used in few rare research positions. Do you work with Lisp? Do you believe there's a demand for functional/Lisp programmers?

I'm actually only a student at the moment, and between schools at that. Still around semester or two away from my degree, because I switched my major to CS after a few years doing audio. My current plans are indeed to be employed as a programmer in the near future. I engage in more self-study than most of my fellow students, so that might explain any competence I display. Still, I try not to overstep myself and pretend to know more than I do.

I know there is a demand for Lisp programmers, since I see job postings on the Internet occasionally. It has been and still is being used in lots of fields, but the reality is that for most Lispers, a Lisp job is just a dream unless they start their own company. Although that may be the way to go anyway if you want the big money. wink As for functional languages in general, the situation is much the same. Although with all the buzz about F#, Haskell, Erlang, and the like, I see a future for FP where people don't say, "Why would you want to do that in a functional language?" I've been asked that before.

I'd say your prof gives an accurate position of Lisp's place in the world. If you want an opportunity to make money with Lisp, you will probably have to manufacture that opportunity for yourself. If you want to get hired by a company, work on their existing products with a team, then go home and not think about programming until 9:30 the next morning after you've made it to your desk and checked your voice mail, Lisp has nothing to offer you. OTOH if you do personal projects or have a passion for learning more about programming, Lisp can be an education and a great platform to work on.

This is as I understand it from my limited perspective, of course.

Offline

#15 2009-01-07 06:06:29

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Lisp: What is it good for?

dsr wrote:

I'm leaning towards Haskell.

You'd do well to learn your Haskell before Lisp spoils you with its lack of syntax. tongue

Offline

#16 2009-01-07 13:19:52

scrawler
Member
Registered: 2005-06-07
Posts: 318

Re: Lisp: What is it good for?

You might enjoy looking at a little language called newlisp.  osnews has a decent article about it  here.

Offline

#17 2009-01-07 21:28:10

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

Re: Lisp: What is it good for?

Thanks for taking the time to answer me, pauldonnelly, your "limited perspective" helps to broaden mine.

Another language if you learn for fun (as I do): factor

Although coding in a mainstream language will feel dull afterwards. wink

Offline

#18 2009-01-08 22:10:52

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Lisp: What is it good for?

wuischke wrote:

Thanks for taking the time to answer me, pauldonnelly, your "limited perspective" helps to broaden mine.

Another language if you learn for fun (as I do): factor

Yeah, I'm very interested in Factor. I'm not doing much with it until the docs on its GUI setup are clearer though. Concatenative languages are looking good to me right now.

Offline

Board footer

Powered by FluxBB