Why lisp?

Started by
103 comments, last by Vlion 20 years, 1 month ago
Alright. I''ve spent about a month working on clisp- writing various functions, mostly dealing with string handling and analyzing. I have experienced no evidence that clisp provides any superiority relative to my personal favorite imperative language, C++. It of course provides better facilities here and there; however, I see no advantage compared to a well-written imperative library. Could I please see a clear, obvious example where the lisp paradigm makes programming a solution easier? I''m not trying to make a c++ vs. lisp war, so no flames. I''d just like a well-written example or two, or even a link to one. Thanks alot. ~V''lion Bugle4d
~V'lionBugle4d
Advertisement
Worse is Better, Richard P. Gabriel''s thoughts on lisp and imperitive languages. Warning: he doesn''t come to any conclusions. The papers he links to come out in support of lisp and against lisp. And they''re all written by him. I just think they''re fun reads. Of course, I have a twisted definition of fun.
I could see a few reasons why Lisp is superior to other development platforms in application development due to code is data and data is code paradigm. If you''re interested dig up an old Lisp vs. XML thread. This superiority is minimized with recent advancements in .NET where classes are easily serialized into XML and back, and source code is generated from XML schema in a few seconds. Of course theoretically Lisp is still more powerful but practically .NET platform provides everything you need to successfully do data parsing, serialization and storage.

I do not see how Lisp would be superior specifically for AI. Of course I''m not a Lisp expert (I never wrote more than a few lines of code in it). May be someone else can give you a more qualified response.
Have you read What is so great about Lisp? and Lisp is King? They both contain a lot of information. Yes they are long, but if you haven''t read them I think it would be worth it to do so.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
quote:Original post by Extrarius
Have you read What is so great about Lisp? and Lisp is King? They both contain a lot of information. Yes they are long, but if you haven''t read them I think it would be worth it to do so.

I''ll second that. Very good threads.
If a plant cannot live according to its nature, it dies; so a man.
Lisp''s simple syntax lends itself to easy manipulation of the language. You can modify the language to suit your needs exactly and archieve abstraction levels higher than imaginable for most C++ programmers. If you don''t know macros and how to use macros well, you don''t know Lisp.

With Lisp, it''s relatively easy to create an actual compiler for a language of your own. Languages that deal with some subset of first order logic are pretty useful in AI. In C++ you have to settle for interpreting any sub-language you need, unless you''re going to use unimaginable amount of time to actually write a compiler for the job. With Lisp, you can compile code at run-time and run code at compile-time. Have you toyed with template metaprogramming in C++? It''s considered to be a hot topic these days since modern C++ compilers are starting to make it possible, but it''s a completely inferior system to what has been used in Lisp for ages through it''s macros.

Read Paul Graham''s On Lisp (free of charge):
http://www.paulgraham.com/onlisp.html
and you won''t want to go back to C++ again
quote:Very. The C++ paradigm has taught you to work within its own limitations. You must explicitly define the exact structure of a class or struct and then work with it. Lisp doesn''t impose this on you. Lisp works well with incomplete data, or data structures which grow according to the evolving data that is being acquired.


From Lisp is King thread.

The last sentence illustrates a common thing I''ve heard WRT lisp- its flexibility.

Could I see some hard code here regarding that? Its a pretty thing to say, but due to my inexperience, I don''t perceive how to do that in clisp.

Anyway:
I still don''t see why lisp is conclusively better than a well-written imperative langauge with a good library behind it.
I''ve even looked through a goodly portion of On Lisp and don''t see why.

~V''lion

Bugle4d
~V'lionBugle4d
Really, I can''t think of any examples that would show how flexable lisp is without being complete programs. It is very difficult to find trivial examples that really demonstrate how usefull features can be =-/
First, realize that Common Lisp is NOT the best language at everything (nor is any other language). There are some things, such as systems programming (drivers, OSes, etc) that are possible but not easily or best done in Lisp. Common Lisp is a good general purpose langauge that allows you to focus on more abstract things than byte alignment and calling conventions. While it isn''t as fast as native-compiled C++, it is close, and definitely fast enough for many, if not all, games and other real-time applications. Note that the speed depends quite heavily on which compiler you use. I don''t know about clisp (it might even be only an interpreter), but Corman''s compiler is quite good and makes fast code (an absolute measurement, I don''t have anything to compare it to).

The best example of flexibility I can think of (probably because its the only thing I''ve used Lisp for so far) is genetic programming. In C++ or some other low-level language, creating a genetic programming library would either require all kinds of trickery with assembly and manually managing the calling conventions of functions OR implementing an interpreter. In Lisp, you can just use the list functions to make a list, (optionally) compile it at runtime, and then execute it as if it had always been there. Since Lisp code is represented as a list, and Lisp (LISt Processing) is good at manipulating lists, it is also quite easy to manipulate code. I haven''t quite finished my implementation of GA yet so I don''t have much code to post, but it took me about 1 day to get a basic code generator up and running and spitting out random formulas with next to no Lisp knowledge (most of the time was spent looking up things in ''ANSI Common Lisp'' because I didn''t know the language at all =-). In that time, I wrote ~100 lines of code that can create a random numerical expression and have it ready to be executed. The operators allowed in the expression, the number of arguments each takes, and the variables the function operates on are all customizable by a few global variables. The only reason I haven''t finished it is because I''ve moved on to making my own Lisp interpreter (which turned out to be a lot harder than I thought it would).
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Since you like C++ you may also appreciate OOP. It''s interesting that the Common Lisp object system (CLOS) was not created by heavily modifying the Lisp language (or modifying it at all actually). Instead, it was added as a sort of library, as an embedded language. You cannot even begin to imagine some such wizardry in the C based crowd of languages.

Lisp changes the way you think. It''s a very slow process, but it is real. No longer do you ask yourself "what is the best way to use this language to solve this problem?", but "what is the best language to solve this problem?". You stop being a slave of a single language, of its particular way of thinking and of the limited things you can express in that language - instead each language gives you ideas of things you can say in Lisp. Prolog, CLIPS, GPSS or XML Schema - all look at programming in different ways - but you can have their philosophies directly imported in Lisp.

______________________________________

Pax Solaris
I think the following quote from one of the three guys who specified the Java language sums Lisp up quite nicely. As Fortran is imperitive, his quote can also be applied to C++/Java etc.

quote:"If you give someone Fortran, he has Fortran. If you give someone Lisp, he has any language he pleases.
–Guy L. Steele Jr"


If you write a library to interface to a database in C/C++, you end up with librares, classes/methods that must be called to interface to the database. If you do the same in Lisp, you end up with a language like SQL that becomes integrated within Lisp.

You may point out that the standard way to interface to a database in C/C++ is via SQL. However someone would have had to have written the SQL parser that translates the SQL expressions into a lower level language. In Lisp the parser is never written, SQL just becomes a direct extension of Lisp.

If you write a game in C/C++, you end up with a game as well as libraries, classes/methods. If you write a game in Lisp you end up with a game, as well as a language that is used for writing games. Lisp becomes the scripting language.

Doing the same in C/C++ requires writing a parser/compiler (or including Lua etc.) then some way to graft the new language into the game engine. And even then, you are either inside the script calling out, or inside C/C++ calling into the script.

This topic is closed to new replies.

Advertisement