Question: immutable strings as design goal?

Indeed, although there’s nothing intrinsically wrong with modifying a
hash key (after all, you could have arrays as hash keys, and they’re
not frozen). Hash#rehash (and some common sense when it comes to
retaining references to keys) is your friend here.

Also it might be worth mentioning that (I believe) that the keys are
duped using copy-on-write semantics, so there’s less overhead that some
might suppose.

Cheers

Dave

···

On Monday, August 18, 2003, at 02:44 PM, Paul Brannan wrote:

On Tue, Aug 19, 2003 at 04:06:24AM +0900, Dave Thomas wrote:

Ruby gets around this by dup-ing strings used as Hash keys, so the
problem doesn’t crop up.

dup-ing and freezing. It would still be possible to modify the Hash
key
if the key were not frozen.

Wow! What an amazing feature! How could Guido have
come up with such a unique and novel idea, never seen before nor
since? :slight_smile:

I am a big fan of File.foreach - but then I’m a big fan of the
blocks and iterators in general.

Actually, far from being impressed by the inclusion of this feature in
Python, I’m more surprised that Perl doesn’t have it. To open a file
and iterate through its lines, I don’t know of any Perl idiom that’s
much simpler than the low-levelish open/read-loop/close sequence. I
think the closest you can get is something like this:

{
    local @ARGV = ($filename);
    while (<>)
    {
	...process $_...
    }
}

… . . which saves the explicit close() line at the expense of legibility.
You could also save the close line by using an IO::File instance instead
of a normal filehandle:

{
    my $fh = IO::File::->new("<$filename");
    while (<$fh>)
    {
	...process $_...
    }
}

But last I checked using IO::File really slowed things down.

Anyway. Back to Ruby.

:slight_smile:

···

On Tue, Aug 19, 2003 at 09:14:16AM +0900, Mark Wilson wrote:

for line in open(filename):
…process line…

While we’re still on the subject of Python and Guido Von Rossum’s blog
entry, I noted the following:

"but for me the high point of the evening was Miguel de Icaza’s
excitement over Python’s feature which makes text files iterators
yielding the lines of the file in succession, so that you can write

for line in open(filename):
…process line… "

At which point I sighed.

Regards,

Mark

Yeah, and it’s funny how he remarks about other languages allegedly
stealing features from Python but crediting CLU etc. instead!

Cheers,
Gavin

Hey, it could have been worse–you could have been sitting between
them when these great revelations were happening… :slight_smile:

···

At 9:14 AM +0900 8/19/03, Mark Wilson wrote:

While we’re still on the subject of Python and Guido Von Rossum’s
blog entry, I noted the following:

"but for me the high point of the evening was Miguel de Icaza’s
excitement over Python’s feature which makes text files iterators
yielding the lines of the file in succession, so that you can write

for line in open(filename):
…process line… "

At which point I sighed.


Dan

--------------------------------------“it’s like this”-------------------
Dan Sugalski even samurai
dan@sidhe.org have teddy bears and even
teddy bears get drunk

eyes.roll

Actually, someone recently pointed out to me
(Gavin I think) that for/in is equivalent to
each, but he had wandered away from that since
he often needed each_with_index or something
similar.

So, then. How does Python’s example work when
you need the index also? Oh, it can be done,
all right. Same as in Fortran.

For that matter, how do you do each_byte in
Python, to iterate a byte at a time?

This is not a flame. I don’t know Python, and
I don’t participate in language wars. But the
more I learn about Python, the less impressed
I am.

I certainly see no compelling reason for me to
switch from Ruby to Python. On the other hand,
it doesn’t surprise me that they feel the same
way.

Hal

···

----- Original Message -----
From: “Mark Wilson” mwilson13@cox.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, August 18, 2003 7:14 PM
Subject: Re: Question: immutable strings as design goal?

While we’re still on the subject of Python and Guido Von Rossum’s blog
entry, I noted the following:

"but for me the high point of the evening was Miguel de Icaza’s
excitement over Python’s feature which makes text files iterators
yielding the lines of the file in succession, so that you can write

for line in open(filename):
…process line… "

At which point I sighed.


Hal Fulton
hal9000@hypermetrics.com

Er, that’s because CLU and Icon were the inspiration for Python’s
iterators, just as they were the inspiration for Ruby’s. The PEP describing
generators (PEP 255 – Simple Generators | peps.python.org) references Sather and
Icon, and searching the archives of the python-iter list, I find no
references to Ruby at all.

–amk

···

On Tue, 19 Aug 2003 16:29:56 +0900, Gavin Sinclair gsinclair@soyabean.com.au wrote:

Yeah, and it’s funny how he remarks about other languages allegedly
stealing features from Python but crediting CLU etc. instead!

Hi,

···

In message “Re: Question: immutable strings as design goal?” on 03/08/19, Dan Sugalski dan@sidhe.org writes:

Hey, it could have been worse–you could have been sitting between
them when these great revelations were happening… :slight_smile:

Yep. And it’s indeed a great step in Python.

						matz.

Hi,

···

In message “Re: Question: immutable strings as design goal?” on 03/08/20, “Hal E. Fulton” hal9000@hypermetrics.com writes:

So, then. How does Python’s example work when
you need the index also? Oh, it can be done,
all right. Same as in Fortran.

There’s enumerate().

a = [1,2,3]
for i,v in enumerate(a):
print i, v

						matz.

You misunderstand me. I wasn’t suggesting that Python or Ruby have
borrowed features from each other. What I was commenting on is the
following quote:

It was nice enough to compare the yield statements in Python and C#
(they are very similar, even though C# quotes CLU as the origin
rather than Python :slight_smile:

It seemed to me at first glance that Guido would like C# to credit
Python as the origin of the yield statement. Looking at the quote
again, I think I might have been a bit mischevous to suggest that.

Cheers,
Gavin

···

On Tuesday, August 19, 2003, 10:43:38 PM, A.M. wrote:

On Tue, 19 Aug 2003 16:29:56 +0900, > Gavin Sinclair gsinclair@soyabean.com.au wrote:

Yeah, and it’s funny how he remarks about other languages allegedly
stealing features from Python but crediting CLU etc. instead!

Er, that’s because CLU and Icon were the inspiration for Python’s
iterators, just as they were the inspiration for Ruby’s. The PEP describing
generators (PEP 255 – Simple Generators | peps.python.org) references Sather and
Icon, and searching the archives of the python-iter list, I find no
references to Ruby at all.

LOL!!! So true, so true.

martin

···

Yukihiro Matsumoto matz@ruby-lang.org wrote:

In message “Re: Question: immutable strings as design goal?” > on 03/08/19, Dan Sugalski dan@sidhe.org writes:

Hey, it could have been worse–you could have been sitting between
them when these great revelations were happening… :slight_smile:

Yep. And it’s indeed a great step in Python.

Yeah, and it’s funny how he remarks about other languages allegedly
stealing features from Python but crediting CLU etc. instead!

Er, that’s because CLU and Icon were the inspiration for Python’s
iterators, just as they were the inspiration for Ruby’s. The PEP
describing
generators (PEP 255 – Simple Generators | peps.python.org) references Sather
and
Icon, and searching the archives of the python-iter list, I find no
references to Ruby at all.

Correct. It’s well-known that Ruby’s iterators
come from CLU – I’ve never heard Icon cited,
but that could well be.

But I see no reason to think that any language
“stole from Python but credited CLU instead.”

I did hear it asserted once that Python “stole”
iterators from Ruby. It’s irrelevant to me. I’d
just as soon assume they came from Icon and CLU.

Hal

···

----- Original Message -----
From: “A.M. Kuchling” amk@amk.ca
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, August 19, 2003 7:43 AM
Subject: Re: Question: immutable strings as design goal?

On Tue, 19 Aug 2003 16:29:56 +0900, > Gavin Sinclair gsinclair@soyabean.com.au wrote:


Hal Fulton
hal9000@hypermetrics.com

There’s enumerate().

a = [1,2,3]
for i,v in enumerate(a):
print i, v

Hm. Must be new in 2.3?

Traceback (most recent call last):
File “”, line 1, in ?
NameError: name ‘enumerate’ is not defined

-Mark

···

On Wed, Aug 20, 2003 at 08:41:03AM +0900, Yukihiro Matsumoto wrote: