[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[OFF] Python 2.4 released

Zach Dennis

11/30/2004 5:35:00 PM

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



20 Answers

Yukihiro Matsumoto

11/30/2004 5:42:00 PM

0

Hi,

In message "Re: [OFF] Python 2.4 released"
on Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <zdennis@mktec.com> 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.


Austin Ziegler

11/30/2004 6:37:00 PM

0

On Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <zdennis@mktec.com>
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 * halostatue@gmail.com
* Alternate: austin@halostatue.ca


Florian Gross

11/30/2004 7:06:00 PM

0

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.18737751763962026080511767565825315790897212670845"

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 :old_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

Its Me

11/30/2004 7:48:00 PM

0

> > (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.

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 ... )

Or is the idea to simply use "self" in that class?


gabriele renzi

11/30/2004 7:53:00 PM

0

Austin Ziegler ha scritto:
> On Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <zdennis@mktec.com>
> 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/rc...



>
>>(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 :)

Edgardo Hames

11/30/2004 7:54:00 PM

0

On Wed, 1 Dec 2004 03:37:21 +0900, Austin Ziegler <halostatue@gmail.com> wrote:
> On Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <zdennis@mktec.com>
> 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.


gabriele renzi

11/30/2004 7:55:00 PM

0

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?PythonAndRubyAre...

Austin Ziegler

11/30/2004 8:38:00 PM

0

On Wed, 1 Dec 2004 04:52:47 +0900, itsme213 <itsme213@hotmail.com> 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 * halostatue@gmail.com
* Alternate: austin@halostatue.ca


Austin Ziegler

11/30/2004 8:39:00 PM

0

On Wed, 1 Dec 2004 04:54:15 +0900, Edgardo Hames <ehames@gmail.com> wrote:
> On Wed, 1 Dec 2004 03:37:21 +0900, Austin Ziegler <halostatue@gmail.com> wrote:
> > On Wed, 1 Dec 2004 02:35:02 +0900, Zach Dennis <zdennis@mktec.com>
> > 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 * halostatue@gmail.com
* Alternate: austin@halostatue.ca


Florian Gross

11/30/2004 10:56:00 PM

0

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?