Re: Unexpected expansion of string with xx

2013-12-21 Thread Moritz Lenz

On 12/20/2013 04:52 AM, Richard Hainsworth wrote:

OK x not xx.

The doubling of operators is confusing.


OTOH having a single operator which two different meanings is also 
confusing (and very un-perlish).


Cheers,
Moritz


Re: Unexpected expansion of string with xx

2013-12-21 Thread Jonathan Lang
On Dec 21, 2013, at 12:00 AM, Moritz Lenz mor...@faui2k3.org wrote:

 On 12/20/2013 04:52 AM, Richard Hainsworth wrote:
 OK x not xx.
 
 The doubling of operators is confusing.
 
 OTOH having a single operator which two different meanings is also confusing 
 (and very un-perlish).

Sometimes, yeah.  On a related note, I sometimes wish that qw«=  » and the 
like were general-purpose comparison operators rather than explicitly numeric 
comparators.  I understand why Perl uses them in the way that it does (mainly, 
it’s a legacy thing from Perl 5, when there weren’t any data types and the 
distinction between “number” and “string” had to be built into the operator); 
but it takes a lot of getting used to, and there are times that I wish that the 
language would use some argument-based magic to let me sort arbitrary objects 
using “” instead of “before”.  

If it wasn’t for the need for backward compatibility, I’d want something like 
the following:

  $a  $b :as(Num) #[coerce $a and $b to Num.  Same as “$a  $b” now.]
  $a  $b :as(Str) #[coerce $a and $b to Str.  Same as “$a lt $b” now.]
  $a  $b :as(*) #[don’t coerce anything.  Same as “$a before $b” now.]
  $a  $b #[coerce $b to whatever type $a is for the comparison.  No simple 
equivalent now.]

That strikes me as better “principle of least surprise” than the current 
approach.  Alas, I suspect that the ship has long since sailed on this idea.  

Re: Unexpected expansion of string with xx

2013-12-20 Thread Carl Mäsak
My mnemonic is x (one thing) is for scalars, xx (many things) is for
lists. Using that, there's seldom any confusion.

The reason Perl 6 makes the distinction is that (unlike Perl 5) it
*has to*. Perl 5 does context-based dispatch, whereas Perl 6 does
argument-based dispatch. We greatly prefer the latter, and it's an
either-or situation, so two operators it is.

// Carl

On Fri, Dec 20, 2013 at 4:52 AM, Richard Hainsworth
rich...@rusrating.ru wrote:
 OK x not xx.

 The doubling of operators is confusing.

 Richard

 On 12/19/2013 10:01 PM, Jonathan Worthington wrote:

 On 12/19/2013 3:47, Richard Hainsworth wrote:

 Initially I though the following was a bug, but now I'm not sure.

 I got these results

 perl6 -v
 This is perl6 version 2013.09 built on parrot 5.5.0 revision 0
 $ perl6
  say '0' xx 4
 0 0 0 0

 Are you sure you didn't want the x (string repetition) operator, instead
 of xx (list repetition)?

  print '0' xx 4
  print 's' ~ ('0' xx 4)
 s0 0 0 0


 I'm not sure why the elements of the expansion are padded with a trailing
 space in one context but not in another.

 print calls .Str, say calls .gist.

 I wasn't sure whether this is the specified behaviour.

 It is.

 If it is how can it be turned off?

 Call .Str or .gist on the argument to print/say as needed.

 I suspect that the problem will be resolved by using the x operator
 instead of xx, however. :-)

 /jnthn





Re: Unexpected expansion of string with xx

2013-12-19 Thread Jonathan Worthington

On 12/19/2013 3:47, Richard Hainsworth wrote:

Initially I though the following was a bug, but now I'm not sure.

I got these results

perl6 -v
This is perl6 version 2013.09 built on parrot 5.5.0 revision 0
$ perl6
 say '0' xx 4
0 0 0 0
Are you sure you didn't want the x (string repetition) operator, instead 
of xx (list repetition)?



 print '0' xx 4
 print 's' ~ ('0' xx 4)
s0 0 0 0


I'm not sure why the elements of the expansion are padded with a 
trailing space in one context but not in another.



print calls .Str, say calls .gist.

I wasn't sure whether this is the specified behaviour. 

It is.


If it is how can it be turned off?

Call .Str or .gist on the argument to print/say as needed.

I suspect that the problem will be resolved by using the x operator 
instead of xx, however. :-)


/jnthn




Re: Unexpected expansion of string with xx

2013-12-19 Thread Richard Hainsworth

OK x not xx.

The doubling of operators is confusing.

Richard
On 12/19/2013 10:01 PM, Jonathan Worthington wrote:

On 12/19/2013 3:47, Richard Hainsworth wrote:

Initially I though the following was a bug, but now I'm not sure.

I got these results

perl6 -v
This is perl6 version 2013.09 built on parrot 5.5.0 revision 0
$ perl6
 say '0' xx 4
0 0 0 0
Are you sure you didn't want the x (string repetition) operator, 
instead of xx (list repetition)?



 print '0' xx 4
 print 's' ~ ('0' xx 4)
s0 0 0 0


I'm not sure why the elements of the expansion are padded with a 
trailing space in one context but not in another.



print calls .Str, say calls .gist.

I wasn't sure whether this is the specified behaviour. 

It is.


If it is how can it be turned off?

Call .Str or .gist on the argument to print/say as needed.

I suspect that the problem will be resolved by using the x operator 
instead of xx, however. :-)


/jnthn