merits of Lisp vs Python

?

=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=

Maybe so. But I've only ever appreciated its functional aspects. I
But CLOS is the best OO there is. The OMG said so. It can do anything
any other OO can do. Why /specifically/ would you not use it? This type

Specifically it does not have name spaces. Therefore it is
fundamentally flawed and cannot be used as a serious object-oriented
tool for developing complex applications. However, I'll give you that
it is pretty nice for pet-projects and educational purposes (counting
parenthesises). But for some, that is more than enough.
 
B

Bill Atkins

Paul Rubin said:
What have you got for concurrency? How would you write a
multi-threaded web server in Lisp?

Multithreading is not a standard part of ANSI CL, but in practice all
Lisps (with the major exception of the CLISP implementation) support
threading.

Hunchentoot is, in fact, a multi-threaded web server written in Lisp.
:) There are also others, like AllegroServe and Araneida.

There are compatibility layers that smooth over some of these
implementation-dependent areas of Common Lisp. Bordeaux-threads is
the package that provides a common interface to the different
threading implementations:

http://trac.common-lisp.net/bordeaux-threads/wiki/ApiDocumentation
 
S

Steven D'Aprano

You are just being silly.
Lisp's OO environment CLOS is vastly superior to Python classes.
Both in terms of expressive power and flexibility.

Oh, well, with evidence like that, I'm convinced!

Python is fine if you approach programming as Lego, simply gluing
together libraries.
But if you want to do some serious algorithmic's you may find that it is
just to slow.

Nobody ever said that Python was idea for serious number crunching
(although see numpy -- use the right tool for the job). If I knew what
sort of "serious algorithmics" you meant, I could comment.
 
?

=?ISO-8859-1?Q?Andr=E9_Thieme?=

Ken said:
The last time we went thru this a Pythonista finally said, Oh, I get it.
These five lines of code I have to write all the time (two setup, one
func call, two cleanup) can be collapsed into one or two. The thread
will be hard to miss in Google groups (two years back?) and the epiphany
appears right at the end of the thread. <hint>

Functional programming is the solution here, not Lisp.

You could make that with a new function (in Python), that takes a
function (and its args, don't remember the correct syntax).

def foo(function, args):
setup(1)
setup(2)
function(args)
cleanup(1)
cleanup(2)


The nice thing in Lisp would now be to save a lambda with the macro.
In Python one would fill the name space with throw away functions that
get called only one time.


André
--
 
A

Aahz

I think an editing program that balances parens automatically is near
indispensible for writing Lisp code. I can't stand writing Lisp
without Emacs.

And that is why I will never write Lisp. I loathe Emacs.
 
S

Steven D'Aprano

1> '(especially if they start young enough)
(ESPECIALLY IF THEY START YOUNG ENOUGH)
2> (sixth *)
ENOUGH

... said!

Yeah, so /unlike/ written natural languages!

What a fucking moron.


Oh my god! Lisp can echo STRINGS to the interpreter???? Why didn't
somebody somebody tell me that!!!! That *completely* changes my mind about
the language!

I'm especially impressed that it knew I wanted them printed in uppercase
without being told.
 
T

tac-tics

I think the lesson here is that LISP is the language you use when you
want mathematical elegance and perfection and Python is the language
you use if you want to actually program stuff.
 
K

Ken Tilton

André Thieme said:
Functional programming is the solution here, not Lisp.

No, you do not understand. The Pythonista figured it out: a function
would not do.
You could make that with a new function (in Python), that takes a
function (and its args, don't remember the correct syntax).

def foo(function, args):
setup(1)
setup(2)
function(args)
cleanup(1)
cleanup(2)


The nice thing in Lisp would now be to save a lambda with the macro.
In Python one would fill the name space with throw away functions that
get called only one time.

Omigod. Is that what you meant? You think macros are unnecessary because
one could hard-code their expansions as separate functions? And that
would constitute hiding the boilerplate? What happens when the
boilerplate changes? <game over>

ken

--
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
 
?

=?ISO-8859-1?Q?Andr=E9_Thieme?=

Ken said:
No, you do not understand. The Pythonista figured it out: a function
would not do.

What do you mean?


Omigod. Is that what you meant? You think macros are unnecessary because
one could hard-code their expansions as separate functions? And that
would constitute hiding the boilerplate? What happens when the
boilerplate changes? <game over>

Well, macros are unnecessary from a mathematical point of view: 0 and
1 are enough. But of course they have the potential to be a real time
saver. What I want to say is: the situation you gave as an example is
not the place where macros shine, because 1st class functions can take
over.

You could maybe give another example: how would one realize something
like (memoize function) in Python?
Or (defmethod name :after ..)?


André
--
 
K

Ken Tilton

André Thieme said:
What do you mean?

I am saying use Google groups to find the thread and find out the use
case contributed by a Pythonista in the midddle of a similar thread that
conveyed to his satisfaction the value of macros.

ken

--
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
 
P

Paddy

Paul said:
Anyway it's pretty lousy advocacy for a language to say "well if the
language is too slow, don't use it, use another langauge like C instead".

Python can be used as a glue language. It is not solely a glue
language.
A lot of people find using Python to script libraries written in other
languages
a way to get things done. Ask the scipy guys or the biopython guys.
The Python community actively encourages groups writing useful
libraries
to maintain a Python port, or Python users might wrap libraries
themselves.

You don't always wrap a module in Python for reasons of speed of
execution.
Software testing may well be easier to do in Python than in the
native language of the wrapped library. The library itself may be
better
used in the dynamic environment of Pythons command line; or used
together
with other libraries already wrapped for/accessible from Python.

- Paddy.
 
J

John Thingstad

Oh my god! Lisp can echo STRINGS to the interpreter???? Why didn't
somebody somebody tell me that!!!! That *completely* changes my mind
about
the language!

I'm especially impressed that it knew I wanted them printed in uppercase
without being told.

Except it is not a string. It is a list of symbols. Hence the upcase.
"This is how you write a string in Lisp"
and that does preserve case.
(If you want symbols to be case sensitive and default case to be lower
then most
Lisp's allow that, but the ANSI spec dosn't give a standard way.)
 
P

Paul Rubin

tac-tics said:
I think the lesson here is that LISP is the language you use when you
want mathematical elegance and perfection and Python is the language
you use if you want to actually program stuff.

That's really a misperception. Lisp is extremely pragmatic in
addition to traditionally having more mathematically oriented
developers and users. There is a saying that Lisp is a ball of mud;
you can throw whatever you want into it and it's still Lisp. Python's
current implementations and the supposedly fancy Python applications
that I've heard of are toys compared to what's been done in Lisp even
on the much smaller machines of decades gone by.

What I'd say is that the most interesting period of Lisp development
was probably the 1970's and 1980's, trailing off into the beginning of
the 1990's. Since then Lisp has gotten kind of stultified, although
one of the cll posters claims there's now a revival going on (maybe
true). It seems to me that many Lisp users and developers moved on to
the ML family in the 1990's and maybe have been moving from ML to
Haskell in more recent times.
 
P

Paddy

Mark said:
How do you compare Python to Lisp? What specific advantages do you
think that one has over the other?

Note I'm not a Python person and I have no axes to grind here. This is
just a question for my general education.

Mark

NOBODY expects the Lispers Inquisition!
Our chief weapon is age... age and macros...
....macros and age.
Our two weapons are age and macros....
And mathematical rigour...
Our THREE weapons are age, macros, and mathematical rigour...
....And an almost fanatical belief in Lisps superiority.
Our *four* ...no.
AMONGST our weapons...
Amongst our weaponry...
....Are such elements as fear, surprise.... I'll come in again.



Python is fun to use.
Easy to read.
Simple and powerful.
Easy to test.
Easy to maintain.
Fast. Very fast!

- Paddy.
..
 
P

Paul Rubin

Paddy said:
Python can be used as a glue language. It is not solely a glue
language.
A lot of people find using Python to script libraries written in other
languages
a way to get things done. Ask the scipy guys or the biopython guys.

Sure, connecting together programs and libraries that were written in other
languages is what a glue language is.
You don't always wrap a module in Python for reasons of speed of
execution.

Software testing may well be easier to do in Python than in the
native language of the wrapped library. ...

That's the thing, those modules are written in languages other than
Python because Python is not attractive for coding those functions
directly in Python. That is a real weakness of Python and glossing
over it by saying to write the functions in other languages and then
wrap them in the C API is not a very impressive answer. For example,
Lisp is routinely used for writing scientific and numerical code
directly with performance comparable to C or whatever. There is no
need to mess with wrapping modules written in other languages, an
operation which should not be trivialized.
 
S

Steven D'Aprano

The question I have is why do critics
single out macros and not other forms of abstraction such as
objects, packages, libraries, and functions?

Who says they do? All forms of abstraction have been criticized. Sometimes
the criticism is valid. Sometimes it warns against abuses of the
abstraction. Just because a feature is useful sometimes doesn't
necessarily mean the benefit outweighs the cost.

just as an example:
from foolib import *
bar.bar("somefile")

What does this program do? I have no idea. Its functionality is
hidden behind multiple layers of abstraction (function, object,
library.)

Sure.

But at least you know that foolib is a module or package. You know what
from and import do, and that can't change. And you know that bar is an
object with a method also called bar, it is being called, and the
argument is a string "somefile". Those things can't change. Imagine a
hypothetical language where those two lines could mean *anything*.

Rightly or wrongly, people fear that Lisp's macros push Lisp closer to
that hypothetical anything-goes language than is healthy. Maybe that's a
problem of perception rather than a problem of fact, but you have to ask,
why do people perceive Lisp that way?

Could it be because of people like J Shrager who writes things like this?

"Can't you just expand the language via macros to create whatever facility
of this sort [major new features with new syntax] you need..."

(This thread, dated 8 Dec 2006 16:14:44 -0800)

Or Wolfram Fenske:

"All the interesting features that haven't originated from Lisp (e. g. OO
from Smalltalk) could in turn easily be implemented in Lisp with a couple
of macros."

(This thread, dated 8 Dec 2006 23:38:02 -0800)

To someone outside of Lisp, that looks like "I can make Lisp look like any
language I like in just a few lines." And that implies that to read a Lisp
program, one might need to be able to read code that looks like Lisp, or
Smalltalk, or Prolog, or Fortran, or all of those, or whatever bizarre
syntax the developer wanted it to look like.

My point isn't whether or not their claims are correct (a "couple" of
macros? really?) but that things like this feed the perception that Lisp
is close to that hypothetical language where anything could be anything.
If anything could be anything, do you really know what (+ 1 2) means
without reading every line of code?

And it isn't really that much comfort to be told that good Lisp
developers know not to do stupid things with macros. Sure. But in the real
world of programming, most developers aren't good developers, they are
merely average -- in fact fifty percent of them are below average. And
the bottom 30% can't be trusted with facilities like Lisp's macros,
because they WILL do stupid things with them and turn your code base into
a morass of shifting syntax, buggy DSLs and other maintenance nightmares.
The damage they can do with operator overloading is minor by comparison.

Even something simple like file I/O can be abused. Example: I've seen
*real* code where somebody needed a dict with ten million keys. (Well, he
thought he needed that dict, I never worked out exactly why. Maybe he
thought he was pre-allocating memory as an optimization.) So he started
off with something like this:

def make_dict():
mydict = {}
mydict[0] = 0
mydict[1] = 0
mydict[2] = 0

and realised that it would take him forever to write that much code. So
he wrote a C program to create the make_dict function for him! Translated
into Python:

def make_dict_factory():
code = open('makedict.py', 'w')
code.write("def make_dict():\n")
code.write(" mydict = {}\n")
for i in range(10000000):
code.write(" mydict[%d] = 0\n" % i)
code.write(" return mydict\n")
code.close()
from makedict import make_dict
return make_dict

(This is an interesting demonstration that any language that allows file
I/O and importing of external program files can always treat functions
as data, even if the language doesn't directly support it. An alternative
would be to keep the strings in memory instead of writing to a module,
then use exec on them instead of importing the module.)

Honest to god, the code really was like that! Maybe I've got the precise
details wrong, it was a long time ago, but if it wasn't just as I've got
it, the consequences were the same: he built a single function that was so
large that loading it caused his machine to thrash for twenty minutes
trying to free enough memory.

Is that an argument against factory functions? Damn straight it is:
they are a powerful tool, and in the hands of morons, they can be
dangerous. Does that mean that languages shouldn't permit higher-order
functions? Not necessarily: all programming tools can be misused, but some
can be misused more easily than others. Power and risk is often a
trade-off, and language designers can't eliminate all risk of stupid
behaviour, but they can design the language to allow whatever level of
risk they believe is acceptable. (E.g. there is no doubt that C's raw
pointers are powerful, but many languages deliberately don't use them.)

The risk of stupid factory functions is small compared to the benefit, but
maybe there is some domain somewhere where the ideal solution is a
language that DOESN'T treat functions as first class objects, deliberately
weakening the language so that a particular class of errors (or stupid
behaviour) just cannot happen. But that language isn't Python.

When it comes to Lisp's macros, the perception is that the power is
correspondingly greater, and the risk of abuse even more so. The safe
examples of what macros can be used for don't seem to provide any
over-whelming advantage (that's not to say they provide NO advantage,
merely that if you use macros safely, the advantage seems small, but if
you use them to their full potential, the risk of abuse is too high).
That's the perspective of many people, and maybe it is wrong. Maybe you
really need to be immersed in Lisp for a while to see the advantages of
macros.

Or maybe it is only an advantage while Lisp programmers are a
self-selected group of above-average skill. Wait until fifty million VB
code monkeys start writing Lisp macros and maybe, just maybe, you'll wish
they were using a less powerful and more restrictive language.
 
G

greg

Bill said:
And mistakes in nesting show up as mistakes in
indenting.

Er, hang on a moment... how do you *know* when you've
got a mistake in indending? You must be visually
verifying the indentation... rather like one does
with Python code...
 
S

Steven D'Aprano

Personally, I find it strange that we, who argued so many times for
dynamic typing, the need for expressiveness and that it is OK to trust
the programmer with power ("we are all adults here" argument) while
arguing against relatively restrictive languages like Java find macros,
a chaotic and disruptive concept.

Why? The benefit of expressiveness and power isn't monotonically
increasing. Look at us: we're all communicating in a common language,
English, and we all agree on syntax and grammar. Now, I could be a lot
more expressive, and language could be a lot more powerful, if I could
define my own language where "You are a poopy-head" was in fact a detailed
and devastatingly accurate and complete explanation for why Python was a
better language than Lisp. You, however, not being an expert in my far
greater expressive language, would see none of that, and would be under
the mistaken impression that I was insulting you.

So it is good that English restricts the expressiveness and power of the
syntax and grammar. While we're talking English, we can both understand
each other, and in fact people who redefine words and ignore the common
meaning of them are often covering weaknesses in their arguments.

The same goes for programming languages. Extra expressiveness comes at the
cost of reduced communication between programmers -- the code becomes
harder to read for those who haven't already learnt how to read it. So
there is no contradiction in the positions that "we are all adults here"
and "macros give too much power". The first is a design decision, the
second is a trade-off, just like the lack of C-style pointers in Python is
a trade-off.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top