Advertisement

Why lisp?

Started by January 31, 2004 10:00 PM
103 comments, last by Vlion 20 years, 11 months ago
Memoizing: http://www.bookshelf.jp/texi/onlisp/onlisp_9.html#SEC43
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
~V'lionBugle4d
Advertisement
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]
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
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]
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]
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
Advertisement
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.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
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]
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]
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.

This topic is closed to new replies.

Advertisement