473,800 Members | 2,475 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 28780
ph************* @gmail.com wrote:
Then bring in more statement and you either have to
remember precedence rules (I can never remember those) or add some
parenthesis (oops!).
Probably you've been burned by C, which has a
ridiculously large number of precedence levels --
I don't know *anyone* who can remember them all.
Most people just remember a subset and use
parens for everything else.

Pascal had four levels, which was easy to remember
but not really enough. About six or seven seems
optimal to me.

Python, incidentally, has rather too many (it
seems to have caught this disease from C).

--
Greg
Dec 16 '06 #731
André Thieme wrote:
The <=is called cmp in Python.
In Lisp it is called signum. The Lisp function has in general the
advantage that it keeps type information.
While Pythons cmp returns either -1, 0 or 1 the Lisp version can
also return -1.0 and 1.0 and also complex numbers:
(signum #C(10 4)) = #C(0.9284767 0.37139067)
Unless you can use it to compare arbitrary types
such as two strings or two lists, it's not really
the same thing as Python's cmp.

Python 2.3 (#1, Aug 5 2003, 15:52:30)
[GCC 3.1 20020420 (prerelease)] on darwin
Type "help", "copyright" , "credits" or "license" for more information.
>>cmp("hello" , "world")
-1
>>cmp([1,3], [1,2])
1

--
Greg
Dec 16 '06 #732


greg wrote:
Ken Tilton wrote:
>I did explain the last little fun bit (where reverse code miraculously
got a case-specific "signed-value" parameter bound to exactly the
right bit of math structure).


I didn't mention that because it was addressed by
another poster. The signature of the user's reverse
function can be made extremely flexible if you have
the foresight to define it as something like

def reverse(resx, opnd, **kwds):
...

Then you can later change it to

def reverse(resx, opnd, signed_value, **kwds):
...

and any existing reverse functions will just absorb
and ignore the extra argument.

However, rather than add an ever-increasing number
of arguments to the signature, I think I would do it
a different way: pass a single object with attributes.
For the want of a better name, let's call it "env"
for "environmen t". The signature is then

def reverse(env):
...

and the body can refer to env.resx, env.opnd,
env.signed_valu e, or whatever else is required.
Looks promising. How does a generic engine that sees only a solution (a
list of mathematical expressions and for each the transformations ,
results, and opnds logged by individual TF functions) build up this
environment such that it has named attributes such as signed-value?
Assume that it can examine all those opnds and results looking for
tagged values such that it then knows the name of those values that have
been named.

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
Dec 16 '06 #733
Ken Tilton schrieb:
Looks promising. How does a generic engine that sees only a solution (a
list of mathematical expressions and for each the transformations ,
results, and opnds logged by individual TF functions) build up this
environment such that it has named attributes such as signed-value?
Most likely it doesn't since there is no such engine. Instead local
rules and combinators are encoded in classes. Hence there is nothing
but an object tree and actions are threaded through recursive method
calls.

This implies that the generic reverse function is just the dual of a
method call:

def reverse(expr):
return expr.reverse()

What expr does depends on the internal representation encoded in the
class of expr. This also implies that not only the form of the
expression is significant but also its ( dynamic ) type.

Dec 16 '06 #734
Paul Rubin wrote:
Kirk Sluder <ki**@nospam.jo bsluder.netwrit es:
>Personally, I've always preferred use the imperative to describe
basic math rather than the passive. This would seem to map better to
RPN than infix.

For writing down complicated, nested expressions too? That's very
unusual. E.g.

n! = (n/e)**n * sqrt(2*pi*n) * (1 + (1/12n)) * ...

vs. the same thing in Lisp notation, and that's not even so complicated.
Yes, infix is better ( and note that Math uses primarly infix notation for
common operators ) because you have a clear view of the evaluation tree
that way. With prefix or postfix notation, you need to parse the full
expression to find what goes to the first parameter of that +, and what
goes to the second parameter.

I would say that prefix/postfix is somewhat easier to write, but that infix
is far far far easier to read.

Dec 16 '06 #735
greg ha escrito:
I don't know about the other Pythonistas in this
discussion, but personally I do have experience with
Lisp, and I understand what you're saying. I have
nothing against Lisp parentheses, I just don't agree
that the Lisp way is superior to the Python way in
all respects, based on my experience with both.
Parentheses have two advantages over identation. First is they can be
used both inline and block.

The inline (a b (c d (e f g))) needs to be formatted in several Python
lines. Therein SLiP (Python) got problems for inline mixed markup but
LML (LISP) or SXML (Scheme) do not.

Second is that i do not need special editors for writting/editting. It
is more difficult to do identation and editing by hand in 'Notepad'
that adding parens from keyboard[*].
[*] Tip. Type always () and next move your cursor inside ( _ ). You
never forget a closing ) this way!

Dec 16 '06 #736
Paul Rubin wrote:
me******@gmail. com writes:
a = 'hello'
a[0] = 'H' # attempt to change first letter to upper case
As CLPython mirrors Python semantics, this results in a TypeError. The
internal representation of an immutable Python string is a mutable Lisp
string, but there is no way you can actually modify it from within CLPython.

How do you manage that? The compiler can't check. Is there some kind
of special dispatch on the assignment statement instead of turning it
into a setf?
Indeed, the assignment of subitems is dynamically dispatched, and
always goes via __setitem__ methods, as specified in the language. The
__setitem__ methods for strings and tuples raise exceptions. The ones
for lists and vectors could be translated into a simple (setf (aref ..)
...) and (setf (nth ..) ..), unless the index is actually a slice and
actually a subsequence must be replaced.

Now, the above description using __setitem__ methods is how it
apparently works, as observed from the outside. Internally there is a
generic function (setf py-subs) that does the work itself, skipping the
lookup and calling of __setitem__, if the object is a vector or dict.
(The user can call x.__setitem__ explicitly, so that method must exist
internally.)

Maybe you were thinking that CLPython, given Python code, outputs a big
pile of self-contained equivalent Lisp code that can be run
independently, and then CLPython is finished. Instead, only a small
amount of Lisp code is generated, but that code can only be run when
the CLPython environment is loaded. The generated code refers to that
environment, e.g. s[0] = 'x' is translated into a call to (setf
(py-subs ..) ..), and function (setf py-subs) is part of the CLPython
environment that must be loaded at run-time.

If you compile a Python function, the result is a (mostly) normal Lisp
function - its origin from the Python world does not really matter.
Also, all Python data structures are first-class Lisp data. Thus
CLPython objects live happily together with "normal" Lisp objects in
the same image.

And now we arrive at the most exciting part: other Lisp libraries can
be loaded in the same image, and we can create connections. Like, after
loading CLIM and defining how CLPython objects should be presented, we
should get a Python interpreter where classes are displayed graphically
and where you can inspect and modify them by mouse. Imagine that you
have interactively added a method to a class by dragging a function to
a class, then being able to right-click and select "write method",
which will write the definition of the method in the right place in the
class definition source code in your Climacs (CLIM-based Emacs) buffer.

That's the kind of features I have in mind, and the best thing is that
conceptually a lot of the work consists of connecting dots that already
out there. But as there are so many of them, a few extra pencils would
be quite welcome <wink>

- Willem

Dec 16 '06 #737
"greg" <gr**@cosc.cant erbury.ac.nz>
>
I once heard mention of a system of units in use at
one time with the odd feature that capacitance came
out in units of length.

Picture the scene: Hobbyist walks into Dick Smith
store and says "I'd like a 5cm capacitor, please."
This is correct - think of it as the number of electrons that
can dance on the surface of a sphere of radius r.

So your hobbyist will be handed a copper ball of 10cm
diameter...

Seriously, in electrostatic units, capacitance is measured
in length. (or it was when they were trying to teach me
Physics)

- Hendrik

Dec 16 '06 #738
greg schrieb:
André Thieme wrote:
> (aif (timeConsumingC alculation)
(use it))

I think the answer is that you just wouldn't do
that in Python at all. Having magic variables
spring into existence in your local namespace
as a side effect of calling something is just
not Pythonic. (It is very Perlish, on the other
hand.)

The closest you might come is using the new
"with" statement like this:

with aif(timeConsumi ngCalculation() ) as it:
use(it)

where the object returned by aif(x) has an
__enter__ method that raises an exception which
aborts the whole with statement if x is None,
thus avoiding executing the body. But that's
so horribly convoluted that any sane programmer
would just write it out the straightforward
way to begin with.
Sounds like "Blub" to me:
http://www.paulgraham.com/avg.html

I will quote some parts of it:

"You can see that machine language is very low level. But, at least as a
kind of social convention, high-level languages are often all treated as
equivalent. They're not. Technically the term "high-level language"
doesn't mean anything very definite. There's no dividing line with
machine languages on one side and all the high-level languages on the
other. Languages fall along a continuum [4] of abstractness, from the
most powerful all the way down to machine languages, which themselves
vary in power.

[...]

Programmers get very attached to their favorite languages, and I don't
want to hurt anyone's feelings, so to explain this point I'm going to
use a hypothetical language called Blub. Blub falls right in the middle
of the abstractness continuum. It is not the most powerful language, but
it is more powerful than Cobol or machine language.

And in fact, our hypothetical Blub programmer wouldn't use either of
them. Of course he wouldn't program in machine language. That's what
compilers are for. And as for Cobol, he doesn't know how anyone can get
anything done with it. It doesn't even have x (Blub feature of your
choice).

As long as our hypothetical Blub programmer is looking down the power
continuum, he knows he's looking down. Languages less powerful than Blub
are obviously less powerful, because they're missing some feature he's
used to. But when our hypothetical Blub programmer looks in the other
direction, up the power continuum, he doesn't realize he's looking up.
What he sees are merely weird languages. He probably considers them
about equivalent in power to Blub, but with all this other hairy stuff
thrown in as well. Blub is good enough for him, because he thinks in
Blub.

When we switch to the point of view of a programmer using any of the
languages higher up the power continuum, however, we find that he in
turn looks down upon Blub. How can you get anything done in Blub? It
doesn't even have y.

By induction, the only programmers in a position to see all the
differences in power between the various languages are those who
understand the most powerful one. (This is probably what Eric Raymond
meant about Lisp making you a better programmer.) You can't trust the
opinions of the others, because of the Blub paradox: they're satisfied
with whatever language they happen to use, because it dictates the way
they think about programs."

André
--
Dec 16 '06 #739
André Thieme <ad************ *************** *@justmail.dewr ites:
Sounds like "Blub" to me:
http://www.paulgraham.com/avg.html
It never occurs to Lisp programmers that Lisp, too, might be a Blub.
Dec 16 '06 #740

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

Similar topics

14
2194
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
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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
10505
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
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
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...
1
4149
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
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.