Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [OFF] Python 2.4 released

Reply
Thread Tools

[OFF] Python 2.4 released

 
 
Zach Dennis
Guest
Posts: n/a
 
      11-30-2004
A coworker of mine came and hollarred at me because on /. it mentioned
that Python 2.4 was released...so I went to check it out.

I read the What's new section but isn't the majority of stuff they added
in 2.4 stuff Ruby already does?

(ruby does/has) 1 PEP 218: Built-In Set Objects
(ruby does/has) 2 PEP 237: Unifying Long Integers and Integers
(dont know) 3 PEP 289: Generator Expressions
(ruby does/has) 4 PEP 292: Simpler String Substitutions
(ruby does/has?)5 PEP 318: Decorators for Functions and Methods
(ruby does/has) 6 PEP 322: Reverse Iteration
(dont know) 7 PEP 324: New subprocess Module
(ruby dont have) 8 PEP 327: Decimal Data Type
(ruby dont have) 8.1 Why is Decimal needed?
(ruby dont have) 8.2 The Decimal type
(dont know) 8.3 The Context type
(dont know) 9 PEP 328: Multi-line Imports
(dont know) 10 PEP 331: Locale-Independent Float/String Conversions

Zach



 
Reply With Quote
 
 
 
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      11-30-2004
Hi,

In message "Re: [OFF] Python 2.4 released"
on Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <(E-Mail Removed)> writes:

|(ruby does/has) 1 PEP 218: Built-In Set Objects
We have. Not built-in, though.

|(dont know) 3 PEP 289: Generator Expressions
We have enumerator module.

|(ruby does/has?)5 PEP 318: Decorators for Functions and Methods
Partially.

|(ruby dont have) 8 PEP 327: Decimal Data Type
We have bigdecimal.

|(dont know) 10 PEP 331: Locale-Independent Float/String Conversions
Partially.

matz.


 
Reply With Quote
 
 
 
 
Austin Ziegler
Guest
Posts: n/a
 
      11-30-2004
On Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <(E-Mail Removed)>
wrote:
> A coworker of mine came and hollarred at me because on /. it
> mentioned that Python 2.4 was released...so I went to check it
> out.
>
> I read the What's new section but isn't the majority of stuff they
> added in 2.4 stuff Ruby already does?


> (dont know) 3 PEP 289: Generator Expressions


This may be similar to Enumerable#inject.

> (ruby does/has) 4 PEP 292: Simpler String Substitutions


This is just bizarre as something to put into Core Python; however,
given that Ruby ships with RDoc, which gives you the RDoc templating
engine, you have something like this already.

> (ruby does/has?)5 PEP 318: Decorators for Functions and Methods


Ruby has this implicitly, because its object model is far more
consistent. The only thing that may improve this is an RCR that
makes it easier to deal with custom decorators by having def return
the Symbol of the method name. Probably

> (dont know) 7 PEP 324: New subprocess Module


This basically introduces popen.

> (ruby dont have) 8 PEP 327: Decimal Data Type


I think that BigDecimal handles this just fine. Note as well that
with the Rational class (require 'rational'), you get support for
real rational numbers. If you add 'mathn', you get full support
including with division, etc.

require 'rational'
Rational.reduce(22, 7) # => Rational(22, 7)

require 'mathn'
"%0.9f" % [ 22 / 7 ] # => "3.142857143"
(22 / 7).class # => Rational

BigDecimal works with Numerics, BigIntegers, and Floats, I think.

> (dont know) 9 PEP 328: Multi-line Imports


Not needed.

> (dont know) 10 PEP 331: Locale-Independent Float/String Conversions


I don't think that this is needed.

-austin
--
Austin Ziegler * http://www.velocityreviews.com/forums/(E-Mail Removed)
* Alternate: (E-Mail Removed)


 
Reply With Quote
 
Florian Gross
Guest
Posts: n/a
 
      11-30-2004
Austin Ziegler wrote:

> I think that BigDecimal handles this just fine. Note as well that
> with the Rational class (require 'rational'), you get support for
> real rational numbers. If you add 'mathn', you get full support
> including with division, etc.
>
> require 'rational'
> Rational.reduce(22, 7) # => Rational(22, 7)
>
> require 'mathn'
> "%0.9f" % [ 22 / 7 ] # => "3.142857143"
> (22 / 7).class # => Rational
>
> BigDecimal works with Numerics, BigIntegers, and Floats, I think.


It's impressive how much you can do with Standard Ruby. Add some glue
(see attachment) to it and you can do things like this one and get exact
results:

(1 .. 100).inject(0) { |state, item| state + 1 / item }.to_s(50)
# => "5.18737751763962026080511767565825315790897212670 845"

Where 50 is the number of floating point digits. Increase it and you get
more and more detail. It's wonderful how simple things can be with Ruby.

It all kind of makes me wonder if Rationals could be added with a
different notation to Ruby -- maybe 0.5R + 0.4R. You would always need
to specify the precision on output, but I think that is okay.


require 'mathn'
require 'bigdecimal'
require 'bigdecimal/util'

class Rational
alias ld_to_s :to_s

def to_s(precision = nil)
if precision then
if precision == 0 then
self.to_d(1).to_s("F").to_i.to_s
else
self.to_d(precision + 1).to_s("F")
end
else
old_to_s
end
end
end

 
Reply With Quote
 
gabriele renzi
Guest
Posts: n/a
 
      11-30-2004
Austin Ziegler ha scritto:
> On Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <(E-Mail Removed)>
> wrote:
>
>>A coworker of mine came and hollarred at me because on /. it
>>mentioned that Python 2.4 was released...so I went to check it
>>out.
>>
>>I read the What's new section but isn't the majority of stuff they
>>added in 2.4 stuff Ruby already does?

>
>
>>(dont know) 3 PEP 289: Generator Expressions

>
>
> This may be similar to Enumerable#inject.



not really. to understand generator expression you first think of list
comprehensions:

ary=[ f(x) for x in sequence if somecondition on x ]

Basically a #map + #select in a single loop
(I'd like to have an Enumerable#map_filter, btw)

Then think of a lazy version of it (returning a generator) instead of a
whole constructed list, so that you can write:

function(f(x) for x in seq)

instead of
function([f(x) for x in seq])


withouth building a whole array when calling the function.

Notice that we have generator.rb wich can transform a internal (rubyish)
iterator into a lazy generator


>>(ruby does/has?)5 PEP 318: Decorators for Functions and Methods

>
>
> Ruby has this implicitly, because its object model is far more
> consistent. The only thing that may improve this is an RCR that
> makes it easier to deal with custom decorators by having def return
> the Symbol of the method name. Probably


this does not relate to the object model.
A common python idiom is always been:
class Foo(object):
def foo():
...
foo=somedecorator(foo)

wich is basically what we do in ruby with:
class Foo
def foo
...
end
somedecorator :foo
end

Btw, I hope matz will accept RCR 277 soon
http://rcrchive.net/rcr/show/277



>
>>(dont know) 7 PEP 324: New subprocess Module

>
>
> This basically introduces popen.


no, they already had popen they just 'refactored'

>
>>(dont know) 10 PEP 331: Locale-Independent Float/String Conversions

>
>
> I don't think that this is needed.


I can't see an use for it, but they have a rational for this, and
actually the code is borrowed from GLIb so others seem to think it is useful


Just playing devil's advocate
 
Reply With Quote
 
Edgardo Hames
Guest
Posts: n/a
 
      11-30-2004
On Wed, 1 Dec 2004 03:37:21 +0900, Austin Ziegler <(E-Mail Removed)> wrote:
> On Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <(E-Mail Removed)>
> wrote:
>
> > (dont know) 10 PEP 331: Locale-Independent Float/String Conversions

>
> I don't think that this is needed.
>


Just wondering, aren't these conversions what allow different formats
for float numbers? For example "3.141592654" in English, "3,141592654"
in Spanish.

Kind Regards,
Ed
--
The downside of being better than everyone else is that people tend to
assume you're pretentious.


 
Reply With Quote
 
gabriele renzi
Guest
Posts: n/a
 
      11-30-2004
Zach Dennis ha scritto:
> A coworker of mine came and hollarred at me because on /. it mentioned
> that Python 2.4 was released...so I went to check it out.
>
> I read the What's new section but isn't the majority of stuff they added
> in 2.4 stuff Ruby already does?


some, then some is unneeeded in ruby, and some is simply done
differently (i.e. set). Python and ruby are converging anyway
http://c2.com/cgi/wiki?PythonAndRubyAreConverging
 
Reply With Quote
 
Austin Ziegler
Guest
Posts: n/a
 
      11-30-2004
On Wed, 1 Dec 2004 04:52:47 +0900, itsme213 <(E-Mail Removed)> wrote:
> > > (ruby does/has?)5 PEP 318: Decorators for Functions and Methods

> >
> > Ruby has this implicitly, because its object model is far more
> > consistent. The only thing that may improve this is an RCR that
> > makes it easier to deal with custom decorators by having def return
> > the Symbol of the method name. Probably

> A convenient decorator syntax would be very nice.


Very. It's been asked for a lot.

> Also, I believe Python manipulates the method as an object. I don't think
> manipulating a symbol (without the context of the class in which that symbol
> serves to name a method) can be equivalent. Maybe def should return
> something like a
> - Method (for def x.foo...) or
> - UnboundMethod or [Symbol, Class] pair (for class X; def foo ... )


Well, the case of def x.foo is the only case where a Symbol by itself
isn't going to be useful, really -- so maybe [Symbol, "Class"] is the
better choice. Other manipulations of thse things in Ruby -- are done
with the Symbol, and there's not a lot you can do to manipulate a
Method object.

-austin
--
Austin Ziegler * (E-Mail Removed)
* Alternate: (E-Mail Removed)


 
Reply With Quote
 
Austin Ziegler
Guest
Posts: n/a
 
      11-30-2004
On Wed, 1 Dec 2004 04:54:15 +0900, Edgardo Hames <(E-Mail Removed)> wrote:
> On Wed, 1 Dec 2004 03:37:21 +0900, Austin Ziegler <(E-Mail Removed)> wrote:
> > On Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <(E-Mail Removed)>
> > wrote:
> > > (dont know) 10 PEP 331: Locale-Independent Float/String Conversions

> > I don't think that this is needed.

> Just wondering, aren't these conversions what allow different formats
> for float numbers? For example "3.141592654" in English, "3,141592654"
> in Spanish.


That's locale-dependent. Basically, Python's numeric output appears to
be locale-dependent in all cases, except when using these new
features.

-austin
--
Austin Ziegler * (E-Mail Removed)
* Alternate: (E-Mail Removed)


 
Reply With Quote
 
Florian Gross
Guest
Posts: n/a
 
      11-30-2004
Austin Ziegler wrote:

> Well, the case of def x.foo is the only case where a Symbol by itself
> isn't going to be useful, really -- so maybe [Symbol, "Class"] is the
> better choice. Other manipulations of thse things in Ruby -- are done
> with the Symbol, and there's not a lot you can do to manipulate a
> Method object.


Symbols are really the only option here because of the overhead involved
when creating a Method object for every def. I agree that it would only
make sense in private def other.method; end cases, but I think class
<< other; private def method; end; end is not too troublesome to use.

I am wondering why matz stays so silent on this. Are there issues
frequently overseen? Would returning a Symbol instead of nil make a
difference in terms of performance?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 R. David Murray Python 0 01-17-2011 02:23 PM
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 Senthil Kumaran Python 0 01-17-2011 10:31 AM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Martin v. L÷wis Python 0 03-01-2008 10:51 PM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Paul Moore Python 0 03-01-2008 10:39 PM
Re: pymozilla ([Python-Dev] RELEASED Python 2.3.3 (releasecandidate 1) - custom Py_Initialize()) Wiktor Sadowski Python 4 12-24-2003 12:08 AM



Advertisments