12 ms·
Python for Lisp Programmers (2000)
- jonathanstrange 8y agoOkay, I certainly don't want to start a language war, so let me be kind. There is one legitimate reason to switch from Lisp to Python: The number of packages and extensions. Python really has more than just batteries included, it's probably the language with the most available libraries after C++. Still, switching from Lisp to Python is bound to be painful...
- judofyr 8y agoIf you don't want to start a language war, maybe you shouldn't present subjective opinion as facts?
- posterboy 8y agoAs with programming languages, natural languages aren't uniform. So you might interpret "one reason" to mean only one or, since "only" wasn't said, give some leeway, assume good faith, and take it as "at least one, and that maybe enough", "primary", or whatever. It's underspecified, as the linguists say.
- judofyr 8y agoThe statement could have been made more neutral by stating that it was a preference: > I prefer programming in Lisp, but the packages available for Python makes me a lot more productive. That alone is enough for me to choose Python. I still miss Lisp though. Language wars are started because people talk about their preferences as an absolute truth (and other people disagree with the presented absolute truth), and you don’t avoid them by starting with “I don’t want to start a language war” while continuing talking in the same way. If you look at the other replies you see what typically happens: someone mentioned that Lisp does also have libraries, someone mentioned that there are other reasons to choose Python, someone mentioned that the article has a different focus (teaching, not writing). Instead of a comment thread where people talk about their experiences we have a thread where people point back at the OP and loudly complain “no, but see, you are wrong, because of x”. We even have a case where the OP is getting annoyed because someone assumed he didn’t know about Norvig. Seriously, this is exactly what happens when you write in such a style. This comment alone will make someone annoyed because there are plenty of people who have used both Lisp and Python and (guess what?) prefers Python: > Still, switching from Lisp to Python is bound to be painful...
- deleted 8y ago[deleted]
- xapata 8y agoWhat if you're the author of a famous textbook and you find that your pseudocode reads more like Python than Lisp and that students on average prefer Python? Is that a legitimate reason? If not, you should probably send a nasty email to Norvig explaining his illegitimacy.
- O_H_E 8y agoJust for your info. Norvig wrote the "Paradigms of AI Programming: Case Studies in Common Lisp" book, so I would say that he is pretty knowledgeable about his stuff.
- jonathanstrange 8y agoJesus Christ, could there be more condescending commentaries than yours or that of some other replies? You can safely assume that I know who Peter Norvig is, so keep it civil. His post illustrates how many programming tasks have gone from problem solving to lego-brick programming, where library is piled upon library and each of them is incomplete and contains piles of bugs. What could possibly be wrong with that approach? Just like Norvig, I don't claim that Python is bad per se or anything like that. All I've said is that it's painful to go from CL to Python in terms of the general features of the languages (not their tooling). If you have never done this transition, have never programmed sufficiently large programs in CL and Python, please don't comment on it.
- nothrabannosir 8y agoPlease don’t swear. Please. There are no victories down this spiral. Only barren soil.
- jonathanstrange 8y agoI'm sorry, I honestly didn't realize that this counts as an instance of swearing in certain language communities. My apologies!
- deleted 8y ago[deleted]
- coldtea 8y ago>His post illustrates how many programming tasks have gone from problem solving to lego-brick programming, where library is piled upon library and each of them is incomplete and contains piles of bugs. What could possibly be wrong with that approach? Compared to problem solving which doesn't use "lego bricks" and re-makes the wheel?
- divs1210 8y agoI'm not so sure about that. Clojure is a lisp, and has full access to the Java ecosystem.
- flavio81 8y agoAlso ABCL lets you Common Lisp over the JVM and have full access to the Java ecosystem.
- sametmax 8y agoSome other reasons: - you use softwares that are scriptable in Python (SIG, Blender, etc) - you write a lot of glue code. That pretty much Python raison de vivre. - you do a lot of data analysis manually. Pandas is the new excel, and jupyter the new matlab. - you do a lot of sysadmin. Scripting is just easier in a dynamic language. - you do a lot of CRUD websites. You just can't beat the frameworks from this language for this kind of things. They do most of the work for you, and do security better than you do. - you want to integrate new members in your team faster. Python is easier to learn than lisp. - you are coding a GUI. With kivy you can target desktop and mobile with one code base, and some skins are pretty (https://imgur.com/a/IjM0XGW https://imgur.com/a/IjM0XGW). With QT you can do powerful things on the desktop. With wx you can do simple GUI simply. - you have a lot of different kinds of task at hand, and don't want to have too many different languages in your stack. Python is never the best language at anything, but it's a damn good language for most things, so it makes it a versatile toolbox.
- giancarlostoro 8y ago> - you want to integrate new members in your team faster. Python is easier to learn than lisp. Heh, I listed Python in my resume and got this as my first job (after working at my local college) and I learned it on the job (I had used Python before, but nothing major yet) and I gotta say, not only is it easy to pick up if you know other languages, it's fun to experiment with if you do know other languages! I have only played with Clojure and Racket the most on the other hand, I appreciate them and would love to learn more but I get more done with Python in shorter spans of time.
- pimeys 8y agoOne thing I don't understand here why somebody needs to switch to Python and forget other languages? Sometimes I too hack something fast with Python, but still write lots of Rust and Clojure. Then if I need Python, it is very easy to just write some and get things done.
- msl09 8y agoWhat I don't understand is the necessity of having the video of the naked pirates of the caribbean guy in the corner.
- HelloNurse 8y agoNo painful switching is intended; for Norvig's purposes there are Lisp programmers taking an AI course and Python programmers taking an AI course, and both groups should be able to follow examples in a language they know, without stumbling. Only their teachers need to adjust to the updated code examples in Norvig's updated book, and this summary is a very nice introduction to the main differences between two basically similar languages. When and whether students should learn Lisp, Python, neither, or both is an entirely different issue.
- pjmlp 8y agoJava followed by .NET, beats both reagarding available libraries, unless you mean only open source ones. And JavaScript with their one liner packages probably beats all. Python still misses having a proper mix of AOT/JIT compilers as standard toolchain, like Lisp does.
- AnimalMuppet 8y agoJava's library is like Barbie - it has everything. For a standard library, it is insanely complete. I was going to say that C probably had more complete non-standard libraries than Java. But, on reflection, for the price of writing a JNI wrapper, Java can use all those C libraries, so Java gets the superset - its own plus C's libraries. In that environment, it is obviously impossible for C to win.
- deleted 8y ago[deleted]
- xapata 8y agoThere are some libraries I maintain in Python which provide services not available as open-source in Java (or any other free language, as far as my Google searching can tell). They're related to an archaic file format that is surprisingly popular, though still esoteric.
- flavio81 8y agoSomebody is underrating the Common Lisp ecosystem, me thinks. There are much fewer libs than in Python, of course, but, most likely, everything you need you would find in CL, and some of those libs are very high quality. >There is one legitimate reason to switch from Lisp to Python: The number of packages and extensions. Python really has more than just batteries included Which you can "steal" by using them from Common Lisp. By using the lisp library called "burgled-batteries". But still, as pointed below, the Java ecosystem is even bigger, and you can easily leverage by running Common Lisp on the JVM (using Armed Bear Common Lisp). And then there is Clojure, a lisp-like language that is weaved together with the JVM and thus with very easy ways to interoperate with the JVM.
- anaphylactic 8y agoI know this comment is rather inane, but rarely have I seen a library name so fitting yet so humorous as "burgled-batteries".
- kennytilton 8y agoLisp can talk to C/C++. And do not forget Clojure. That interops with Java.
- dwarfylenain 8y agoAnd what about hylang.org ? I'm surprised it's not even mentioned here : nice lispy syntax with all the python packages = best of both worlds :)
- a_c 8y agoWould appreciate if the reverse (Lisp for python programmer) exists.
- icc97 8y agoSecond sentence: > Although it wasn't my intent, Python programers have told me this page has helped them learn Lisp
- a_c 8y agoobviously the lazy me didnt click through the article. thanks!
- nerpderp83 8y agoMentioned elsewhere in the thread but take a look at Hy Lang, a lisp that compiles down to Python.
- deleted 8y ago[deleted]
- flavio81 8y agoI will consider writing such a guide... not a bad idea, really...
- kennytilton 8y agoAre we going to discover that Lisp is really a Python?
- flavio81 8y agoHis Kennyness, So many surprising things are to be found on this series of tubes called "the internets", you wouldn't be surprised, not only to find such a baseless claim, but a whole video to support it. That's one of the four noble truths of the internets: "online forum content is always ridiculous." Of course, I am not going to claim such a thing. I'd be reasonable and claim that Python is a Lisp, because Python actually is the compiler inside CMUCL.
- icc97 8y agoIt's worth noting that one of the main pain points mention of Python was that it was 2-100 times slower (vs 1-2x slower for Lisp). The slowest elements of Python compared to C++ were matrix multiplication (278x slower), array access (141x slower) and heapsort (84x slower). NumPy solves the two slowest, although I can't find an obvious contender for the sorting.
- enitihas 8y agoNumpy does sorting too.
- masklinn 8y ago> heapsort (84x slower) […] I can't find an obvious contender for the sorting. Use the built-in sort instead of hand-rolling your own? The built-in sort is not a heapsort and though I don't know what it was before the 2.3 "timsort" implementation, the essay mentions Python 2.7 so I would assume it's not talking about the old built-in sort either.
- hellofunk 8y agoThis article predates Python 2.7 by 10 years. The link to 2.7 was probably added or edited many years later.
- mkesper 8y ago(2000) Sadly there is no date at all in the article.
- susam 8y agoI like how code in both Python and Lisp can often look similar despite different syntaxes, different conventions, and different philosophies. Here is a toy example of file I/O in Python 3: with open('foo.txt', 'w') as f: print('hello, world', file=f) with open('foo.txt') as f: print(f.readline()) Here is a similar example in Common Lisp: (with-open-file (f "foo.txt" :direction :output :if-exists :supersede) (format f "hello, world~%")) (with-open-file (f "foo.txt") (format t "~a~%" (read-line f))) This example is a bit contrived to show the similarities. Real and idiomatic code may not look so strikingly similar. But similarities in concepts, constructs, and structure of code emerge in both languages. In fact the article mentions, "Take a Lisp program, indent it properly, and delete the opening parens at the start of lines and their matching close parens, and you end up with something that looks rather like a Python program."
- lmm 8y agoAre they really any more similar to each other than to any other random language? E.g. Java: try(Writer f = new PrintWriter("foo.txt")) { f.println("hello, world"); } try(BufferedReader f = new BufferedReader(new FileReader("foo.txt"))) { println(f.readLine()); }
- sametmax 8y agoThe difference here is that you don't need to know the name of the types of all the things, nor write them. Or wrap an object in another object.
- lmm 8y ago> The difference here is that you don't need to know the name of the types of all the things, nor write them. I believe the latest version of Java would allow "var", fwiw. > Or wrap an object in another object. True. The java standard library's I/O functionality is quite low-level, perhaps excessively so. In practice there are libraries that give a more lightweight/high-level interface.
- pieterr 8y agoSince the Japanese translation was done in 2002, I doubt this article originated in 2008 as is currently mentioned. [1] http://www.unixuser.org/~euske/doc/python/python-lisp-j.html http://www.unixuser.org/~euske/doc/python/python-lisp-j.html
- dang 8y agohttps://web.archive.org/web/*/http://norvig.com/python-lisp.html https://web.archive.org/web/*/http://norvig.com/python-lisp.... has 2000 so we can go with that.
- rauhl 8y agoThis seems to be a good excuse to share this great story: > At ILC 2002 former Lisp giant now Python advocate Peter Norvig was for some reason allowed to give the keynote address like Martin Luther leading Easter Sunday mass at the Vatican and pitching Protestantism because in his talk Peter bravely repeated his claim that Python is a Lisp. > When he finished Peter took questions and to my surprise called first on the rumpled old guy who had wandered in just before the talk began and eased himself into a chair just across the aisle from me and a few rows up. > This guy had wild white hair and a scraggly white beard and looked hopelessly lost as if he had gotten separated from the tour group and wandered in mostly to rest his feet and just a little to see what we were all up to. My first thought was that he would be terribly disappointed by our bizarre topic and my second thought was that he would be about the right age, Stanford is just down the road, I think he is still at Stanford — could it be? > ‘Yes, John?’ Peter said. > I won’t pretend to remember Lisp inventor John McCarthy's exact words which is odd because there were only about ten but he simply asked if Python could gracefully manipulate Python code as data. > ‘No, John, it can’t,’ said Peter and nothing more, graciously assenting to the professor’s critique, and McCarthy said no more though Peter waited a moment to see if he would and in the silence a thousand words were said. from http://smuglispweeny.blogspot.com/2008/02/ooh-ooh-my-turn-why-lisp.html http://smuglispweeny.blogspot.com/2008/02/ooh-ooh-my-turn-wh...
- kennytilton 8y agoStrange that six years into my Lisp-hood I could not recognize the great one. Or the great beard: https://www.independent.co.uk/news/obituaries/john-mccarthy-computer-scientist-known-as-the-father-of-ai-6255307.html https://www.independent.co.uk/news/obituaries/john-mccarthy-... It never changed!
- flavio81 8y ago>Strange that six years into my Lisp-hood I could not recognize the great one. God disguises in mysterious ways... RIP John McCarthy
- Phrodo_00 8y agoBTW, Python can do that [1], it's just not very recommended because the ast is not stable between versions (and maybe even implementations? not sure about that) [1] https://docs.python.org/3.6/library/ast.html https://docs.python.org/3.6/library/ast.html
- mattlondon 8y agoObligatory: "Dude, where's my car?"
- didibus 8y agoI wish all languages were Lisps. Code as data, partial functions, higher order functions, everything is an expression, and recursive evaluation. That's the basis, and I wish more languages had a similar foundation. Now, the article details Python sharing a lot of features with Common Lisp, often just called Lisp. Which is true, but the foundation is very different.
- norvig 8y agoSome points: - Yes, the original publication year was 2000. I've added that to the file. - @HelloNurse: You've got the key point. I provided Lisp code to teach AI; but my goal was to teach AI, not Lisp. As more schools and students were familiar with Python and not with Lisp, I needed to make the switch to keep teaching AI effectively. - @jonathanstrange: Yes, "batteries included" is key to Python; there is some pain in doing any change; this page attempted to alleviate some of the pain. - @rauhl: "in the silence a thousand words were said". I'm not sure what words are in that silence. But to me, the words are: Lisp and Python are different ecosystems with different customs. The Lisp community likes to solve lots of problems with macros. The Python community doesn't. For 95% of the usages, neither approach is better than the other, they are just different. For example, in Python, `with` is a statement, and you define custom classes for each usage you think of. In Lisp, you define a macro like `with-open-file` for each usage. The end result in usability and efficiency is similar. In Lisp, you often define macros for custom data types, e.g. (def-tree T1 root (A B C) A (D E) B (E F) ...) In Python you use a combination of built-in data types (like dicts), custom classes, and ad-hoc parsers of text. Again, the approach is different, but readability and efficiency is similar. It is certainly true that if you want to define, say, a mock Prolog system, it is easier to do it in Lisp with macros than in Python, where you would need to deal with the far messier `ast.parse` module. Is that where the silent words were? For me the words would be "Lisp is a much better choice if your primary goal is defining a full-blown domain specific language. For most other programming tasks, the two languages offer similar functionality in different way."
- kennytilton 8y agoWas McCarthy even thinking of macros when he locked onto code as data? Or was he thinking code generation in pursuit of AI?Asking, do not know. I know macros are a great example of code=data, but I once had a ball using the AllegroStore CLOS database and a homebrewed DB synch layer to handle remote distribution and update of forms and the code to validate them in a clinical drug trial management context, where forms and their validation code are forever changing. Basically, an intractable software maintenance problem just disappeared. That's always fun. http://smuglispweeny.blogspot.com/2008/03/my-biggest-lisp-project.html http://smuglispweeny.blogspot.com/2008/03/my-biggest-lisp-pr...
- deleted 8y ago[deleted]
- kbp 8y agoOne distinction between Lisp and Python's docstrings that he didn't mention is that in Lisp, you can (and it's normal to) give docstrings to variables; you can then look these up later with DOCUMENTATION or however else you read docstrings: CL-USER> (documentation '*print-readably* 'variable) "If true, all objects will be printed readably. If readable printing is impossible, an error will be signalled. This overrides the value of *PRINT-ESCAPE*." CL-USER> (documentation '+ 'variable) "the value of the most recent top level READ" CL-USER> (defvar *variable* nil "a variable") *VARIABLE* CL-USER> (documentation '*variable* 'variable) "a variable"
- kennytilton 8y agoMethinks the enumeration of "Lisp's essential features" a tad short. 1. Coding JS quite a bit these days, I greatly miss every form returning a value. 2. Python's lambda is just sad, and GvR keeps threatening to remove even that. And people, please, once and for all, 3. those parentheses and where we put the operator are absolutely essential to the Lisp experience.
- kennytilton 8y ago4. Lisp indents itself. This alone speaks volumes. That said, credit where due, Python code does look great.
- fulafel 8y agoRe 2 - are you bothered by the fact that there is this thing that Python calls lambda, and it would be fine if it was called exprfn or something? Or do you think there is really a big problem with using def in the would-be-lambda's scope to give a temporary name for the function?
- kennytilton 8y agoPython's lambda was pretty sad last I looked. Has it caught up with Lisp/Clojure's? And has the BDFL stopped trying to eliminate it altogether? I heard he regretted adding it and wanted to yank it at some point. The D in BDFL looks a lot bigger than the B.
- fulafel 8y agoPython's lambda is unchanged, and it is still included. I have the impression that Guido regrets adding it because of the language-design-aesthetic wart - the recurring "why is it called lambda when it can only define single-expression functions?" "you can just use def in the scope just before use, if you need statements" "but then it's not anonymous!" "just use a temp name" dialog loop.
- kennytilton 8y ago
- madmax96 8y agoI was reading the Lisp code and thinking "why wouldn't this evaluate to (S)?" And, of course, it does. The invocation of the lisp program should be: (generate 'sentence)
- deleted 8y ago[deleted]