Mutable strings

Hi All,

Since my communications skills have be questioned on the ML, I am trying to
be better :slight_smile:

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.

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

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?

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/

regards,
Mystifier

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

-austin

路路路

On Fri, 14 Jan 2005 03:48:58 +0900, Mystifier <mystifier@users.berlios.de> wrote:

Hi All,

Since my communications skills have be questioned on the ML, I am trying to
be better :slight_smile:

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.

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

Mystifier wrote:

Hi All,

Since my communications skills have be questioned on the ML, I am

trying to

be better :slight_smile:

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

* 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);}

"Mystifier" <mystifier@users.berlios.de> 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

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

路路路

On Fri, 14 Jan 2005 03:48:58 +0900, Mystifier <mystifier@users.berlios.de> wrote:

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

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

Nope:

$ ruby
p "\0"
"\0".intern
"\000"
-:2:in `intern': symbol string may not contain `\0' (ArgumentError)
         from -:2

PGP.sig (186 Bytes)

路路路

On 13 Jan 2005, at 10:48, Mystifier wrote:

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

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

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

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.

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

路路路

On Fri, 14 Jan 2005 14:00:07 +0900, Mystifier <mystifier@users.berlios.de> 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

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

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 [mailto:halostatue@gmail.com]
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 <mystifier@users.berlios.de> 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 * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

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.

Yes. The intrinsic value of a symbol is immutable -- and it doesn't
have support for virtual classes; the fact that it's an Object like
everything else, though, says that it can have additional methods or
even instance variables added at any time.

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.

And I think that the existence of Ruby -- which is quite performant
for a lot of people -- suggests otherwise.

-austin

路路路

On Sat, 15 Jan 2005 00:04:39 +0900, Mystifier <mystifier@users.berlios.de> wrote:
--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

"Austin Ziegler" <halostatue@gmail.com> schrieb im Newsbeitrag
news:9e7db911050114080130590517@mail.gmail.com...

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

That statement is far too general IMHO. There are a lot more factors that
affect VM performance. And a fast VM still does not guarantee fast
program execution...

Cheers

    robert

路路路

And I think that the existence of Ruby -- which is quite performant
for a lot of people -- suggests otherwise.

-austin
--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

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

Clarification:
It says that immutable string class is necessary in VM because instead of
comparing strings for method names etc in VM you can use integers or
references comparison. Ruby also does same thing but for Unknown reasons
prefers to call them symbol class and not an immutable string class. They
want to deny that Ruby has any. I have found Symbol has all the ingredients
of immutable string class. It has something more - uniqueness.

Mystifier

references comparison. Ruby also does same thing but for Unknown reasons
prefers to call them symbol class and not an immutable string class. They
want to deny that Ruby has any. I have found Symbol has all the ingredients
of immutable string class. It has something more - uniqueness.

Read this message [ruby-talk:113107]

Guy Decoux

* Mystifier (Jan 14, 2005 18:40):

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

Clarification: It says that immutable string class is necessary in VM
because instead of comparing strings for method names etc in VM you
can use integers or references comparison. Ruby also does same thing
but for Unknown reasons prefers to call them symbol class and not an
immutable string class. They want to deny that Ruby has any. I have
found Symbol has all the ingredients of immutable string class. It has
something more - uniqueness.

Ruby doesn't have an immutable string class, that's final. Ruby has a
Symbol class that is used for the specific ideas you're referring to, to
make certain implementation details faster and more memory efficient.
It has nothing to do with the other "merits" of having immutable
strings.

You can add strings, but you can't add symbols,
  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);}

Thanks.

Should messages like this be mailing posts or personal posts?

Mystifier

路路路

-----Original Message-----
From: ts [mailto:decoux@moulon.inra.fr]
Sent: Friday, January 14, 2005 11:21 PM
To: ruby-talk ML
Cc: ruby-talk@ruby-lang.org
Subject: Re: Mutable strings

references comparison. Ruby also does same thing but for Unknown
reasons prefers to call them symbol class and not an immutable string
class. They want to deny that Ruby has any. I have found Symbol has
all the ingredients of immutable string class. It has something more
- uniqueness.

Read this message [ruby-talk:113107]

Guy Decoux

Should messages like this be mailing posts or personal posts?

Mailing list post, see

   http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/113107

Guy Decoux

Mailing posts I would think though I sure would like it if an actual link was
provided.

T.

路路路

On Friday 14 January 2005 12:59 pm, Mystifier wrote:

Thanks.

Should messages like this be mailing posts or personal posts?

Uff! I did it again. Need to go to school back!

Sorry, I meant small messages like thanking you for the link etc be posted
on personal mail or on this mailing list.

Mystifier

路路路

-----Original Message-----
From: trans. (T. Onoma) [mailto:transami@runbox.com]
Sent: Friday, January 14, 2005 11:35 PM
To: ruby-talk ML
Subject: Re: Mutable strings

On Friday 14 January 2005 12:59 pm, Mystifier wrote:

Thanks.

Should messages like this be mailing posts or personal posts?

Mailing posts I would think though I sure would like it if an actual link
was
provided.

T.