Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Mutable strings

Reply
Thread Tools

Mutable strings

 
 
Mystifier
Guest
Posts: n/a
 
      01-13-2005
------=_NextPart_000_000A_01C4F9CE.A35BD420
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi All,
=20
Since my communications skills have be questioned on the ML, I am trying =
to
be better
=20
=20
I saw few last posts by matz categorically saying that strings shall be
mutable.=20
=20
I have nothing against or for it as a language specification. What =
interests
me that if string are immutable, we can use strings as symbols. This can
bring about few important effects on VM.
=20
1) Symbols and FixNum have few exceptions to the usual rules. Symbols =
may
not have any exceptions, since symbol and strings will be basically =
same.
=20
2) Efficiency of VM will improve because Symbols and Strings can be used
interchangeably.
=20
3) It might help on security, perhaps.
=20
A Mutable string class can be created for mutating strings.
=20
No, I am not trying to create another java, but as Users, how many times
have you mutated your strings?
=20
A mailing list to discuss Vuby Specifications has been created on =
Berlios
and will be active shortly for discussions.
=20
https://developer.berlios.de/projects/vuby/
=20
regards,
Mystifier
=20

------=_NextPart_000_000A_01C4F9CE.A35BD420--


 
Reply With Quote
 
 
 
 
Austin Ziegler
Guest
Posts: n/a
 
      01-13-2005
On Fri, 14 Jan 2005 03:48:58 +0900, Mystifier
<(E-Mail Removed)> wrote:
> Hi All,
>
> Since my communications skills have be questioned on the ML, I am trying to
> be better
>
> I saw few last posts by matz categorically saying that strings shall be
> mutable.
>
> I have nothing against or for it as a language specification. What interests
> me that if string are immutable, we can use strings as symbols. This can
> bring about few important effects on VM.


"Foo Bar".to_sym
:"Foo Bar".to_s

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


 
Reply With Quote
 
 
 
 
Charles Mills
Guest
Posts: n/a
 
      01-13-2005

Mystifier wrote:
> Hi All,
>
> Since my communications skills have be questioned on the ML, I am

trying to
> be better
>
>
> I saw few last posts by matz categorically saying that strings shall

be
> mutable.
>
> I have nothing against or for it as a language specification. What

interests
> me that if string are immutable, we can use strings as symbols. This

can
> bring about few important effects on VM.
>
> 1) Symbols and FixNum have few exceptions to the usual rules. Symbols

may
> not have any exceptions, since symbol and strings will be basically

same.

Symbols are immutable. The current implementation of symbols seems
like a good one to me. They are just a number that uniquely identifies
a string (contained in a symbol table somewhere in the interpreter).

>
> 2) Efficiency of VM will improve because Symbols and Strings can be

used
> interchangeably.
>

Ruby already uses some nice tricks for sharing memory between string
instances (and between array instances).

> 3) It might help on security, perhaps.
>
> A Mutable string class can be created for mutating strings.
>
> No, I am not trying to create another java, but as Users, how many

times
> have you mutated your strings?


Try ri String. About 1/2 the methods change the reciever.

>
> A mailing list to discuss Vuby Specifications has been created on

Berlios
> and will be active shortly for discussions.
>
> https://developer.berlios.de/projects/vuby/
>


There are already a number of Ruby VM projects. Many of them
relatively mature. Perhaps you should take a look at those.
If you are writing a VM, I don't see why you would need to rewrite the
standard library, or even break the Ruby API at the C level.

-Charlie

 
Reply With Quote
 
Nikolai Weibull
Guest
Posts: n/a
 
      01-13-2005
* Mystifier (Jan 13, 2005 19:50):
> I have nothing against or for it as a language specification. What
> interests me that if string are immutable, we can use strings as
> symbols. This can bring about few important effects on VM.


Python has immutable strings. If you want 'em, use Python.

Now, lets begin a long thread about Python versus Ruby, starting off by
discussing the merits of immutable versus mutable strings, but soon
trailing off by discussing the fact that Guido is Dutch and matz is
Japanese and how this makes Python/Ruby better/worse,
nikolai

--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


 
Reply With Quote
 
Mystifier
Guest
Posts: n/a
 
      01-14-2005
Dear Charles,

I have no intensions of changing the language APIs for it really does not
matter to a VM Implementation. All the components that inherently affects
the VM implementations are those that VM uses natively like File, Strings,
Numbers and Threads.

I surprisingly found Symbols are exactly not Immutable...., they are just
like any other class

irb(main):001:0> foo = :foo
=> :foo
irb(main):002:0> class Symbol
irb(main):003:1> def bar=(value)
irb(main):004:2> @bar = value
irb(main):005:2> end
irb(main):006:1> def printbar
irb(main):007:2> print @bar
irb(main):008:2> end
irb(main):009:1> end
=> nil
irb(main):010:0> foo.bar = "eee"
=> "eee"
irb(main):011:0> foo.printbar
eee=> nil
irb(main):012:0> zoo = :foo
=> :foo
irb(main):013:0> zoo.printbar
eee=> nil
irb(main):014:0>

We can think that keys that are strings of the Symbol table are immutable,
while the values which are objects of the instances Symbol are mutable. I
had thought that symbol table was a hash_set but it turns out that it is a
hash_map.

In that case it appears immutable strings are be called as symbols and Ruby
has Immutable strings. of course, by implementing additional methods.

Regards,
Mystifier



 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      01-14-2005

"Mystifier" <(E-Mail Removed)> schrieb im Newsbeitrag
news:000901c4f9a0$899eb620$1a87103d@vubydump...

> I saw few last posts by matz categorically saying that strings shall be
> mutable.
>
> I have nothing against or for it as a language specification. What

interests
> me that if string are immutable, we can use strings as symbols. This can
> bring about few important effects on VM.
>
> 1) Symbols and FixNum have few exceptions to the usual rules. Symbols

may
> not have any exceptions, since symbol and strings will be basically

same.

Do you mean that the current restrictions of Symbol will no longer apply?

> 2) Efficiency of VM will improve because Symbols and Strings can be used
> interchangeably.


Not necessarily: you can see with a Java VM that efficiency of the
application degrades if you have many string manipulations that use String
instead of a more suited class (StringBuffer for example). The same will
happen in Ruby if you need to create a new object for each mutated string.

> 3) It might help on security, perhaps.


Ruby has already #freeze and $SAFE. What additional security do we gain?

> A Mutable string class can be created for mutating strings.


I don't understand what we gain by this. We have this situation already:

- Symbols and frozen Strings are immutable

- Other Strings are mutable

With the added benefit that Symbols are unique: there is at most one
Symbol instance representing a certain character sequence.

> No, I am not trying to create another java, but as Users, how many times
> have you mutated your strings?


Often enough to say it's a very common scenario.

Regards

robert

 
Reply With Quote
 
Florian Gross
Guest
Posts: n/a
 
      01-14-2005
Mystifier wrote:

> I surprisingly found Symbols are exactly not Immutable...., they are just
> like any other class


They are mostly immutable. I'd still consider them value objects. In
Ruby you can set instance variables of all Objects, even if they're
immutable.
 
Reply With Quote
 
Austin Ziegler
Guest
Posts: n/a
 
      01-14-2005
On Fri, 14 Jan 2005 14:00:07 +0900, Mystifier
<(E-Mail Removed)> wrote:
> Dear Charles,
>
> I have no intensions of changing the language APIs for it really
> does not matter to a VM Implementation. All the components that
> inherently affects the VM implementations are those that VM uses
> natively like File, Strings, Numbers and Threads.
>
> I surprisingly found Symbols are exactly not Immutable...., they
> are just like any other class


Um. That's not the same at all. Symbols themselves are immutable.
The Symbol Class is not immutable.

Yes, this means that someone could override #to_s on Symbol to do
something else entirely, but Symbols themselves are immutable -- and
they cannot have virtual (singleton) classes:

irb(main):001:0> foo = :foo
=> :foo
irb(main):002:0> class << foo
irb(main):003:1> end
TypeError: no virtual class for Symbol
from (irb):2
irb(main):004:0>

There is a significant difference between the two sorts of
immutability that you would be advised to understand before even
thinking of attempting to implement a VM to support Ruby.

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


 
Reply With Quote
 
Austin Ziegler
Guest
Posts: n/a
 
      01-14-2005
On Fri, 14 Jan 2005 03:48:58 +0900, Mystifier
<(E-Mail Removed)> wrote:
> No, I am not trying to create another java, but as Users, how many
> times have you mutated your strings?


All the time.

I'm working on Text::Format again to get it cleaned up for a 1.0
release, and it does:

line << " " if sentence_end and extra_space
line << " #{next_word}"

There's your mutable strings. They are a necessary component of most
languages that do a lot of string manipulations. (Most of my
projects end up doing quite a bit of string manipulation; Ruwiki
uses a lot of gsub! calls, no less.)

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


 
Reply With Quote
 
Mystifier
Guest
Posts: n/a
 
      01-14-2005
Dear Austin,

Immutability as I understand is preserving state of the Object. State of
Object are instance variables in Ruby. My example does sot change class
variables, but the instance variable. Symbol class being immutable or not is
besides the point. I am talking about symbol instance, and ability to change
symbol instance variables makes them not immutable as such. Yes, the
sequence of chars they represent are immutable. Hence, I get an impression
that the Symbol is a immutable string class.

About learning things before writing VM, I am sure I have to. What I feel No
VM or Interpreter can exists with reasonable performance with have an
immutable string class. It is altogether a different matter what you call
them.



-----Original Message-----
From: Austin Ziegler [(E-Mail Removed)]
Sent: Friday, January 14, 2005 7:59 PM
To: ruby-talk ML
Subject: Re: Mutable strings


On Fri, 14 Jan 2005 14:00:07 +0900, Mystifier <(E-Mail Removed)>
wrote:
> Dear Charles,
>
> I have no intensions of changing the language APIs for it really does
> not matter to a VM Implementation. All the components that inherently
> affects the VM implementations are those that VM uses natively like
> File, Strings, Numbers and Threads.
>
> I surprisingly found Symbols are exactly not Immutable...., they are
> just like any other class


Um. That's not the same at all. Symbols themselves are immutable. The Symbol
Class is not immutable.

Yes, this means that someone could override #to_s on Symbol to do something
else entirely, but Symbols themselves are immutable -- and they cannot have
virtual (singleton) classes:

irb(main):001:0> foo = :foo
=> :foo
irb(main):002:0> class << foo
irb(main):003:1> end
TypeError: no virtual class for Symbol
from (irb):2
irb(main):004:0>

There is a significant difference between the two sorts of immutability that
you would be advised to understand before even thinking of attempting to
implement a VM to support Ruby.

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






 
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
Mutable Strings - Any libraries that offer this? casebash Python 9 07-27-2009 12:36 AM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
Are JavaScript strings mutable? Water Cooler v2 Javascript 12 04-20-2006 07:50 PM
Mutable strings Gordon Airport Python 17 09-25-2003 08:10 PM
RE: Mutable strings SBrunning@trisystems.co.uk Python 1 09-22-2003 09:31 PM



Advertisments