From: Martin Asser Hansen Date: 2011-01-21T19:54:02+09:00 Subject: [ruby-core:34720] Re: Feature request - Low level bitwise operations on char arrays (or class String) --0016e644c5aa2cae85049a591199 Content-Type: text/plain; charset=ISO-8859-1 I agree that simply copying Perl's way is not a good idea if Ruby is supposed to be "Perl's younger and prettier sister". But we can let us inspire? Brain storming below: Questions: 1. Why implement this in the first place? (useful for my bitarrays - and for finding Hamming distances :o) 2. What to do with strings of uneven lengths? (do like Perl) 3. Will optimization using 32/64 bit machine words be in order? (like in Bit::Vector.pm) And another question. Consider 1 and 2 below: 1. string1 = string1 & string2 2. string1 &= string2 As I understand Ruby's behaviour with respect to and = then 1 and 2 will use the same amount of memory because they both return a new string variable holding the result? So in the case of 2 you could simply mutate string1 and skip the new variable with the return string. I'd like to save that memory, because then you can use this for manipulating huge bitarrays. Cheers, Martin On Thu, Jan 20, 2011 at 7:56 PM, NARUSE, Yui wrote: > (2011/01/19 18:22), Martin Asser Hansen wrote: > >> I still think that String#^ (and corresponding | & ~) would be in >> order as these can be used much more generic. >> >> How about simply copying Perl's way? >> >> maasha@mel:~$ perl -le 'print "aaaaa" ^ " "' AAaaa >> >> I find that this behaviour unsurprising. >> > > I agree that Perl's way is a possible choice. > But when we design, the spec must have well considered. > Usually "because perl does so" can't be a reason. > > http://perldoc.perl.org/perlop.html#Bitwise-String-Operators > > -- > NARUSE, Yui > > --0016e644c5aa2cae85049a591199 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I agree that simply copying Perl's way is not a good idea if Ruby is su= pposed to be "Perl's younger and prettier sister". But we can= let us inspire? Brain storming below:

Questions:
  1. Why implement this in the first place? (useful for my bitarray= s - and for finding Hamming distances :o)
  2. What to do with strings o= f uneven lengths?=A0(do like Perl)
  3. Will opt= imization using 32/64 bit machine words be in order? (like in Bit::Vector.p= m)
And another question. Consider 1 and 2 below:
  1. s= tring1 =3D string1 & string2
  2. string1 &=3D string2
=
As I understand Ruby's=A0behaviour=A0with respect to <ope= rator> and <operator>=3D then 1 and 2 will use the same amount of = memory because they both return a new string variable holding the result? S= o in the case of 2 you could simply mutate string1 and skip the new variabl= e with the return string. I'd like to save that memory, because then yo= u can use this for manipulating huge bitarrays.


Cheers,


Martin



On Thu, Jan 20, 2011 at 7:56 PM, NARUSE, Yui &= lt;naruse@airemix.jp> wr= ote:
(2011/01/19 18:22), Marti= n Asser Hansen wrote:
I still think that String#^ (and corresponding | & ~) would be in
order as these can be used much more generic.

How about simply copying Perl's way?

maasha@mel:~$ perl -le 'print "aaaaa" ^ " "' AA= aaa

I find that this behaviour unsurprising.

I agree that Perl's way is a possible choice.
But when we design, the spec must have well considered.
Usually "because perl does so" can't be a reason.

http://perldoc.perl.org/perlop.html#Bitwise-String-Operator= s

--
NARUSE, Yui =A0<n= aruse@airemix.jp>


--0016e644c5aa2cae85049a591199--