473,768 Members | 2,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

merits of Lisp vs Python

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

Dec 8 '06
852 28613
Steven D'Aprano <st***@REMOVE.T HIS.cybersource .com.auwrites:
>something like:

control_code = connection.read _next_control_c ode()
if control_code == +break+:
connection.kill ()
throw blah
else if control_code == +status+:
connection.send _status_summary ()
else if control_code == +noop+ || control_code == +keep_alive+:
else:
error "CONTROL_CO DE fell through conditional cascade; was not one of +BREAK+, +STATUS+, +NOOP+, +KEEP_ALIVE+"

Your Python syntax is rather wonky, but that's incidental.
What is wonky about it? The use of +foo+ symbols from the Lisp? Is
there some particular bit of wonkiness you can point out that will
make me think you've done anything but intentionally misunderstand my
post?
Nine lines, including handling the case where control_code is none of the
four constants. Ten if you add the "pass" statement that it actually
needs. And it is completely self-contained, with no external functions or
macros to understand.

Saving one line of code, at the expense of having another block of code to
write or understand -- is that really the best example of what macros are
used for in practice? You don't really save writing any boilerplate code,
except for else clause, unless you're claiming that "if" and "elif" is
boilerplate. Fine, you claim them as boilerplate. I'm going to claim all
those unnecessary brackets as boilerplate.
We're not counting lines here, you goon. We're talking about how
expressive constructs are and how closely they match your concept of
what you want to do. The conditional example is lower-level; you're
talking to the interpreter instead of saying what you want to achieve.
You're having to repeat things because that's what the language asks
of you, instead of describing in a higher-level way what you're
actually doing.
Yes, I know the parser needs them. But as so many people keep telling me,
once you've been writing Lisp code for a month, you don't even notice the
brackets. That makes them unnecessary for the developer, and therefore
something the computer should handle on its own. You've already split
expressions with whitespace, why should you have to use brackets as well?
That's just boilerplate.
This simply means that the parentheses do not stand out. It doesn't
mean that they *literally* cease to become visible (unless I have
perhaps missed out on Lisp enlightenment).

Obviously, this doesn't mean that they are "unnecessar y." They are
necessary to give Lisp its regular structure, which 1) makes macros
possible, 2) allows easy movement through and automatic indentation of
code and 3) is aesthetically pleasant, which leads to easier
maintenance. Brackets are no more boilerplate than the significant
whitespace in Python is boilerplate (that is, they're not boilerplate
at all).
Okay, I'm impressed that ecase can pick up on the four constants being
tested against, and feed their names (rather than merely their values)
into an error message. Python has nothing like that, and if you only have
three or four things to test against, *and* they have names, that could be
a useful thing to do. And if I've understood correctly, that's more a
feature of Lisp's symbols than of macros.
But you haven't understood it correctly, of course. The only reason
this works is that the macro is passed the unevaluated code, which
still has the original symbols that the programmer used. It can
insert these into the generated code as it pleases. I feel that
should be clear to someone who claims to know as much Lisp as you do.
But if you're testing against fifty different values, well, is it really
useful for your error message to list all fifty names? Or do you have
another macro ecase-with-lots-of-tests?
Is it really useful? Yes, it is.
If that's the best example of what macros can be used for, frankly I'm
unimpressed. Yes, I can see some benefit. But I don't see that the benefit
is worth the added complexity. Maybe there are more complex tasks that
macros are better suited for.
Did you read the DEFINE-BINARY-CLASS macro I mentioned elsewhere?
Where did you get the notion that ECASE was the best example of where
macros can be used? Why am I responding to another of your absurd
posts?
Dec 10 '06 #271
Bill Atkins <at****@rpi.edu writes:
maintenance. Brackets are no more boilerplate than the significant
Ack. Of course I mean "parenthese s."
Dec 10 '06 #272
Ken Tilton wrote:
George Sakkis wrote:
JS******@gmail. com wrote:

>1. Lisp is the only industrial strength language
^^^^^^^^^^^^^^^ ^^^^
You keep using that phrase. I don't think it means what you think it
means.

To me in part it means "no one can decide to take away lambda because
they decided they should not have put it in in the first place and then
change their mind and leave it in after I already put a few people on
de-lambdifying our 100kloc system because..."
Funny, coming from the guy with an inclination in discovering straw man
arguments in others. Python 3.0 should be at least a year away from
now, let alone the time of discussions about lambda. If you're changing
a working system based on brainstorms and speculations about a
backwards incompatible version to appear after two years or three, I
can't feel sorry for you :)
, and in part it means
compilation. And it /has/ to have macros. :)
Oh, and I had the vague impression that it was somehow related to
standards about bleeding-edge technologies, such as sockets. But then,
I could be wrong :)
Metaprogramming by definition cannot be obscure. Metaprogramming means
programming at a higher level.
Check.
A higher level means "more productive".
*Segfault* *core dump* *kernel panic* :)

No, it is more productive only if you (and the other 5, 10, 100 people
in your group) can understand, implement, debug, test and maintain code
in that higher level of abstraction.

The rest of the proof is therefore irrelevant ;-)
...which are
irrelevant to the vast majority of programmers.

You insult them by suggesting they cannot concieve at a higher level.
Mebbe they could if their language aupported it. Yours does not.
Actually it does. Metaclasses, descriptors, decorators are some high
level Python concepts. Most people are productive in Python for years
without ever having to write a custom metaclass, or even know their
existence (although a library or framework they use daily might in fact
use all of the above). Ever heard of Zope ? Even though it's written in
Python, it is criticised for its steep learning curve, one main reason
being its high level of abstraction.
I don't know if other lispers
would join you in your feeble attempt to steal a bite from Ruby's
current glory...

Of course we would. You do not get it. The only thing you guys are
bleating about is greater popularity. Now someone is about to eat your
lunch popularity-wise. Live by the poll, die by the poll. And you held
first place for like a week in language geologic time, taken down merely
because...
(mostly thanks to the admirable marketing around the
overhyped Rails framework)

... a little hype came along? Wow, your fundamental advantage must have
been about zip, and all derived from things unrelated to syntax. <gasp>
Well, for one thing we never held the first place anyway. Second, what
appears to be the big boost for Ruby today maybe its death sentence
tomorrow, ending up as a niche language for web apps, like PHP today.
With a large crowd undoubtly, but I bet most Pythonistas would prefer
lower popularity than ending up in a corner of the application
spectrum.
, but Ruby is much closer to Python than
either of them is to lisp. In fact, if Python suddenly disappeared,
Ruby would probably be my next stop. Both Ruby and Python are high
level dynamic languages with an emphasis on pragmatic needs, not being
the language of the God(s) (see, I can bring up stupid slogans of
languages too).

As Graham said, if some pretty good programmers are jumping up and down
about X, mebbe you should take a look at X. Even if assholes like me
piss you off. :)
Change that to "amuse me"; nothing better than a sense of
self-knowledge :) If you mean the same Graham that wrote
http://paulgraham.com/pypar.html, perhaps we don't disagree that much
after all :)

George

Dec 10 '06 #273
Paul Rubin <http://ph****@NOSPAM.i nvalidwrites:
"Wolfram Fenske" <in***@gmx.netw rites:
[...]
I just don't see a non-messy way to simulate Python generators in CL.
They can be done in Scheme using call/cc though.

Scheme is also a Lisp. So?

No I don't buy that, you can't say Scheme is Lisp when it suits you to
do so and that it isn't Lisp at other times.
OK, I cheated a bit. (Although when I say "Lisp" I don't necessarily
mean Common Lisp. Scheme is also Lisp.) You are right about call/cc
and probably also about lexical variables. I have to modify my
statement from "All the interesting features that haven't originated
from Lisp could easily be implemented in Lisp" to "A lot of the
interesting features ...". Assertions starting with "all" are a
dangerous business because usually someone comes along with a
counter-example. I should have been more careful when I wrote that.

What I meant to say with the two sentences "a lot of 'modern' language
features have originated from Lisp" and "a lot of the interesting
features that haven't originated from Lisp could easily be implemented
in Lisp" was that I believe that Lisp has hit a sweet spot in the
programming language continuum. It must have been right about a lot
of things to still be alive and kicking after all this time.

[...]
http://www.math.chalmers.se/~rjmh/Papers/whyfp.html

The examples in it are pretty easy to do in Python or Scheme, but I
think not so easy in CL.

Anything in particular? I'd be surprised if the solutions in Scheme
and CL would differ very much

I took it back,
Sorry, I only noticed that after posting.

--
Wolfram Fenske

A: Yes.
>Q: Are you sure?
>>A: Because it reverses the logical flow of conversation.
>>>Q: Why is top posting frowned upon?
Dec 10 '06 #274
Wolfram Fenske wrote:
Sure, you can shoot yourself in the foot with macros. But you can do
that in any language of any degree of expressiveness [3]. Come to
think of it, the whole reason why we use high level languages is
because of their expressiveness: We get stuff done faster and
introduce less errors. So "the more expressive, the better," right?
But according to you, there's a point when a language gets "too
expressive". I don't see why.
Is Qi Lisp? There are several problems:

1. Language design is so hard that most people get it wrong (e.g. Python).
What do you do when you find that your proprietary syntax extension was a
bad idea?

2. There is a trade-off between being expressive and sacrificing syntax.
Lisp is very verbose because you must write the AST for your code by hand,
even if you aren't exploiting s-exprs, EVAL and macros.

3. One could argue that every syntax extension in Lisp makes a new language.
So Lisp is a heavily forked language. Is that a good?

Maybe if you're a lone coder and an expert in language design then you can
knock up a DSL and halve your working time using Lisp. In industry, you're
more likely to hire four people with half the expertise each and restrict
them to a well-known C-like syntax.
>Now, if Lispers would say "Oh yes, macros give you great power, and
with great power comes great responsibility. Be careful." then, no
doubt, we'd take you guys more seriously.

Sure, it's a powerful tool but it's not *that* hard to use.
Look at all the threads in c.l.l where people have gotten confused by their
own macros. Look at the unboxing macro that Juho Snellman used to try to
get competitive performance for Lisp on my ray tracer benchmark:

(defmacro def ((name params &body body)
(mname &rest mparams)
(wname &rest wparams))
`(progn
(declaim (inline ,name ,wname))
(defun ,name ,params
(declare (type double-float ,@params))
,@body)
(defmacro ,mname ,(mapcar #'car mparams)
,(loop with inner = (list name)
with body = ``,',inner
with all-names = nil
for (form count) in (reverse mparams)
for names = (loop repeat count collect (gensym))
do
(setf all-names (append all-names names))
(setf body ``(multiple-value-bind ,',(reverse names)
,,form ,,body))
finally
(setf (cdr inner) (reverse all-names))
(return body)))
(defun ,wname ,(mapcar #'car wparams)
(,mname ,@(mapcar #'cadr wparams)))))

Note that this page of magic does something done by the compiler in most
other languages.
Maybe you're afraid of it because that it's something that's unique to
Lisp?
It isn't unique to Lisp. OCaml has camlp4, for example. It is very rarely
used, perhaps because the OCaml community is wary of syntax extensions or
perhaps because it is even harder to use than Lisp's macros.
But IMO the reason for that is not that they're too powerful. IMO it
has mostly to do with the fact that other languages' syntaxes make it
too difficult to implement Lisp-style macros.
I agree. However, the fact that other languages ship with sophisticated
syntax can also be a good thing: it can make them more concise, it can make
them more expressive (e.g. pattern matching).

I get the impression that Lispers use macros when they could use HOFs.
>But we don't hear that -- we hear Lispers going on and on about how
great it is that they can easily redefine every corner of the
language. Do you blame people for *believing them* and imagining
that reading Lisp code is like following some ghostly
will-o-the-wisp across a swamp, where nothing is what it seems and
the landscape is forever shifting?

Come on! You're telling me people don't learn Lisp because they are
afraid of it? Python allows you to redefine built-in functions, as
you said, Ruby allows you to attach new methods to live objects, but
Lisp is simply going too far?
The biggest activation barrier to using Lisp for me is having to write ASTs
for everything by hand. Perhaps it would be a good idea to include an
editor that allowed newbies to use a more familiar syntax and have it
converted to s-exprs for them, so they can see the correspondence and learn
how to write s-exprs themselves?
>Now, if you want to tell me that, despite all the talk, Lisp coders
don't actually create new syntax or mini-languages all that often,
that they just use macros as functions, then the question becomes:
why do you need macros then if you are just using them as functions?
Why not use functions?

Easy because macros are not functions. Functions allow you abstract
functionality, macros allow you abstract syntax.
While that is true, you've provided two examples to back up his point. In
another post you use the example of wrapping try .. finally which can be
done with a HOF instead of a macro. Next, you use the example of COND,
which can also be written as a HOF instead of as a macro:
Look at the examples
above. How would you implement conditional expressions as a function?
Answer: You can't, it's syntax.
That is not true. You can implement conditional expressions without
extending the syntax:

# let rec cond x rules default = match rules with
| [] -default
| (f, e) :: _ when f(x) -e
| _ :: t -cond x t default;;
val cond : 'a -(('a -bool) * 'b) list -'b -'b = <fun>

For example:

# cond 2
[( = ) 1, "one";
( = ) 2, "two";
( = ) 3, "three"]
"neither one, two nor three";;
- : string = "two"

Of course, this is pointless in OCaml because the built-in pattern matcher
is more expressive, powerful and faster than COND:

# match 2 with
| 1 -"one"
| 2 -"two"
| 3 -"three"
| _ -"neither one, two nor three";;
- : string = "two"

--
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/product...ex.html?usenet
Dec 10 '06 #275
Paul Rubin wrote:
>That is a deficiency of Python that doesn't exist in modern FPLs like
OCaml, SML, Haskell, F#...

Nothing stops you from re-using the same internal function name in
your Python code, like you might use "i" as a throwaway loop index in
several places in the same function. It's just like in Scheme...
It is not "just like in Scheme" if you don't have anonymous functions in
Python.

--
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/product...ex.html?usenet
Dec 10 '06 #276

ta**********@go oglemail.com schrieb:
A few months ago, I missed the Condition System most
when using Python, and also lexical scope. However, it is nice to work
with friends, who know Python and not Lisp.)
Could you explain in which way Python lacks lexical scoping?

Dec 10 '06 #277
Paul Rubin <http://ph****@NOSPAM.i nvalidwrites:
"Wolfram Fenske" <in***@gmx.netw rites:
>In Lisp, I could just write a macro "WITH-CONNECTION" that takes the
name of the connection variable and the code for "do something with
the connection" as arguments. Actually, I ended up writing something
like it as a function in Python:

--8<---------------cut here---------------start------------->8---
def withConnection( self, fun):
self.lock.acqui re() # ...

Do you know about Python's "with" statement? You'd define a class for
those db connections, that acquire the lock on entry, and release it
on exit.
Yes, I wrote about it in another post. It was introduced in Python
2.5. And if it hadn't been I'd still have to write code like this.

--
Wolfram Fenske

A: Yes.
>Q: Are you sure?
>>A: Because it reverses the logical flow of conversation.
>>>Q: Why is top posting frowned upon?
Dec 10 '06 #278
Wolfram Fenske wrote:
It must have been right about a lot of things to still be alive and
kicking after all this time.
No. Fortran and Lisp are just old, not better.

--
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/product...ex.html?usenet
Dec 10 '06 #279
Paul Rubin wrote:
Haskell is pretty neat in that it basically removes things like setq.
That makes possible (for example) very cool simplifications to
concurrent programming. See the paper "Composable memory transactions":

http://research.microsoft.com/~simon.../stm/index.htm

Yeah you could do that with Lisp by writing in a restricted style,
just like you could avoid pointer errors in C++ by writing in a
restricted style. But it's hard for the compiler to guarantee that
your program obeys the restrictions. You could write a language like
Ada or Java that makes a lot of guarantees, but is unexpressive and a
huge pain to program in. You can write a language like Lisp that's
expressive but doesn't make as many guarantees. Interesting problems
in language design arise in writing languages that are expressive AND
make guarantees.
I discovered this recently with F#. Although F# (as a dialect of OCaml) is
impure like Lisp, it does make purely functional programming easy and
provides many purely functional data structures. I translated 15kLOC of
mostly-functional OCaml code into F# and only had to add four locks to make
the whole library concurrent.

That is probably feasible in Lisp but not in Python...

--
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/product...ex.html?usenet
Dec 10 '06 #280

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2184
by: Paddy3118 | last post by:
This month there was/is a 1000+ long thread called: "merits of Lisp vs Python" In comp.lang.lisp. If you followed even parts of the thread, AND previously used only one of the languages AND (and this is the crucial bit), were persuaded to have a more positive view of the other language; (deep breath, this is a long, as well as grammatically incorrect sentence), THEN WHY NOT POST ON WHAT ARGUMENTS PERSUADED YOU.
0
9407
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10015
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7384
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3931
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3534
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.