Re: Choosing a Programming Language
Posted: Mon Nov 15, 2010 8:58 am
usagi wrote:Anyways, yes, you're right I've never written anything serious in Lisp. Who has?
One recent example is ITA software, who sold to Google for 700 million dollars this year. There are lots of success stories at the ALU wiki.
They don't have a compiler. Well, that isn't actually true, but no one has the libraries.
No, to both; these are common myths without any connection to reality. Almost all modern Common Lisp implementations have compilers and use them. Also, there are tons of libraries for any purpose you might imagine. The most popular can be installed through clbuild, the gentoo lisp overlay, asdf-install, or (brand new) quicklisp. You can also browse Cliki.
Imagine "ls" written in lisp. How big is the binary?
Well, it would have to include the basic Lisp system, so it would be comparatively big. C programs have the advantage that their runtime is already running on Unix-like systems, so they do not need to include it. This would be the other way around on a Lisp-based operating system.
Writing something like a sgf editor or flashcard drilling program for sale and use would be a true nightmare for both programmers and end users, but easy tasks in more modern programming languages.
What makes you say that? You can take some OpenGL binding or McCLIM and have it up and running just as easily as in other languages.
Am I wrong in that assumption, that Lisp isn't nearly as suitable as, say, Java or C# for writing killer applications? And if I am right, what is it exactly that Lisp was designed to do?
Yes, you are wrong.
Harleqin wrote:I have learned to think in terms of breaking up the idea itself, and translating that directly into code. So I have tended to avoid langauges which have a large amount of esoteric syntax. LISP in particular contains a large amount of such.
No, it does not. In fact, it has almost no syntax at all. In other languages, you have three or four kinds of parentheses, a lot of keywords, precedence rules, perhaps even "structure by indentation" so that the amount of whitespace becomes part of the syntax.
You directly write the abstract syntax tree. This has several important advantages that set Lisp apart. For example, instead of writing "2 + 3 * 4", which has to be translated into an abstract syntax tree through the use of precedence rules and the shunting yard algorithm, you write "(+ 2 (* 3 4))", which directly represents the abstract syntax tree.
I am not sure I understand. I find the point and the example difficult to understand. Perhaps I've been infected by the java way of doing things. But all joking aside, if you mean it's easier for the computer to understand "(+ 2 (* 3 4))" than "2 + 3 * 4", I'd be inclined to agree.
I mean that it is easier for the programmer to reason about. Lisp syntax is extremely regular (not in the grammar sense) and explicit.
Again I find the examples very difficult to follow.
Yes, it is difficult to argue on the basis of your limited understanding of Lisp.
But the point I was making is not that ",@" is readable or unreadable. The point I was making is that ",@" is esoteric and difficult for beginners to understand.
It is quite clear once you understand how macros work. "Practical Common Lisp" has a very nice explanation for that.
I mean, look at the above Lisp. No wonder they invented syntactic sugar. But when do you stop? Why don't you just writeand be DONE with it all? Finally and forever?Code: Select all
CustomerList.add(CustomerRecord);
I do! I write
Code: Select all
(push customer-record customer-list)
and that's it.
Harleqin wrote:Being familiar with many computer languages and how they are implemented I find the decision to include such syntax as part of the language incomprehensible.
I think you just had a bad introduction to the language, or none at all.
That may be true, but including hardware kludges in software is an abomination, and Lisp shows its age well with its irregular syntax.
Lisp syntax is extremely "regular". It is always "(operator argument1 argument2 ...)". That is all there is to it.
Au contraire, in Lisp, you usually shape the language to your problem domain and then only think in that.
Yeah I get what you're saying. But you can do that in any language.
Well, on the face of it, yes. This is also known as the Turing tarpit. However, it is easier to do in some languages than in others. Having real macros on the level of the abstract syntax tree is a feature the lack of which is difficult to work around.
What I was referring to in a roundabout way was the syntax (aforementioned) screwups like incorporating hardware kludges into the software -- the "cons problem", which was designed to aid translation into assembly language and so forth.
Lisp just has support for lists on the basic language level. Modern applications usually do not even use cons, they use CLOS objects with explicit names from the problem domain.
Then there is the single quote problem, where by you are quoting something, but there's no end-quote. But actually there is, it's a different character that looks like it belongs somewhere else. LikeCode: Select all
(list 1 '(2 3) 4)
;Output: (1 (2 3) 4)
Makes brilliant sense, in a way, but looks weird and is not good for beginners because it is esoteric.
Why is it esoteric? It is not difficult to understand that quote prevents a symbol from being evaluated, and that 'foo is an abbreviation for (quote foo)---unless you expect ALGOL syntax, of course.
Let us take a look at C syntax:
Code: Select all
int a = 1;
a = 2;
How can a be at the same time equal to 1 and to 2? It does not make sense!
Code: Select all
(let ((a 1))
(setf a 2))
"Let a be 1. Now, set a to 2."
Let me explain my idea this way. Let's say we are going to design a brand new computer language that will solve all of the world's software engineering problems. This language would be taught in every school to every child and the next ten years would all be about implementing it in EVERYTHING.
Let's say that to save time we were also going to start with Lisp, but it was going to be reviewed to make sure it was a suitable language -- just to be certain. During the review process someone says "Wait a minute, isn't Lisp, fundamentally, a language that manipulates lists?" and everyone says yeah, sure, of course. Then he says "Well then why does the list primitive which the entire language is build on only contain two elements? Why don't we update that one, small part of the language so that a list, natively, can have any number of elements that anyone would want?"
And everyone says sure, why not. But then some guy in the back says "Wait a minute! Computers 50 years ago had to do things this way!!" so they all agreed they would leave cons in, just in case. Just in case you needed to implement it on an IBM 704 or PDP, where including first, last, rest accessors would be somewhat problematic.(from: http://www.faqs.org/faqs/lisp-faq/part2/section-13.html)John McCarthy developed the basics behind Lisp during the 1956 Dartmouth Summer Research Project on Artificial Intelligence. He intended it as an algebraic LISt Processing (hence the name) language for artificial intelligence work. Early implementations included the IBM 704, the IBM 7090, the DEC PDP-1, the DEC PDP-6 and the DEC PDP-10. The PDP-6 and PDP-10 had 18-bit addresses and 36-bit words, allowing a CONS cell to be stored in one word, with single instructions to extract the CAR and CDR parts. The early PDP machines had a small address space, which limited the size of Lisp programs.
Then they said no, that's ridiculous, why should we cater to 50 year old hardware limitations? But, they still decided to leave cons in -- "We'll leave in the cons just in case there arises a problem for which higher level structures already present in Lisp (like arrays, hashmaps or using "proper lists") can't solve."
Thus you have the current Lisp style of doing things. But there are still big problems with this because cons are there, and the fact that there are alternate ways of doing things doesn't solve these problems. Example --> no copy list function. You have to write your own, from scratch, every time. Or, do I have that wrong? I might. It's true I don't have serious experience with lisp. Maybe someone wrote a library or something.
Well, you have not understood lists. How would you construct a single-linked list? Each node would have two things, a value and a pointer to the next cell. That is exactly what a cons cell is: a container for two things. A list is then either the empty list, or a series of cells, where each has a value and a pointer to the next cell, terminated by the empty list. This has nothing to do with hardware. It is just a very simple data structure, which is very useful to implement a language with.
In fact, John McCarthy had first developed Lisp syntax as a way to write mathematical statements. It was then discovered that it was very easy to directly implement as a programming language.
Example; I just wrote a few programs recently; a NetHack like program, an advanced SGF editor with tag-editing features, and a flascard program that drills CJK, which I actually use in the highschool classroom when I teach occasionally. If I wrote those programs in Lisp I would have had to write separate linked list libraries for EACH PROGRAM. Instead, I saved time by writing them in Java.
Take a look at the source code of the old Intercom text adventures. They are written in a Lisp dialect, which allowed a very direct description of the worlds. Similar exercises seem to be in the new "Land of Lisp" book. You do not need linked list libraries, they are part of the language standard. If you want this kind of comparisons, here is a report on an experiment: http://www.flownet.com/gat/papers/lisp-java.pdf. Really, there is no problem writing the programs you mention in Common Lisp.
The end user doesn't care what language it is written in and I saved time by not having to reinvent the wheel three separate times. To tell you the truth Harlequin, I'm scared to try lisp because I don't want to end up proving to myself it is a giant waste of my time and then dumping it.
I call FUD. I have never seen a language where you can take the DRY (Do not Repeat Yourself) principle as far as in Lisp. Java is always "verbose language is verbose".
But I remain puzzled by people's attachment to a 50 year old language with hard to grasp, irregular syntax, that has no higher level list operators.
It is not irregular, it is easy to grasp (unless you cannot let go of ALGOL-derived syntax), and it has all kinds of higher level list operators, many of which you do not even find in Java and similar languages. Where is MAP, MAPCAR, MAPCON, MAPL, MAP-INTO, REDUCE in Java? What, you cannot pass functions? What kind of stupid language is that? You should consider that the people who are attached to Lisp even though they know the ins and outs of Java and similar languages perhaps have found something.
The examples you give can all be written in one line of Java (or whatever); something like CustomerList.add(CustomerRecord); where CustomerList and CustomerRecord are variables/lists/whatever.
Again, you simply have no idea of even the basic functions Lisp provides. (Push customer-record customer-list). That is even without going into the power CLOS (the Common Lisp Object System) provides. I am pretty sure I can match any Java code snippet you provide with a more concise and at least as readable version in Common Lisp.
What you mentioned about coding your problem domain and thinking in terms of that has, generally speaking, already been done. So from the standpoint of someone who has a great deal of experience with languages, including Lisp, I wouldn't recommend for beginners.
You obviously do not have any great experience in Lisp.