New to Python: Features

Andrew Dalke adalke at mindspring.com
Tue Oct 5 05:22:14 EDT 2004


Alex [on tail call elimination]:
> My use case for this was
> the nightmare of 'recursion limits exceeded' for a nevow page with a few
> hundred deferreds -- they got (implicitly, by the framework) chained to
> each other by tail call (for termination purposes), 

Don't know enough about Nevow to comment.  Someone else
pointed out an existing bytecode hack to support this
so you might not need to wait.

> I was very used to workspaces back in the days of APL and I still miss
> them.  Why is it good not to have them?

I've never used such a system so this is only second hand.
I recall hearing that in Smalltalk people end up customizing
an image, which makes is harder for different people to work
together on the same project.

I think of it as working on a Python installation where
I've installed more and more packages over time so when
I start working with a new Python (working on a new
machine, or upgrading to 2.4) I've got to reinstall
everything to get my software to work again.  Only worse
because in a workspace there might not be an independent
source for a function I hacked together months ago
that I end up using often.


>>Try Perl or Ruby instead.
> 
> 
> Not Ruby!  That's a _good_ language:
> 
> kallisti:~/cb/cha/tex/cba alex$ ruby         
> 2+"23"
> -:1:in `+': String can't be coerced into Fixnum (TypeError)
>         from -:1
 >
> to perpetrate such horrors, he definitely wants Perl.

Methods of builtin types can be changed in Ruby.  To
get the OP's desired behavior is simple:

class Fixnum
   alias_method :old_plus, :+
   def +(other)
     if other.instance_of?(String)
       return self + other.to_i
     else
       return old_plus(other)
     end
   end
end

print "add ints: ", 8 + 7, "\n"
print "add int and string: ", 2 + "23", "\n"


% ruby tmp.rb
add ints: 15
add int and string: 25
%

Personally I think the ability to do this is a horror,
precisely because it leads to the horrors you talk about.



> Not sure what docs (besides Python Cookbook and Python in a Nutshell)
> one would have to read to find this answer -- differently from most
> other questions he's asking, this one's hardly obvious from docs...

And I think I pointed it out to you in c.l.py 3 or 4
years ago ;)

> I agree with you that it does, though not as well as you appear to
> believe (e.g. no `` 2 + "23" '' abominations in Ruby, either).

Unless one wants it.  That's why I think Ruby is a better fit
for the OP -- it lets him change the language much more to
meet his expectations than Python does.

				Andrew
				dalke at dalkescientific.com



More information about the Python-list mailing list