• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Why lisp?

## Recommended Posts

Diodor    517
quote:
Prolog seems to be a better "other" langauge, frankly.

Paul Graham has a Prolog language embedded in Lisp written in 180 lines in his "On Lisp" book. This should be the kind of example you''re looking for.

##### Share on other sites
Diodor    517
Another small example of sublanguage built on Lisp: the loop construct. This is available in Lisp, but it is coded as a set of macros - as an extension language: http://www.ai.sri.com/~pkarp/loop.html

##### Share on other sites
Extrarius    1412
I think a good example is the new object system created in the book ANSI Common Lisp. You might think its no big deal, since C++ has an object system too, but I think its nice that in Lisp you can make your own if you want. I don''t particularly like C++''s object system or CLOS, so if I were to ever become a serious lisp programmer one of the first things I''d probably do is make my own object system with the features I want and lacking the ones I don''t.

##### Share on other sites
Guest Anonymous Poster
quote:
Original post by Vlion
Interesting.
I still don''t percieve any practical advantage Lisp has over <good OO language>.
Sigh. The point is that you won''t find the set of features described in this thread from any other single language except Lisp. If you don''t believe those features have any practical advantage, that only shows your ignorance regarding those features. You''re like a C++ newbie who can''t yet use classes and wonders what use they have over the convenient C structs. If you''re not interested in researching a bit on the topics, nobody will be able to convince you. We''ve already presented a bunch of stuff Lisp can do that most other languages can''t, yet you keep on insisting that Lisp has no practical advantage. Is that really logical at all? I mean, what would make Lisp have a practical advantage in your eyes?

##### Share on other sites
Dobbs    164
quote:
Original post by Krippy2k
Lisp lacks much of the powerful functionality provided by the STL...

Such as?

Honestly, from a quick glance at SGI''s STL site (link) I see little to nothing in the STL that isn''t either a part of Lisp or trivial to implement (and by trivial I mean a couple lines of code). The Common Lisp standard includes a LOT of useful stuff. Google for "Common Lisp Hyperspec" if you don''t know where to look.

And while I agree with you that the library of C++ code available out there dwarfs that of Lisp, in some areas that code accomplishes something that is largely unnecessary in Lisp (as a couple of examples how about scripting languages, and just about anything related to XML).

--- end of smug Lisp weenie post ---

Disclaimer: I''m not a zealot but I do like Lisp. It just strikes me that your assertion about Lisp and the STL is just plain wrong and probably coming from ignorance.

##### Share on other sites
Diodor    517
Memoizing: http://www.bookshelf.jp/texi/onlisp/onlisp_9.html#SEC43

##### Share on other sites
Vlion    151
Oooh, look, a loop construct in lisp. How underused but useful.
Excuse me?
This is called elementary procedural programming. This is what you learn in week three of CS101. I''m sorry, but I laugh.

The caching/memoizing construct is interesting- on thought it wouldn''t be difficuly to write some c++ construct to do it. Would have been nice to see the implementation though.

What would make lisp a notably practical language is to present a topic which would require not only pages and pages of backend c++ code, but pages and pages of frontend code; which both could be neatly concatenated and/or made much clearer using lisp.

The prolog application sounds interesting and a good application.

AP: I did do some study and learning. I spent 4-6 weeks trying to work out a concept in lisp. I''m asking this question based on my experience in lisp.

I would submit that string work is non-intuitive in lisp, as I worked somewhat with strings in my code and found the mechanisms difficult to work with clearly.

~V''lion

Bugle4d

##### Share on other sites
Extrarius    1412
quote:
Original post by Vlion
Oooh, look, a loop construct in lisp. How underused but useful.
Excuse me?
This is called elementary procedural programming. This is what you learn in week three of CS101. I'm sorry, but I laugh.[...]
Have you looked at the lisp loop construct? Its probably the most complex 'basic' construct you'll find in any language. It is NOT just the basic-style loop/endloop/exitwhen. It can be virtually any kind of loop and can automatically do lots of complex things. It is so complex, in fact, that many lisp books don't cover it. It could be a pair of books itself if somebody felt like explaining both the implementation and usage.

The implementation of memoize can be found on page 65 of the freely download book 'On Lisp' and is as follows:
(defun memoize (fn)  (let ((cache (make-hash-table :test #’equal)))    #’(lambda (&rest args)	(multiple-value-bind (val win) (gethash args cache)	  (if win	      val	      (setf (gethash args cache)		    (apply fn args)))))))

[edited by - extrarius on February 22, 2004 1:25:09 AM]

##### Share on other sites
Diodor    517
quote:
Original post by Vlion
Oooh, look, a loop construct in lisp. How underused but useful.
Excuse me?
This is called elementary procedural programming. This is what you learn in week three of CS101. I'm sorry, but I laugh.

The point about the loop construct wasn't (just) that it is more powerful than similar looping constructs in other languages, but that it was _added_ [EDIT:] on top of the[:EDIT] Lisp language. If it wasn't there, you could have added it yourself. Now _that_ is something you can't do in that many languages.

quote:

The caching/memoizing construct is interesting- on thought it wouldn't be difficuly to write some c++ construct to do it. Would have been nice to see the implementation though.

The implementation was on the page I linked to, though slightly above. What would be a C++ equivalent of this?

quote:

AP: I did do some study and learning. I spent 4-6 weeks trying to work out a concept in lisp. I'm asking this question based on my experience in lisp.

I would Submit that string work is non-intuitive in lisp, as I worked somewhat with strings in my code and found the mechanisms difficult to work with clearly.

This is the exact same experience I've had with Lisp. It's very obvious that there are very many things to love about Lisp (dynamic types, first class functions, lambda functions, symbols, the interactive way of coding - with instant access to compiler, debugger and execution at the same time, mapping functions, lists, macros) and it's very easy to find things that wow me away (On Lisp is full of such examples), but when the time came for me to actually do something in Lisp, it was all very complicated and clunky, and all the functions I need seemed to be missing. Things will get better with practice (lots of it), Lisp isn't a side language you learn fast and use right away, but you should be able to see that there's more to Lisp than lots of paranthesis.

[edited by - Diodor on February 22, 2004 5:28:49 AM]

##### Share on other sites
Predictor    198
quote:
Original post by Anonymous Poster
The point is that you won't find the set of features described in this thread from any other single language except Lisp.

I'm not sure I see the practical value of this. The vast majority of programming effort is spent on well-studied problems. Why not use more than one language? The reason that there is a SQL language is that a powerful need was perceived for dealing with relational data structures. SQL provides an effective and efficient set of tools for dealing with this problem. While SQL is a poor choice for other types of work, like statistical analysis or intricate text manipulation, there are other tools which excel at those functions, like MATLAB and Perl.

The above quoted quality seems better suited to the question, "If you were stuck on a desert island and could only take one programming language, and didn't know ahead of time what sort of develepment challenges would present themselves, what would you take?", than it is to the question, "Which language or languages best suit this problem, in this particular context". (Incidentally, I suspect assembly language and Forth programmers would have brought their favorites to the island!)

-Predictor
http://will.dwinnell.com

[edited by - Predictor on February 22, 2004 9:58:34 AM]

##### Share on other sites
Guest Anonymous Poster
Side question: how does Lisp compare to Haskell ("a purely function language with modadic IO", www.haskell.org)? I''ve only used Haskell and I like it very much. And what is the benefit of Haskell (functional programming) over imperative programming? Added abstraction: higher order functions, partial parametrisation, (in case of Haskell) lazy evaluation, et cetera. Even just being able to write ''map'' and ''fold''.
I had a class on functional programming. It greatly improved my thinking. I still write games is C++; you would have a hard time to do it in Haskell I suppose. But for lab assignments Haskell is great and it is great fun trying to write as elegant code as possible.
Nowadays, I recognize ''map'' and ''fold'' everywhere when programming. In Haskell, I hardly ever write explicit recursion: I recognise the higher-abstraction concept I''m applying and state that instead.
If you study CS, by all means pick up a course on functional programming. It''s great :D.

Thamas

##### Share on other sites
Extrarius    1412
quote:
Original post by Predictor
[...]
Well, Lisp isn''t best for all problems, but it a nice, clean language and for trying new things its fun. If all you want to do is write yet another database interface, by all means feel free to use VB or Borland Builder or some other RAD tool. I, personally, prefer doing things I haven''t done before, and for a lot of those kinds of projects, Lisp is a good language. That may just be because of the kinds of things I haven''t done yet (I have spent several years programming random things in C and now C++, so I have more places to expand in other types of language). As everybody has pointed out over and over, because it lacks libraries or premade interfaces to them it isn''t the perfect language, but it is pretty good. The ANSI standard could definitely use an overhaul, and I''d very much like to see it get one.

AP: I''ve not looked into Haskell much, but one thing that makes Lisp very different is that Lisp is not a ''pure functional'' language. It can be used as one, but the ability to redefine variables and things like that makes it a nice halfway point between imperitive and functional. Also, I seem to remeber that Haskell didn''t benchmark too well. I''ve only seen a few benchmarks with Common Lisp in them, but in all of them it seemed to compete very well. It isn''t quite as fast as C++ of course, but close enough for most of the people that visit this site. As you have said, the more you learn such a language you learn to see where the ''callback constructs''(map, etc) come in handy and can use them instead of explicit iteration or recursion.

##### Share on other sites
Diodor    517
quote:
Original post by Extrarius
Have you looked at the lisp loop construct? Its probably the most complex 'basic' construct you'll find in any language. It is NOT just the basic-style loop/endloop/exitwhen. It can be virtually any kind of loop and can automatically do lots of complex things. It is so complex, in fact, that many lisp books don't cover it. It could be a pair of books itself if somebody felt like explaining both the implementation and usage

This makes me curious: is there more to loop than the tutorial I've linked to shows? ( http://www.ai.sri.com/~pkarp/loop.html )

quote:
As everybody has pointed out over and over, because it lacks libraries or premade interfaces to them it isn't the perfect language, but it is pretty good.

It should still be possible to use the libraries of other languages. I got to combine C and Lisp by loading a DLL, and made a graphical tic-tac-toe game (SDL + my user interface in C; AI & logic in Lisp), but I wasn't very happy with the solution as it made debugging somewhat difficult (and the Lisp executable was rather big too at 1.3MB).

[edited by - Diodor on February 22, 2004 11:55:20 AM]

##### Share on other sites
Diodor    517
quote:
Original post by Predictor
Why not use more than one language?

Which is the very point of Lisp - it makes it easy to use more languages for a single project - without the interfacing and maintainance problems. With Lisp you get many languages working together on the same data, and you have access to all of them at the same time using the same debugger.

[edited by - Diodor on February 22, 2004 12:08:02 PM]

##### Share on other sites
Guest Anonymous Poster
quote:
Original post by Predictor
Why not use more than one language?
It won''t suffice, not by far. When writing a single function, I might find it handy to use pattern matching, continuations and dynamic closure. You might be able to find many languages with the features you want but you wouldn''t be able to interoperate between several languages so easily. If you have to change language after every few lines, you''d be writing more interfacing code than normal code. In fact, it''d be so hard that one would in most cases settle for a sub-par solution within a single language. The jumping between several unrelated languages becomes unbearable or practically impossible, if you really want to use many different features from several languages.

And those languages, even when combined, still wouldn''t be able to give me all the features I can do with macros. There are lots of uses for macros that extend the language in such a way one would never expect to see in some "pre-written" language, because those features would be so highly dependent on a single problem field, or even just your particular application.

##### Share on other sites
Predictor    198
quote:
Original post by Anonymous Poster
quote:
Original post by Predictor
Why not use more than one language?
It won't suffice, not by far. When writing a single function, I might find it handy to use pattern matching, continuations and dynamic closure. You might be able to find many languages with the features you want but you wouldn't be able to interoperate between several languages so easily. If you have to change language after every few lines, you'd be writing more interfacing code than normal code. In fact, it'd be so hard that one would in most cases settle for a sub-par solution within a single language. The jumping between several unrelated languages becomes unbearable or practically impossible, if you really want to use many different features from several languages.

And those languages, even when combined, still wouldn't be able to give me all the features I can do with macros. There are lots of uses for macros that extend the language in such a way one would never expect to see in some "pre-written" language, because those features would be so highly dependent on a single problem field, or even just your particular application.

Who said anything about changing languages "every few lines"? I think people here are talking past each other.

The claim was made that Lisp provide some unspecified advantage over other languages. Knowing that Lisp cannot possibly be better than all other tools under every circumstance, my question is: Under what circumstances does Lisp provide a real advantage?

Most computing tasks which are in commercial demand are fairly well studied, hence the development of relatively specialized languages and related tools (macro languages, development environments, debuggers, etc.). My contention is that these tools (C/C++, SQL, Perl, Fortran, whatever) when used in combination, as they are in real work offer two important qualities: 1. sufficient syntactic elegance to adequately represent useful solutions to common problems and 2. efficient use of available system resources.

Is there some bizarre situation which could be dreamed up, under which Lisp would dominate other, more popular tools? Sure. What I wonder is: What fraction the actual programming effort that is undertaken on this planet is covered by such situations? It's obviously greater than zero, but I doubt its more than a few percent, if that.

Most of the examples given thus far of Lisp's presumed advantage are technically cool, but I don't see that they provide a general advantage. The thing about needing to be more intelligent to use Lisp seems completely backward to me: How is a tool being more difficult to use an advantage? Color me old-fashioned, but I think for most computing tasks, conventional tools will continue to dominate the field. I can't imagine someone simulating Fortran (or, insert any of a dozen other languages here...) in Lisp and getting any kind of run-time performance.

-Predictor
http://will.dwinnell.com

[edited by - Predictor on February 22, 2004 2:24:06 PM]

##### Share on other sites
Predictor    198
quote:
Original post by Anonymous Poster
quote:
Original post by Predictor
Why not use more than one language?
It won't suffice, not by far. When writing a single function, I might find it handy to use pattern matching, continuations and dynamic closure. You might be able to find many languages with the features you want but you wouldn't be able to interoperate between several languages so easily. If you have to change language after every few lines, you'd be writing more interfacing code than normal code. In fact, it'd be so hard that one would in most cases settle for a sub-par solution within a single language. The jumping between several unrelated languages becomes unbearable or practically impossible, if you really want to use many different features from several languages.

And those languages, even when combined, still wouldn't be able to give me all the features I can do with macros. There are lots of uses for macros that extend the language in such a way one would never expect to see in some "pre-written" language, because those features would be so highly dependent on a single problem field, or even just your particular application.

Since multiple, non-Lisp languages are used together for exactly this purpose everyday, on some of the largest systems in the world, I suppose the above needs to be qualified. Let me give an example. I work at a bank, where a substantial database of customers and their activities are stored in an Oracle database. The data in that database is regularly churned by SQL code. My department, which performs the analytic function of the bank uses SAS both: 1. to extract and process data from the relational database and 2. to store intermediate and final results (SAS is sort of both a language and a database). I write programs to perform all sorts of quantitative analysis (mainly predictive modeling), which I do in SAS and MATLAB. This, in my experience, is a typical collection of programming tools in the corporate world. My question is: Is anyone here seriously suggesting that any of these three components, or all of them, is a candidate for replacement by Lisp (let's ignore transition costs, legacy code issues and the skill set of current developers)?

Let's be clear about the real mix of programming situations: what you term "single problem fields" are, together, the bulk of the computing world, by any serious measure.

-Predictor
http://will.dwinnell.com

[edited by - Predictor on February 22, 2004 2:26:24 PM]

##### Share on other sites
Diodor    517
quote:
Original post by Predictor
The thing about needing to be more intelligent to use Lisp seems completely backward to me: How is a tool being more difficult to use an advantage?

Lisp _allows_ you to be more creative - the extra intelligence you spend on writing code pays up because the resulting code is that more compact, elegant and maintainable.

quote:

Color me old-fashioned, but I think for most computing tasks, conventional tools will continue to dominate the field. I can''t imagine someone simulating Fortran (or, insert any of a dozen other languages here...) in Lisp and getting any kind of run-time performance.

Whether Lisp will dominate anything or not is not necessarily relevant. The embedded languages, built on Lisp using Lisp macros, transform the code from the embedded language to Lisp code, which is then compiled. The run-time performance doesn''t suffer in any way.

quote:
Who said anything about changing languages "every few lines"? I think people here are talking past each other.

You understand the need for specialized languages for special problems, yet you aren''t thrilled at the thought of freely using several different languages together in a single function. I find this thought quite amazing.

##### Share on other sites
Predictor    198
quote:
Original post by Diodor
You understand the need for specialized languages for special problems, yet you aren''t thrilled at the thought of freely using several different languages together in a single function. I find this thought quite amazing.

Whether Lisp can usefully recreate the functionality of those other languages is the issue. Are you saying that it would be possible to re-create, for example, the performance of a large corporate relational database (Oracle, let''s say) in Lisp?

-Predictor
http://will.dwinnell.com

##### Share on other sites
Guest Anonymous Poster
quote:
Original post by Diodor
Lisp _allows_ you to be more creative - the extra intelligence you spend on writing code pays up because the resulting code is that more compact, elegant and maintainable.

Would being more intelligent be an advantage in any language? Why is this an advantage specific to Lisp?

-Predictor
http://will.dwinnell.com

##### Share on other sites
HairyTroll    192
quote:
Original post by Predictor
Are you saying that it would be possible to re-create, for example, the performance of a large corporate relational database (Oracle, let's say) in Lisp?

I'm not sure why one would want to rewrite a database such as Oracle in Lisp. Rather use Lisp to perform analysis of the data retrieved from the database, such as in the following case:

Lisp & C/C++ are used to run the back-end for Orbitz.

Here is an email from one of the guys that implemented the system.

quote:

Occasionally we've had to move code from Lisp to C++, usually because of data loading issues (Lisp garbage collectors just can't deal with gigs of data, and there's no way to rapidly load gigs of data into a Lisp). Our experience has been a 10 to 1 code expansion; I don't think there are any programmers in our company that regret the choice of Common Lisp.

If you read the article in its entirety, you will see that the strengths of both C++/C and Lisp are used to full advantage. They didn't do the entire system C/C++, neither did they attempt to write everything in Lisp.

[edited by - HairyTroll on February 22, 2004 6:12:52 PM]

##### Share on other sites
Predictor    198
quote:
Original post by HairyTroll
quote:
Original post by Predictor
Are you saying that it would be possible to re-create, for example, the performance of a large corporate relational database (Oracle, let''s say) in Lisp?

I''m not sure why one would want to rewrite a database such as Oracle in Lisp.

I am not arguing that one would want to. What I wrote, which you quote above was in response to the following from Diodor:

quote:
Original post by Diodor
You understand the need for specialized languages for special problems, yet you aren''t thrilled at the thought of freely using several different languages together in a single function. I find this thought quite amazing.

I fully appreciate the benefits of mixing programming languages (whether Lisp is included or not)- in fact, that''s what I''ve been arguing for. Others here, though, seem to be aserting that Lisp can take over the function of all other languages due to its extensibility.

-Predictor
http://will.dwinnell.com

##### Share on other sites
Guest Anonymous Poster
quote:
Original post by Predictor
Who said anything about changing languages "every few lines"? I think people here are talking past each other.
No, you''re missing the point. I *want* to have a set of features X,Y,Z in a single function. If language 1 gives me X, some other gives me Y and some other gives Z, I''ll *have* to change the language every few lines or as the realistic case is, use one language that best suits the situation and use sub par solutions for the features it lacks. Or I can use Lisp, which gives me X,Y,Z within one language, thanks to macros (and possibly other features).
quote:
Knowing that Lisp cannot possibly be better than all other tools under every circumstance
What do you know? Lisp can be pretty close under every circumstance, if not better. It all depends on the team''s ability to create (or find someone else''s implementation) the most useful abstractions they''ll need. Just the fact that a prolog compiler can be written in Lisp with a few hundred lines should give you some feel about Lisp''s ability to adapt to highly different domains.
quote:
Under what circumstances does Lisp provide a real advantage?
If the project is large enough and the team is skillful enough. Or if the team has already built all kinds of useful abstractions in their previous projects, Lisp has an advantage on small projects also.
quote:
but I don''t see that they provide a general advantage.
You''re just unwilling to accept it. It sounds as credible as a C programmer saying "I don''t see how OO would provide a general advantage".
quote:
The thing about needing to be more intelligent to use Lisp seems completely backward to me: How is a tool being more difficult to use an advantage?
C++ is more difficult to use than Basic. C++ has an advantage for dedicated programmers because it offers more power -- power that takes more time to master. Lisp has an advantage for the same reason. A person who uses C++ and Prolog need not understand how Prolog really works. A person who implements something like Prolog into Lisp, must be a pretty good programmer. You can''t get power out of Lisp if you''re not able to think liberally. You could just be using CLOS and some other pre-made features, but that wouldn''t make Lisp worth using.
quote:
I can''t imagine someone simulating Fortran (or, insert any of a dozen other languages here...) in Lisp and getting any kind of run-time performance.
Believe it or not, the performance of Lisp, also when used to compile some other language, is not bad. The needed features/sub-languages wouldn''t be "simulated", but compiled.

##### Share on other sites
Kylotan    9853
quote:
Original post by Diodor
You understand the need for specialized languages for special problems, yet you aren''t thrilled at the thought of freely using several different languages together in a single function. I find this thought quite amazing.

The thing is, with Lisp you''d have to write these mini-languages, right? Whereas with 2 existing languages, they are already designed to fit the different needs. It''s like the difference between a factory that makes tools, and a well-stocked toolbox; Lisp is more powerful but does that make it immediately more convenient?

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

##### Share on other sites
Diodor    517
quote:
Original post by Kylotan
The thing is, with Lisp you'd have to write these mini-languages, right? Whereas with 2 existing languages, they are already designed to fit the different needs. It's like the difference between a factory that makes tools, and a well-stocked toolbox; Lisp is more powerful but does that make it immediately more convenient?

Of course, you're right. You have the choice of interfacing with the other (external) languages in the usual multi-language ways (also available in Lisp). (the Oracle example before should fit here I suppose)

It should be noted that usually only a few features of another language are needed at a time.

[edited by - Diodor on February 23, 2004 2:43:53 AM]