Rakudo Star silent exit on subset violation?

2010-07-29 Thread Ovid
I don't know if this is reported (I can't find a bug report for it).

I just downloaded and compiled Rakudo Star.

$ uname -a
Linux localhost.bbc.co.uk 2.6.32-24-generic #38-Ubuntu SMP Mon Jul 5 09:22:14 
UTC 2010 i686 GNU/Linux

The bug:

subset Int::Positive of Int where { $_  0 };

sub lotto (Int::Positive $count, Int::Positive $range) returns List {
  die $range must not be less than $count if $range  $count;
  return (1 .. $range).pick($count);
}
.say for lotto(-3,10);
Note that the first argument to lotto is negative and thus violates the type 
constraint.  This code works fine if the first argument is a positive integer 
less than the second argument, but exits with no output otherwise. Making the 
second argument negative (and the first positive) hits the die line, so the 
type constraint is simply being ignored for negative numbers.

If I change the first argument to a float such as 3.2, it seems to round it up 
to 4.

Cheers,
Ovid--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://blogs.perl.org/users/ovid/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




Re: Custom errors on subsets?

2010-01-05 Thread Ovid
--- On Tue, 5/1/10, Jonathan Scott Duff perlpi...@gmail.com wrote:

 From: Jonathan Scott Duff perlpi...@gmail.com

 I'd imagine that the functionality will fall
 out of the ability  to have nice failures because surely
 something like the following works now:
 
 subset Filename of Str where { $_ ~~ :f  or
 fail No such file: '$_' }
 Perhaps s/fail/die/, but that seems like a means
 to your desired end. 

Ah, the die works fine.  However, fail causes that sub call to be skipped 
altogether:

subset Filename of Str where { $_ ~~ :f or fail $_ is not a filename };

sub foo (Filename $name) {
say Houston, we have a filename: $name;
}

foo($*EXECUTABLE_NAME);
say before;
foo('no_such_file');
say after;

Output:

Houston, we have a filename: /Users/ovid/bin/perl6
before
after

Is this a bug or just documented behavior that I don't know about?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




Re: Custom errors on subsets?

2010-01-05 Thread Ovid
--- On Tue, 5/1/10, Solomon Foster colo...@gmail.com wrote:

 From: Solomon Foster colo...@gmail.com

  Is this a bug or just documented behavior that I don't
 know about?
 
 fail just returns an uncalled exception.  What does
 that do in a where block?

I knew it returned an uncalled exception, but I'm still not expecting the sub 
call to be skipped silently due to a constraint failure.  Silent failures are 
bad :)

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




Custom errors on subsets?

2010-01-04 Thread Ovid
Given this code:

subset Filename of Str where { $_ ~~ :f };

sub foo (Filename $name) {
say Houston, we have a filename: $name;
}

my Filename $foo = $*EXECUTABLE_NAME;
foo($foo);
foo($*EXECUTABLE_NAME);
foo('no_such_file');

We get this output:

Houston, we have a filename: /Users/ovid/bin/perl6
Houston, we have a filename: /Users/ovid/bin/perl6
Constraint type check failed for parameter '$name'
in Main (file src/gen_setting.pm, line 324)

Obviously the error message can use some work, but how would I customize that 
error message (assuming such will be possible in the future)?  Clearly there 
will be many cases where a custom error message for constraint failure could 
make life much easier for developers.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Custom errors on subsets?

2010-01-04 Thread Ovid
--- On Mon, 4/1/10, yary not@gmail.com wrote:

 From: yary not@gmail.com

 How about
 multi sub foo(Any $name) { die Houston, we have a major
 malfunction.}

Looks like tha would work, but it forces the developer to remember to write 
this extra code every time they may have a constraint failure, if they forget, 
we're back to the old, cryptic message.  It would be much nicer to be able to 
do this (psuedo-code, obviouly):

  subset Filename of Str where { $_ ~~ :f } 
:OnFail { No such file: '$_' }
  subset Celsius  of Num where { $_ = -273.15 }
:OnFail { Celsius temperature should be a Num = -273.15, not '$_'  }

With something akin to that, developers won't have to write extra boilerplate 
every time a constraint fails.  Plus, the code is friendlier :)

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




Re: Debugging Grammars

2009-12-29 Thread Ovid
As a follow-up to this, I have my code posted at 
http://blogs.perl.org/users/ovid/2009/12/configini-in-perl-6.html

While my admittedly clumsy grammar matches, transforming it into an AST has 
failed miserably.  

Aside from the advent calendar or the online docs at 
http://perlcabal.org/syn/S05.html, are there any other resources for explaining 
the generation of an AST from a grammar?
 
Cheers,
Ovid--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



- Original Message 
 From: Patrick R. Michaud pmich...@pobox.com
 To: Ovid publiustemp-perl6langua...@yahoo.com
 Cc: perl6-langu...@perl..org
 Sent: Sun, 27 December, 2009 16:57:44
 Subject: Re: Debugging Grammars
 
 On Sun, Dec 27, 2009 at 01:30:18AM -0800, Ovid wrote:
  
  my $config = Config::Tiny::Grammar.parse($text);
  #say $config ?? 'yes' || 'no';
  say $config.perl;
  
 
  Currently this matches, but if I add a \s* before the final \n 
  in the section token, it fails to match.  I don't know why 
  this is and I'm unsure of how to debug Perl 6 regexes.
 
 Any \s* will end up matching the final \n, and since quantifiers
 in tokens default to non backtracking, \s* \n in a token will 
 always fail.  (In P5, it'd be like (?\s*)\n.)  Perhaps 
 \h* \n would do what you want here?
 
 Alternatively, you can force backtracking by using \s*! instead.
 
 The new version of Rakudo (the ng branch) provides a debugging
 mode that provides some tracing of the grammar as its matching.
 I don't know that it would've found the above yet -- it still needs
 some work.
 
  my $config = Config::Tiny::Grammar.parse($text);
  #say $config ?? 'yes' || 'no';
  say $config.perl;
 
  Also, if I uncomment that 'say $config ??' line, I get the 
  following strange error:
  
ResizablePMCArray: Can't pop from an empty array!
in Main (file , line ) 
 
 It's a parsing error in Rakudo at the moment -- it *should* be 
 telling you that it found a '??' but no '!!'.  Again, the new
 version (arriving in a week or so) should be better about such
 messages.
 
 Pm




Debugging Grammars

2009-12-27 Thread Ovid
To understand grammars better, I figured I would convert Config::Tiny to Perl 
6.  I've started with the following:

grammar Config::Tiny::Grammar {
token TOP {
root_section?
section+
}
token root_section {
property+
}
token section {
^^ '[' \s* $name=-[\n\]]* \s* ']'  \n
property*
}
token property {
^^ \s* $name=-[=]* \s* '=' \s* $value=[\N*] \n
}
}

my $text = Q{
[foo]
};

my $config = Config::Tiny::Grammar.parse($text);
#say $config ?? 'yes' || 'no';
say $config.perl;

Currently this matches, but if I add a \s* before the final \n in the section 
token, it fails to match.  I don't know why this is and I'm unsure of how to 
debug Perl 6 regexes.

Also, if I uncomment that 'say $config ??' line, I get the following strange 
error:

  ResizablePMCArray: Can't pop from an empty array!
  in Main (file unknown, line unknown) 
And adding any property lines like bar=baz causes the grammar to fail to 
match, or switching section+ to section* in the TOP token causes the 
grammar to fail to match.  In short, just about anything I touch seems to break 
the grammar :)

Any suggestions welcome.

Cheers,
Ovid--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




Re: Debugging Grammars

2009-12-27 Thread Ovid
- Original Message 
 From: Patrick R. Michaud pmich...@pobox.com


 Any \s* will end up matching the final \n, and since quantifiers
 in tokens default to non backtracking, \s* \n in a token will 
 always fail.  (In P5, it'd be like (?\s*)\n.)  Perhaps 
 \h* \n would do what you want here?

Works like a charm!

  Also, if I uncomment that 'say $config ??' line, I get the 
  following strange error:
  
ResizablePMCArray: Can't pop from an empty array!
in Main (file , line ) 
 
 It's a parsing error in Rakudo at the moment -- it *should* be 
 telling you that it found a '??' but no '!!'.  Again, the new
 version (arriving in a week or so) should be better about such
 messages.


Aargh! That one bugs me. I can see how I made that mistake, but boy, I should 
have spotted it :)
 
Thanks for your help.

Cheers,
Ovid--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




Compiler Toolkit

2009-11-24 Thread Ovid
Figured I'd brush up on the compiler toolkit described at 
http://www.parrotblog.org/2008/03/targeting-parrot-vm.html

It appears to be out of date..  For example, you cannot run 'make test'.  
Reading the README which is generated with 'perl tools/dev/mk_language_shell.pl 
SomeLang' doesn't help because it refers me to non-existent files.  Anyone know 
about about this area and can fix up a few things so people can dive back into 
writing compilers?

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly..com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




Re: Compiler Toolkit

2009-11-24 Thread Ovid
- Original Message 

 From: François Perrad francois.per...@gadz.org

 the mantra is :
 $ parrot setup.pir
 $ parrot setup..pir test

After successfully building and installing Parrot on my Mac, the parrot 
setup.pir still fails badly.

parrot $ parrot --version
This is Parrot version 1.8.0-devel built for i386-darwin.
Copyright (C) 2001-2009, Parrot Foundation.

This code is distributed under the terms of the Artistic License 2.0.
For more details, see the full text of the license in the LICENSE file
included in the Parrot source tree.

parrot  $ perl tools/dev/mk_language_shell.pl checkit
creating checkit/
creating checkit/README
creating checkit/Configure.pir
creating checkit/setup.pir
creating checkit/PARROT_REVISION
no ops: skipping checkit/src/ops/Makefile.in
no pmc: skipping checkit/src/pmc/Makefile.in
creating checkit/Makefile.in
no doc: skipping checkit/doc/checkit.pod
no doc: skipping checkit/doc/running.pod
no dynext: skipping checkit/dynext/.ignore
creating checkit/checkit/
creating checkit/checkit/.ignore
creating checkit/checkit.pir
creating checkit/src/
creating checkit/src/checkit.pir
creating checkit/src/parser/
creating checkit/src/parser/grammar.pg
creating checkit/src/parser/grammar-oper.pg
creating checkit/src/parser/actions.pm
no pmc: skipping checkit/src/pmc/checkit.pmc
no ops: skipping checkit/src/ops/checkit.ops
creating checkit/src/builtins.pir
creating checkit/src/builtins/
creating checkit/src/builtins/say.pir
creating checkit/t/
creating checkit/t/00-sanity.t
parrot  $ cd checkit/
checkit  $ ls
Configure.pir   PARROT_REVISION checkit setup.pir   t
Makefile.in README  checkit.pir src
checkit  $ parrot setup.pir 
/usr/local/bin/parrot
/usr/local/lib/parrot/1.8.0-devel/library/PGE/Perl6Grammar.pbc
--output=src/gen_grammar.pir  src/parser/grammar.pg
src/parser/grammar-oper.pg
/usr/local/bin/parrot
/usr/local/lib/parrot/1.8.0-devel/languages/nqp/nqp.pbc --target=pir
--output=src/gen_actions.pir  src/parser/actions.pm
/usr/local/bin/parrot -o xyz/xyz..pbc src/xyz.pir
Error reading source file src/xyz.pir.
/usr/local/bin/parrot -o xyz.pbc xyz.pir
Error reading source file xyz.pir.
/usr/local/bin/pbc_to_exe xyz.pbc --install
Unable to open filehandle from path 'xyz.pbc'
current instr.: 'generate_code_gcc' pc 496 (tools/dev/pbc_to_exe.pir:298)
called from Sub 'main' pc -1 ((unknown file):-1)
strip installable_xyz
strip: can't open file: installable_xyz (No such file or directory)

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly..com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: unusual invocants

2009-10-21 Thread Ovid
- Original Message 

 From: TSa (Thomas Sandlaß) tho...@sandlass.de

   So what the OP wants to do is declare a method that is available on
   all those invocants - and only those invocatnts - which do all of
   roles X, Y, and Z.  Granted, you can declare a new role XandYandZ
   that does X, Y, and Z, and define the method there, but that won't
   work on $foo unless you declare explicitly  '$foo does
   XandYandZ' .  The goal is to have the method show up no matter how
   $foo comes to do all three roles.
 
  Right.
 
 I have difficulty seeing the need for a method here. The distinguishing
 feature of a method is the access to the private data of an object that
 can hardly be granted by doing the three roles X, Y and Z. After all
 there's no unique implementation of these roles!

I believe I started this thread, unless we mean John Lang as the OP after the 
rename.

Private state is actually a separate issue and one which the traits 
researchers already dig into. I was asking the special case where:

1. A class consumes two (or more) roles
2. Each roles provides a method with an identical signature
3. The methods are not equivalent and neither role can rely on the other's 
method

 
With that, you have roles which cannot be composed. You must rewrite one (bad 
if you don't own it), or omit one..

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Freezing role methods

2009-10-15 Thread Ovid
--- On Thu, 15/10/09, Richard Hainsworth rich...@rusrating.ru wrote:

 From: Richard Hainsworth rich...@rusrating.ru
  Basically, the problem they have is this T1 (Trait
 1) and T2 each implement a public x() method and other
 methods in T1 and T2 rely on their respective versions of
 x() and trying to rely on another version breaks those
 methods. When class C tries to compose these roles, it has
 a problem.  It can't exclude one x() because that
 breaks the role which needs the excluded x().  It can't
 override x() because you'll likely break both roles. 
 You *could* (this wasn't explained in the paper) extract
 those methods into C::x(), check your callers and dispatch
 as appropriate, but that would get very problematic,
 particularly with roles composed of other roles.
  snip
  How would Perl 6 approach this issue?
    
 S14 states:
 Roles may be composed into a class at compile time, in
 which case you get automatic detection of conflicting
 methods. A role may also be mixed into a class or object at
 run time to produce an anonymous derived class with extra
 capabilities, but in this case conflicting methods are
 overridden by the new role silently. In either case, a class
 is necessary for instantiation--a role may not be directly
 instantiated.
 
 This indicates to me that for perl6 the conflict is
 detected and reported to the programmer to resolve. The
 compiler is not required to resolve the conflict.
 
 Later S14 has:
 There are several ways to solve method conflicts. The
 first is simply to write a class method that overrides the
 conflicting role methods, perhaps figuring out which role
 method to call.
snip
 Am I wrong in thinking the spec answers the question?

Reading the paper I linked to could help to clarify the issue.  In short, there 
are times under my current understanding of roles where you *can't* resolve the 
conflicts.  Two roles, each providing and dependent upon a method x(), such 
that if either tries to use the other's x(), the code will fail. Thus, you 
cannot choose one x() over the other.

frozen traits suggests that the composing class determine which x() it wants 
and statically binding the other x() to its role, thus guaranteeing that no 
role can get the wrong x(), but still allowing classes full control over their 
composition.

I need to read the other responses more closely to understand their reasoning.  
So far, they seem wrong to me, but that's probably because I'm not reading them 
closely enough.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Freezing role methods

2009-10-15 Thread Ovid
--- On Thu, 15/10/09, Richard Hainsworth rich...@rusrating.ru wrote:

 From: Richard Hainsworth rich...@rusrating.ru

 But the assumption in the paper is that the class
 composer resolves the conflict, without further programmer
 intervention. The perl6 spec does not require the class
 composer to resolve the conflict only to detect it.
 
 Given the explanation in the spec about conflict
 resolution, it is my understanding that it is
 the programmer's task to rewrite to eliminate the
 conflict.

Ugh. That's ambiguity in the paper.  Thanks for pointing that out. The specific 
intention is that the programmer has to specifically address this issue (in 
this case, by potentially freezing one or more methods).

At the BBC, we never encounter this because semantically different methods are 
renamed and semantically identical methods are refactored (aliasing and 
excluding being code smells).  However, if roles start making their way on to 
the CPAN, you won't necessarily have control over the source code, forcing you 
to fork or simply not use the role in question.  Regrettably, that defeats the 
purpose of roles -- namely, to facilitate code reuse.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Freezing role methods

2009-10-14 Thread Ovid
I recently was trying to research some composition issues with roles and one of 
the researchers directed me to this paper:

http://scg.unibe.ch/archive/papers/Duca07b-FreezableTrait.pdf

Basically, the problem they have is this T1 (Trait 1) and T2 each implement 
a public x() method and other methods in T1 and T2 rely on their respective 
versions of x() and trying to rely on another version breaks those methods. 
When class C tries to compose these roles, it has a problem.  It can't 
exclude one x() because that breaks the role which needs the excluded x().  
It can't override x() because you'll likely break both roles.  You *could* 
(this wasn't explained in the paper) extract those methods into C::x(), check 
your callers and dispatch as appropriate, but that would get very problematic, 
particularly with roles composed of other roles.

The only way to handle this appears to be renaming one of the x() methods and 
trying to track down all code which relies on it and changing it.  This 
essentially violates the problem we're trying to solve with traits, er, roles.

In short, under the original traits model, you have roles you can't compose 
together.  The paper argues that in languages which have public and private 
methods, that the composing class is allowed to decide which x() method it 
needs (if any) and that it can *freeze* the other x() method.  That is to say, 
the x() in question would become private and statically bound to the invocants 
to ensure that they're always calling the correct x().

How would Perl 6 approach this issue?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Trait researches on class wins in role composition

2009-10-14 Thread Ovid
Summary: the original trait researches did intend for class methods to have 
precedence over roles methods in composition, but they had no intention that it 
do so silently.  In fact, they go on to say that doing so silently would be a 
bad idea.  One way of resolving this is to do what Sun finally realized that 
Java needed to do: they provide an @Override annotation for methods which 
override parent methods.  The compiler should warn if an overridden method is 
not annotated as such 
(http://java.sun.com/javase/7/docs/api/java/lang/Override.html).

See http://use.perl.org/~Ovid/journal/39751 for more information, including 
relevant correspondence with the researches (used with permission).

Would Perl 6 consider a feature to add a warning if a class method silently 
takes precedence over a role method?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: Freezing role methods

2009-10-14 Thread Ovid
--- On Wed, 14/10/09, Jon Lang datawea...@gmail.com wrote:

 From: Jon Lang datawea...@gmail.com

 The initial possibility that springs to mind would be to
 use longnames
 to disambiguate between the two options - specifically, by
 means of
 the invocant:
 
     role T1 { method foo() }
     role T2 { method foo() }
     class C does T1 does T2 {
         method foo(T1 $self:) {
 $self.T1::foo() }
         method foo(T2 $self:) {
 $self.T2::foo() }
     }
 
 ...or something to that effect.  You'd still have a
 disambiguation
 issue, in that you'd somehow need to specify which hat an
 object of
 class C is wearing when you try to call the method. 

Except that if a consumer of C needs foo(), they have to fully qualify the call 
to foo().  That violates encapsulation.
 
 Much of this could be handled implicitly, by means of which
 role was
 requested when the object was passed into the current
 block:
 
     sub bar (T1 $x) { ... }
     sub baz (T2 $x) { ... }
     my C $x;
 
     bar $x;

Same problem as above.  Works for C, but not for consumers of C which need to 
call foo().

 In other cases, there may be no way to implicitly
 disambiguate.  In
 those cases, there would need to be an explicit way to
 decide which
 hat the object is wearing.

I really don't think that deferring the decision works.  The freezing 
technique described in the paper allows the consumer, C, to statically bind the 
method foo() in the methods in the appropriate role which call it.  Dynamic 
binding defers the decision which causes implementation details to leak to 
consumers of C.  This means that if you change your roles, your consumers will 
potentially need to be rewritten.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [perl #69322] Segfault in say 4.HOW.HOW

2009-09-24 Thread Ovid
- Original Message 

 From: Christoph Bussenius perl6-bugs-follo...@perl.org
 
 Hi,
 
 this produces a segfault with the current rakudo version
 (0220cc22acefd5567c03b562eab3dd06fe53e6d8)
 
 ./perl6 -e 'say 4.HOW.HOW'

Various things seem to generate segfaults:

  rakudo  $ ./perl6 -e 'say 4.^can(int)'
  
Segmentation fault
  
rakudo  $ ./perl6 -e 'say 4.^can(Int)'
   # no output

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Parrot in Firefox

2009-07-20 Thread Ovid

Hi all,

Aza Raskin, the head of user experience at Mozilla labs 
(http://en.wikipedia.org/wiki/Aza_Raskin), was giving a talk at the BBC today 
and I asked him  about multiple client-side language support.

The short response is that this will not be implemented soon, but it sounded 
like they were leaning towards the LLVM (http://en.wikipedia.org/wiki/Llvm) to 
implement this.   In fact, Aza seemed to be under the impression that Parrot 
was a dead project.  I asked permission to mail him about this later and he 
said yes (I suspect he might simply have been polite) and I'm wondering the 
best way to approach this.

My first thought (for Parrot devs), one which I know has been discussed before, 
is about sandboxing Parrot and how to implement authorities for adjusting the 
sandbox restrictions.

My second thought is rather blue sky (and directed at Mozilla, but I'll mention 
it here) is how this would look on the client side.  Here's what I think would 
be a sample API:

  script 
grammar=http://my.server.com/my/custom/grammar/; 
version=1.2 
authority=https://my.server.com/grammar/authority/;

include My.Login;
Document login_form password matches(SafePassword)
  or element error(Password must match #{SafePassword});

  /script

 
In other words, if the sandbox is secure enough, one could use the Parrot 
Compiler Toolkit to write a set of bindings to allow you to write your 
client-side in any language you like, include bespoke languages, if desired.  I 
think this could be a very compelling feature and perhaps might pique Mozilla's 
interest.  More to the point, Aza specifically mentioned that he wants to write 
his client side code in Python.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Parrot in Firefox

2009-07-20 Thread Ovid

- Original Message 

 From: Ovid publiustemp-perl6compil...@yahoo.com
 
 Hi all,
 
 Aza Raskin, the head of user experience at Mozilla labs 
 (http://en.wikipedia.org/wiki/Aza_Raskin), was giving a talk at the BBC today 
 and I asked him  about multiple client-side language support.

I forgot to mention that there's some unofficial internal (BBC)
interest in something like this.  I can't say if we'd support this
effort directly, but I'd certainly try and push for it if it looks like
it's realistic.  Having the Parrot Foundation, the Mozilla Foundation
and the BBC all plugging a project could be a huge win for everyone
involved.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: RFC: overriding methods declared by roles (Was: Re: Reusing code: Everything but the kitchen sink)

2009-07-13 Thread Ovid

- Original Message 
 From: Jon Lang datawea...@gmail.com

 Right.  But as they were originally conceived, they were interfaces
 that could also handle code reuse, rather than units of code reuse
 that could also be used as interfaces.  From this perspective, it
 makes perfect sense that a role's methods can be overridden as easily
 as they are.

As originally conceived in Perl 6 or in the original traits papers?  In the 
original research, the purpose of roles was to allow the decoupling of 
responsibility and behavior (code reuse) found in inheritance-based OO systems. 
 Traits (roles) took over code reuse.

 But you make a good point: there are some (a few? most?) programmers
 who are going to want to use roles primarily for code reuse, and who
 will want it to be a little more difficult to override the code
 provided by a role (e.g., requiring the use of supersede and perhaps
 augment in order to replace the definition with a new one).

Just to give people some real data to play with (our system may not be 
representative), here's some sample source code and some imformation about our 
use of roles in the BBC.

package PIPs::ResultSource::Series;
use Moose;
extends 'PIPs::ResultSourceBase::BrandSeries';
with qw(
PIPs::ResultSource::Role::DoesParentChildRelationships
PIPs::ResultSource::Role::DoesTags
PIPs::ResultSource::Role::DoesContentObject
PIPs::ResultSource::Role::DoesInspector
PIPs::ResultSource::Role::DoesRelatedLinks
PIPs::ResultSource::Role::DoesIdentifiers
PIPs::ResultSource::Role::DoesChangeEvents
);

 
(The astute reader will not that the base class is awful, but it's been a long, 
hard slog to get this far).

Most of our classes which implement roles have similar preambles, but with 
different behaviors listed.

Other points of interest.  Only 11 of 114 classes which implement roles exclude 
any methods (none use method aliasing) and we currently have 40 roles 
implemented.  

Only three classes provide methods which override role's methods, but in the 
few cases they do, we explicitly exclude the methods from the role to make it 
clear that we need to do this.  We had more overriding of role's methods, but 
continual refactoring has pushed those into roles.

 
So we're very, very heavily on the use roles for shared behavior side.  The 
relative paucity of overridden role methods suggests to me that (for our code), 
the annoyance of having to be explicit for overridding a role's methods easily 
offset by how hard it's been to debug this issue.  That being said, the pain in 
debugging might have been a side effect of the fast transformation from a 
complex inheritance hierarchy to a roles-based system.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: YAPC::EU and Perl 6 Roles

2009-07-08 Thread Ovid

- Original Message 
 From: Timothy S. Nelson wayl...@wayland.id.au

 class PracticalJoke {
 has Bomb $bomb handles ;
 has Spouse $spouse handles ;
 }
 
 Note that I have no idea where (if anywhere) the type goes in this. 
 Hopefully someone will correct me here.  Note that this does not use the 
 roles 
 as roles; it uses them punned as classes.  But it does what you asked :).


Though I have issues with Jonathan's approach (I don't like classes silently 
discarding role methods as this has caused us many bugs at the BBC), it's much 
cleaner that what I see here.  You see, with Jonathan's, you only have to 
provide methods for what you're disambiguating, It seems like your code would 
require that I specifically list every method which is handled, which would 
clearly get unwieldy with large roles or many roles.  Did I miss something?
 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: YAPC::EU and Perl 6 Roles

2009-07-08 Thread Ovid

- Original Message 

 From: Jonathan Worthington jonat...@jnthn.net

 Ovid wrote:
  It needs the timed fuse() from a Bomb role and a non-lethal explode() from 
  a 
 Spouse role, though each role provides both methods.
 I'm curious...
 
 1) How often do you in real life find yourself needing to do things like this 
 in 
 real life? This is a sort of strained, if amusing, example. :-)

We use roles very, very heavily.  We've found that the important thing is 
choosing descriptive names.  Thus, we rarely need to exclude methods from roles 
because our names are unambiguous.  The only time I recall us running into this 
problem is when we have two or more methods with identical names which perform 
semantically identical behaviors but need different implementations.
 
 2) A lot of me wonders if a need to exclude a method from a role is a hint 
 that 
 the role does too many things and should be decomposed into smaller pieces, 
 such 
 that it can be applied in a more granular way?

As noted, we only have this happen when the semantics are identical but the 
implementation must differ.  At this point, we really do need a way to exclude 
methods.  This doesn't happen very often, but it's happened enough (probably 
about 10 times in our code base) that a convenient way of handling this would 
be useful.

 I'm curious to hear the experiences of Ovid and others working with roles a 
 lot 
 too. Is this a serious lacking in Perl 6's roles as currently specified, or 
 something that, in being absent, makes people consider their design more? 
 Knowing that will influence the solution we choose, which has options ranging 
 from, yes, make a neat syntax for it through leave it out of the core, and 
 if 
 people want it enough it can be a CPAN module.

Actually, the only serious concern I have (pardon me if you've heard this 
before) is how we silently discard a role's method if the class provides it.  A 
digression is in order.  Some of you know the background behind roles, but not 
everyone.

The problem with classes is that they tend to have two competing uses.  Classes 
are agents of responsibility (which tends to make them grow larger) and, via 
inheritance, are agents of code reuse (which tends to want classes to be 
smaller).  These competing tendencies have been a source of much OO pain and 
roles decouple the behavioral reuse from class responsibility quite nicely.

That being said, roles also have two competing uses (though they don't conflict 
as badly).  As units of behavior, they provide the functionality your code 
needs.  However, they can also serve as an interface.  The behavioral/interface 
divide has already demonstrated a subtle tension in the use of roles in my work.

For those of you who have seen the arguments about this rage on use.perl, my 
apologies :(

Interface:  if you are taking advantage of a role as an interface, it's quite 
useful to have your class provide one or more methods with an identical 
signature to the role and have the role's method silently ignored.

Behavioral:  if you are primarily relying on roles to provide behavior (as we 
do at the BBC), then silently discarding the role's behavior by providing a 
method of the same name in your class can lead to very confusing bugs.  I've 
lost a lot of time debugging this behavior.

I'd like to see something like this (or whatever the equivalent Perl 6 syntax 
would be):

  class PracticalJoke does Bomb does SomeThingElse {
method fuse() but overrides { ... }
  }

The overrides tells Perl 6 that we're overriding the fuse() method from 
either Bomb or SomeThingElse (or both).  Otherwise, a warning or exception 
would be useful to prevent me from accidentally overriding needed behavior.  
Again, we've lost a huge amount of time debugging this behavior with 
Moose::Roles and I'd hate to have to do this again with Perl 6.  Your mileage 
may vary :)

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


YAPC::EU and Perl 6 Roles

2009-07-07 Thread Ovid

Giving a talk about roles at YAPC::EU in Lisbon and I'm a bit stuck on how to 
translate a Perl 5 example into Perl 6.  Basically, Imagine a PracticalJoke 
class which has fuse() and explode methods().  It needs the timed fuse() from a 
Bomb role and a non-lethal explode() from a Spouse role, though each role 
provides both methods.  In Moose, it's easy:

  package PracticalJoke;
  use Moose;
  with 'Bomb'   = { excludes = 'explode' };
   'Spouse' = { excludes = 'fuse' };

Try as I might, I can't figure out how to translate that into Perl 6.  I have 
the following:

  role Bomb {
method fuse (){ say '3 .. 2 .. 1 ..' }
method explode () { say 'Rock falls. Everybody dies!' }
  }

  role Spouse {
method fuse (){ sleep rand(20); say Now! }
method explode () { say 'You worthless piece of junk! Why I should ...' }
  }

  class PracticalJoke does Bomb does Spouse {
  }

Nothing I see in S14 (http://perlcabal.org/syn/S14.html) seems to cover this 
case. I can't declare them as multis as they have the same signature.  There's 
a note that one can simply to write a class method that overrides the 
conflicting role methods, perhaps figuring out which role method to call, but 
I don't understand how a particular role's methods would be called here.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



rakudo.org rss

2009-06-11 Thread Ovid

The RSS feed for rakudo.org shows the last update as Feb 28, 2009.  Wasn't 
certain from the site where I should send a contact email.  Thus, rss complaint 
list spam!

http://rakudo.org/rss.xml

 
Cheers,
Ovid

PS:  Thanks for all of the fantastic work, folks!
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Roles driven by events

2009-03-16 Thread Ovid
Having a problem with the following role in Perl 5:

  package PIPs::ResultSource::Role::HasTags;
  use Moose::Role;

  requires 'do_setup';
  after 'do_setup' = sub { ... };

So far this has worked really well, aside from that one class which didn't call 
'do_setup'.  Oops.

Requiring methods and requiring methods to be called are different things.  It 
might be a nice feature to have roles which tie into events.  If a particular 
condition doesn't hold true by, say, INIT time, the role fails.

How would I implement something like that in Perl 6?  Or am I just looking at 
this wrong?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: Recursive Runtime Role Reapplication Really Rebounds

2009-03-12 Thread Ovid

- Original Message 

 From: David Green david.gr...@telus.net

 I suppose, but is there a reason why you want to apply roles instead of 
 coercing 
 the results?
 
 $x = Role::Serializable::XML $resultset;
 $y = Role::Serializable::YAML $resultset;


Because I am coming from Moose instead of Perl 6 and didn't know about this :) 

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Recursive Runtime Role Reapplication Really Rebounds

2009-03-09 Thread Ovid

- Original Message 

 From: Ovid publiustemp-perl6langua...@yahoo.com

 Eventually, the code broke and threw a bunch of weird recursive inheritance 
 warnings due to multiple anonymous classes being applied to the object.  This 
 was *real fun* to debug, but I can imagine a scenario for this being natural:
 
 Your REST interface returns XML, but sometimes someone wants YAML.  So you 
 have:
 
   $resultset does Role::Serializable::XML
 
 But sometimes:
 
   $resultset does Role::Serializable::YAML
 
 Since you cache resultsets if they've not changed, you could easily have the 
 XML 
 and YAML roles getting reapplied at runtime multiple times.  

Could this issue be mitigated with temp variables?

  {
  temp $resultset does Role::Serializable::YAML;
  print $resultset.as_string;
  }

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Recursive Runtime Role Reapplication Really Rebounds

2009-03-08 Thread Ovid

(OK, the subject sucked, but I tried :)

From S14:

  You can, however, say
  $fido does Sentry;
  $fido does Tricks;
  $fido does TailChasing;
  $fido does Scratch;
  snip
  Unlike the compile-time role composition, each of these layers
  on a new mixin with a new level of inheritance, creating a new 
  anonymous class for dear old Fido, so that a .chase method from 
  TailChasing hides a .chase method from Sentry.

Recently I reported a bug in Moose's runtime role application:

  http://rt.cpan.org/Public/Bug/Display.html?id=43904

The problem was very hard to track down because I was effectively doing 
something like this:

  $object-meta-apply('Some::Role') while 1;

(The reality is that we had a singleton with a role applied to it multiple 
times).

Eventually, the code broke and threw a bunch of weird recursive inheritance 
warnings due to multiple anonymous classes being applied to the object.  This 
was *real fun* to debug, but I can imagine a scenario for this being natural:

Your REST interface returns XML, but sometimes someone wants YAML.  So you have:

  $resultset does Role::Serializable::XML

But sometimes:

  $resultset does Role::Serializable::YAML

Since you cache resultsets if they've not changed, you could easily have the 
XML and YAML roles getting reapplied at runtime multiple times.  

I don't see anything in the spec addressing this.  Aside from don't do that, 
is this something which can be addressed in perl instead of Perl?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Rakudo repository -- svn or git?

2009-01-28 Thread Ovid
- Original Message 

 From: Patrick R. Michaud pmich...@pobox.com

 I will be making a decision (and possibly starting the
 migration) tomorrow.  If anyone has any strong opinions
 one way or another, please let them be known quickly.

 
Hope I'm not too late to chime in.

Subversion's OK, but I would definitely prefer git.  I've only used it for a 
few small projects, but already it's impressed the heck out of me for its 
behavior in both big things (branching) and small things (git diff 
automatically pages).

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: RFD: Built-in testing

2009-01-24 Thread Ovid
- Original Message 

 From: jerry gay jerry@gmail.com

 i don't understand the drive to have unique test identifiers. we don't
 have unique identifiers for every code statement, or every bit of
 documentation. why are tests so important/special/different that each
 warrants a unique id?

 
Actually, if code is well-written, we *do* sort of have unique identifiers.  
Bob, you need to change Customer::name to also show the middle initial.  We 
don't really have anything like that in tests unless we move close to the xUnit 
style.  TAP has no concept of this.

Unique identifiers are useful in that they can let you track changes over time 
(many of us use source control history to understand changes over time for 
code).  It would be very useful to have unique identifiers to persist to a db 
and create graphs of one's test suite behavior (hey, we keep failing out 
credit card tests. We should look into this more carefully!).

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


.trim and 'gilding the lilly'

2009-01-24 Thread Ovid
In chromatic's latest Perl 6 Design Minutes post 
(http://use.perl.org/~chromatic/journal/38334), he writes 

   Missing a discussion on.trim and gilding the lily. 

   Nicholas: 
  * if I wanted PHP I know where to find it

So there's a lot of context missing there and I'm unsure of what this implies, 
but if it's deemed that .trim and friends are too much, so be it.  I would 
submit that .chop is also a great candidate for removal (.chop?  Why is it even 
in there?)

Is there guidance on where to go from here or what the balance is between 
convenience functions and the bare minimum?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: .trim and 'gilding the lilly'

2009-01-24 Thread Ovid
- Original Message 

 From: Nicholas Clark n...@ccl4.org

 You can also write that as a single substitution, although it turns
 out the combined statement is slower than the separate ones. That
 might not matter to you, though.
 
 s/^\s+|\s+$//g;
 
 
 If there's one answer that is both elegant and fast, there is no longer a
 compromise needed, nor do journeymen programmers waste time questing for a
 better answer that masters know does not exist.*

You know, I rewrote .trim as:

  .sub 'trim' :method :multi(_)
  .local string s
  s = self
  s = 'trim_start'(s)
  s = 'trim_end'(s)
  .return(s)
  .end

I thought about the performance issue but opted for correctness and no 
duplicate code.  I figured it's trivial to speed up later, if need be.

Short of trying to figure out how to survey the CPAN and see what people are 
really doing with strings, I'm unsure of how to solve the useful/baggage 
dichotomy.  Maybe just going through and turning the Perl 5 Cookbook into a 
series of builtins ... :)

(Note that the latter suggestion was a joke.  Mostly)

I'd still opt for removing .chop, though.  I think only once have I ever seen 
it used appropriately.  All other times the user wanted .chomp.
 
Cheers,
Ovid



Re: .trim and 'gilding the lilly'

2009-01-24 Thread Ovid
- Original Message 

 From: Nicholas Clark n...@ccl4.org

 I can't keep up with the typing even with my mouth shut. I definitely can't
 think, talk and type at the same time.

For what it's worth, I have trouble doing more than *one* of those at once.

In any event, it's nice to get a slightly better idea of what others are 
thinking.

(And a bit thanks to chromatic for regularly posting those updates.  It helps a 
lot)


Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



[PATCH] Updated trim() functions

2009-01-23 Thread Ovid
This patch provides trim_start() and trim_end() per earlier discussions.  
trim() is rewritten in terms of those.  There were some discussions about how 
other data structures should be handled, so until there's a spec or a much 
clearer agreement on the lists, I'm leaving that off.

Tests for this are already committed to Pugs.  I'll remove the fudge when/if 
this gets applied.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


trim.patch
Description: Binary data


Re: RFD: Built-in testing

2009-01-22 Thread Ovid
- Original Message 

 From: jerry gay jerry@gmail.com

 since the :ok adverb is modifying the operator, perl  knows what kind
 of comparison is being attempted, and can automatically give smart
 diagnostics. this point was taken into consideration when the
 adverbial test syntax was originally designed. some examples of perl 6
 tests using adverbial notation:
 
   plan *;
   3 === 3 :ok('int constant is equivalent to string constant integer');
   3 !~~ 3 :ok('int constant smartmatch to string constant integer')
   my $x = 284;
   +$x == 284 :ok('$x is 284');
   ?$x :ok('$x is True');
 
 there will no longer be ok() and is() functions, so although is() is
 still a floor wax and a dessert topping, it has nothing to do with
 testing. the comparisons are now explicit, so the intent of the test
 isn't hidden behind a friendly-looking but difficult to debug function
 like is().

Reading through that log more carefully now.  Sorry I didn't do that earlier.

One concern is where Larry asks:

I wonder how often we'd have people making the error
of trying to interpoalte into :okbad $x pardner

 
I'd be one of them.  The following is a very common idiom:

for my $method (@methods) {
can_ok $object, $method;
lives_ok { $object-$method } ... and calling '$method' isn't fatal;
}

Interpolation in the test description is very important on iterative tests or 
to distingiush similar tests (sometimes it would be nice to go so far as to ban 
identical test descriptions).

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: RFD: Built-in testing

2009-01-22 Thread Ovid
- Original Message 

 From: Moritz Lenz mor...@faui2k3.org

 So Larry and Patrick developed the idea of creating an
 adverb on the test operator instead:
 
 $x == 1e5   :ok('the :ok makes this is a test');
 
 This is an adverb on the infix:== operator, and might
 desugar to something like this:
 
 multi sub infix:==($left, $right, :$ok) {
 $*TEST_BACKEND.proclaim($left == $right, $ok)
 or $*TEST_BACKEND.diag(
 Got: «$left.perl()»; Expected: «$right.perl»);
 }

Regarding the disadvantages:

 However nothing in life is free, we pay for it with a
 few disadvantages:
 * We nearly double the number of built-in operators
by adding an :ok multi

Yes, but conceptually this will be transparent to the end user, right?  They'll 
just know that they can add :ok to operators.  They'll mentally have one extra 
piece of information, not twice as many.

Are there other consequences of this?

 * We force implementors to handle operator adverbs
and named arguments very early in their progress
(don't know how easy or hard that is)

This might be a problem.  After my (now possibly moot) rewrite of Test.pm was 
finished, my plan was to write a basic Test.pm which required as few features 
as needed but still allowed the spectests to run.  Then you simply provide 
language developers a list of features they need to implement to run the test 
suite.  Adding operator adverbs to the mix means a lot of rewriting of tests.

Alternatively, we can say you don't need these at first and Test.pm is merely 
a older way of running tests.  It still remains a valid alternative and new 
implementers don't need to worry about adverbs. 

 * Testing of operators becomes somewhat clumsy. If you
 * want to test infix:==, you won't write
'2 == 2 :ok(== works)', because you test a
different multi there. Instead you'd have to write
something like '?(2 == 2) :ok(== works)', where
:ok is an adverb on prefix:.

Bad:

  2==2 :ok(== works);

Good:

 ?(2==2) :ok(== works);

I don't relish explaining, over and over again, why the first is bad and the 
second is good.  That being said, if this is only used for internals tests, is 
this likely going to be exposed?

 So I'd like to hear your opinions: do you think
 adverb-based testing is a good idea? If you don't like
 it, do you see any other good way to tackle the
 problems I mentioned above?

So how would the following work?

  can_ok
  lives_ok
  throws_ok
  isa_ok
  is_deeply

And so on?  Sure, I can write extensions for this, but they're so common that 
it seems a shame to not have them built-in, but what operator would they hook 
to?

Also, if we're going to go whole hog on this, then may I suggest a tests or 
test keyword?  We might have :ok embedded in our code, in which case running 
multiple sections of code might have multiple sections with :ok.  How do test 
numbers work?  When Foo.pm calls Bar.pm calls Baz.pm and they all use :ok, we 
may not know how many tests we have, so these might get handled different from 
something like this:

  test Unit::Customer plan 3 {
  use Customer;
  my Customer $cust .= new( :fnameBilly, :lnameBob );
  $cust.fname eq 'Billy' :okfname should match;

  # plan assumes 2 referrals
  # won't work because we can't interpolate?
  for $cust.referrals - $ref_cust {
  $ref_cust.referrer === $cust :ok{$ref_cust.name} should have correct 
referrer;
  }
  }

With a scheme like this, we can separate tests explicitly written by 
programmers for testing and those which are embedded.  If the referrals method 
has :ok in it, this shouldn't impact the overall plan, right?

Side note: for the desugar, I'd still prefer we go with 'have/want' instead of 
'got/expected'.  We've been wanting to do this with TAP for a while. It reads 
well and also aligns nicely for fixed-width fonts.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: RFD: Built-in testing

2009-01-22 Thread Ovid
- Original Message 

 From: Moritz Lenz mor...@faui2k3.org

test Unit::Customer plan 3 {
use Customer;
my Customer $cust .= new( :fname, :lname);
$cust.fname eq 'Billy' :ok;
  
# plan assumes 2 referrals
# won't work because we can't interpolate?
for $cust.referrals - $ref_cust {
$ref_cust.referrer === $cust :ok{$ref_cust.name} should have 
 correct referrer;
}
}
snip
 I'll think a bit more about these points.

I've been thinking about this and have realized that it also solves an 
intractable problem with Perl 5 tests:  identifying tests.

By promoting 'test' to a first class concept (not just adjectives), you can 
name a test.  Right now, I'm trying to write App::Prove::History 
(http://github.com/Ovid/app--prove--history/tree/master), a bad name for code 
which saves the state of test runs.

One incredibly thorny problem I have is that tests are identified by the name 
of the file.  Reorganize your tests in directories or rename 'em?  You've just 
lost your test history.  However, if tests have an implicit name, developers 
are no longer locked into a directory hierarchy to identify their tests.  This 
also brings us conceptually closer to the xUnit crowd.

I would say for the above, if referrals had embedded :ok tests, they could be 
output as warnings (if failing) or be provided via some mechanism that would 
let them be embedded into a TAP stream (or other test protocol) so that the 
information is not lost.

I also wonder if 'plan' might not belong there.  Not all testing protocols 
implement that and perhaps some developers won't want it.  So long as their 
tests don't prematurely exit, they know they've run all of their tests.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: RFD: Built-in testing

2009-01-22 Thread Ovid
- Original Message 

 From: jerry gay jerry@gmail.com

 On Thu, Jan 22, 2009 at 09:22, Moritz Lenz wrote:
  Richard Hainsworth wrote:
  But it is interesting to think about the case where a user wants two
  different diagnostic test messages (to all the testing gurus out there:
  do you actually want such a feature?). It shouldn't be too hard to do;
  maybe just  :OK('True message', 'False message')?

I can't speak for others, but I only want one diagnostic message, with the 
option to turn it on for passing tests.  Having different messages for 
different conditions will confuse me :)

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Test.pm and skip()

2009-01-21 Thread Ovid
The skip multisub in Rakudo's Test.pm is defined like this:

  multi sub skip()  is export() { proclaim(1, # SKIP); }
  multi sub skip($desc) is export() { proclaim(1, # SKIP  ~ $desc); }
  multi sub skip($count, $desc) is export() {
  for 1..$count {
  proclaim(1, # SKIP  ~ $desc);
  }
  }

The first is reasonable, but the second and third awkward.  We have positional 
parameters whose position changes based upon the number of arguments.  We could 
do something like this:

  multisub skip();
  multisub skip(Int $count);

  multisub skip(Str $desc);
  multisub skip(Int $count, Str $desc);

However, that's going to break if $count is a string, right?

I am thinking that the Perl 5 way is better here.  We have (effectively):

  multisub skip(Str $desc);
  multisub skip(Str $desc, Int $count);

Otherwise, we stick with named parameters, but that's a bit odd since every 
other function exported uses positional parameters.

Thoughts?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: RFD: Built-in testing

2009-01-21 Thread Ovid
- Original Message 

 From: Moritz Lenz mor...@faui2k3.org

 * the word 'is' is overloaded in Perl 6
* if we export subs is() and ok(), we clutter the
  namespace with subs with short names 
* is() is rather imprecise; it doesn't say *how*
  things are compared.
snip
 So Larry and Patrick developed the idea of creating an
 adverb on the test operator instead:
 
 $x == 1e5   :ok('the :ok makes this is a test');

This may all be irrelevant, but I'm tossing it out here in case anyone thinks 
of how it might impact things.

I'm not entire certain how I feel about this yet, but I love the core concept 
of making testing a first class feature (well, duh ... of course I would say 
that :)

I'd like for this to be thought through really carefully lest we create an 
interesting idea which is hampered by its implementation.  Specifically, I'm 
concerned about diagnostics.  What we'd ultimately love to have in TAP is some 
way of improving diagnostics (pseudo-TAP).

  is 3,3 'constants are constants;
  # ok 1 - constants are constants
  # have: 3
  # want: 3

Now we have a curious situation:

  multisub foo(Str $bar);
  multisub foo(Int $bar);

If we're testing what we should pass to foo:

  is 3,3 'constants are constants;
  # ok 1 - constants are constants
  # have: 3
  # want: 3

Integration tests will still do OK, but unit tests may have issues and this 
could be an expectation violation.  What does it mean that the string 3 eq the 
integer 3?

Worse:

  my $bar = 284;
  ok $bar, '$bar should be true';
  # ok 1 - $bar should be true
  # have: 284
  # want: True

That can also look a bit strange, particularly if someone is coming from a 
different language background.

How would this new system handle diagnostic information?  One thing which might 
mitigate this is something we've wanted in newer versions of TAP:

  my $bar = 284;
  ok $bar, '$bar should be true';
  # ok 1 - $bar should be true
  # test: ok $bar, '$bar should be true';
  # have: 284
  # want: True

By letting programmers see the exact line of code for the test, the type 
information *might* not be as important.  I'm unsure.

One possibility is to look at the Test::More::cmp_ok function:

  $ perl -MTest::Most=no_plan -e 'cmp_ok 3, ==,2'
  not ok 1
  #   Failed test at -e line 1.
  #  got: 3
  # expected: 2
  1..1

If you change 2 to 3, the test still passes, but we could force it to not 
pass unless eq is passed in as the second argument.  Then we could have the 
following diagnostics:
 
  perl6 $ perl -MTest::Most=no_plan -e 'cmp_ok 3, eq,3'
  not ok 1
  # have: 3
  # test: eq
  # want: 3
  1..1

And then it's crystal clear why it failed.

Cheers,
Ovid



Re: Rakudo leaving the Parrot nest

2009-01-15 Thread Ovid
- Original Message 

 From: Patrick R. Michaud pmich...@pobox.com

 Many people have strongly suggested that we switch to
 using git as our version control system.  At the moment I'm
 neither strongly in favor of nor strongly opposed to switching
 version control systems, but we have to recognize that at least
 two of Rakudo's dependencies (Parrot and the spectest suite) 
 are using Subversion and are likely to remain that way for 
 a while.  We don't want to require non-developers to install a 
 lot of different source code control systems simply to run and 
 test the latest incarnation of Rakudo Perl.

I'm not going to jump up and down about this issue.  At the very least, 
Subversion isn't CVS.  However, it *is* Subversion which means we have a 
painful source control system which attempts to wrap a soft cloth around the 
hammer to the head that is CVS.  For it's time, Subversion was great.  
Subversion is no longer great.  I find that it's not too hard to use simply 
because I use it, not because I like it.

With my admittedly limited exposure to git, it is superior in terms of both 
usability and design to Subversion.  I admit, though, that many people are not 
willing to learn a new source control system (and does it still have Windows 
issues?).  If that's the primary objection to git, I could accept that 
argument.  If the primary objection is merely to accept the fact that we have a 
bunch of architecture based on bad technology, then we're making the decision 
for the wrong reason.

(I just need to install svk and have at least *some* of my subversion pain go 
away)

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Rakudo leaving the Parrot nest

2009-01-15 Thread Ovid
- Original Message 

 From: Patrick R. Michaud pmich...@pobox.com

 Moritz already replied with why spectest is currently in pugs, I
 tend to agree.  For now I'd like spectests to continue to have
 a very liberal commitbit policy, and that may or may not be
 compatible with Rakudo's commitbit policy (depending on how
 things end up).

I buy the arguments put forward.  Some had been explained before and now that 
I'm reminded, yeah, they make sense.


Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Extending classes in a lexical scope?

2009-01-14 Thread Ovid
- Original Message 


 As far as I know, Perl6Array should _not_ be showing up in
 Perl 6's namespace, and if it is doing so, that's a reportable
 bug.

I was just being sloppy.  I was using that in PIR, not Rakudo, and I mistyped 
the type -- er, I wrote the wrong class name in writing that email.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: Trimming arrays

2009-01-14 Thread Ovid
- Original Message 

 From: Patrick R. Michaud pmich...@pobox.com
  I would expect this to be roughly equivalent to:
  
  for @array { $_ .= trim; }
  
  For an array of hashes, this would result in each hash element
  of @array being replaced with a reference to an array of the 
  trimmed string representation of the hash.
 
 Oops -- I over-referenced here.  The corrected form:
 
 For C @array».=trim ,  each element of @array would be replaced 
 with its trimmed string representation.  If @array starts out
 as an array of hashes, then @array».=trim would leave @array 
 with the trimmed stringification of each hash element.

I don't get this.  If I can't call @array.trim, I certainly can't call 
%hash.trim.  If you mean stringify the hash and then trim *that*, what does 
that mean?  We get that all the time in Perl 5 and I've written tests to catch 
things like HASH(0x80631d0) showing up in templates.  This is probably some of 
the most useless behavior in Perl 5 and I don't want to see it propagate to 
Perl 6.  Either that should die violently or it should do something useful and 
I'm unsure of what would be useful here.

A hash is basically a set of pairs.  You *can't* trim the keys because they're 
supposed to be unique.  Otherwise, what does it mean to trim { '  foo' = 1, 
'foo  ' = 2 }?  So we can only trim values, but what if the values are pairs?  
Then wouldn't you effectively be apply the hyperop recursively throughout the 
data structure?  That might be expensive and have unwanted side-effects (what 
do you mean my hash had a reference to your ORM data?).

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [perl #62366] AutoReply: [PATCH] Add 'no_plan' and die_on_fail to Test.pm

2009-01-14 Thread Ovid
- Original Message 

 From: perl6 via RT perl6-bugs-follo...@perl.org

 This patch implements die_on_fail (halts test at first test failure), but 
 only 
 if the author calls the die_on_fail sub in their test.


This patch works much better when attached to the email :)
 
Jeers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6# Copyright (C) 2007, The Perl Foundation.
# $Id: Test.pm 34904 2009-01-03 23:24:38Z masak $

## This is a temporary Test.pm to get us started until we get pugs's Test.pm
## working. It's shamelessly stolen  adapted from MiniPerl6 in the pugs repo.

# globals to keep track of our tests
our $num_of_tests_run= 0;
our $num_of_tests_failed = 0;
our $todo_upto_test_num  = 0;
our $todo_reason = '';
our $num_of_tests_planned;
our $no_plan;
our $die_on_fail;

our $*WARNINGS = 0;

# for running the test suite multiple times in the same process
our $testing_started;


## test functions

# Compare numeric values with approximation
sub approx ($x, $y) {
my $epsilon = 0.1;
my $diff = abs($x - $y);
($diff  $epsilon);
}

# you can call die_on_fail; to turn it on and die_on_fail(0) to turn it off
sub die_on_fail($fail=1) {
$die_on_fail = $fail;
}

# plan 'no_plan'; is now plan *;
multi sub plan(Whatever $plan) is export() {
$no_plan = 1;
}

multi sub plan($number_of_tests) is export() {
$testing_started  = 1;

$num_of_tests_planned = $number_of_tests;

say '1..' ~ $number_of_tests;
}

multi sub pass($desc) is export() {
proclaim(1, $desc);
}

multi sub ok(Object $cond, $desc) is export() {
proclaim($cond, $desc);
}

multi sub ok(Object $cond) is export() { ok($cond, ''); }


multi sub nok(Object $cond, $desc) is export() {
proclaim(!$cond, $desc);
}

multi sub nok(Object $cond) is export() { nok(!$cond, ''); }


multi sub is(Object $got, Object $expected, $desc) is export() {
my $test = $got eq $expected;
proclaim($test, $desc);
}

multi sub is(Object $got, Object $expected) is export() { is($got, $expected, 
''); }


multi sub isnt(Object $got, Object $expected, $desc) is export() {
my $test = !($got eq $expected);
proclaim($test, $desc);
}

multi sub isnt(Object $got, Object $expected) is export() { isnt($got, 
$expected, ''); }

multi sub is_approx(Object $got, Object $expected, $desc) is export() {
my $test = abs($got - $expected) = 0.1;
proclaim($test, $desc);
}

multi sub is_approx($got, $expected) is export() { is_approx($got, $expected, 
''); }

multi sub todo($reason, $count) is export() {
$todo_upto_test_num = $num_of_tests_run + $count;
$todo_reason = '# TODO ' ~ $reason;
}

multi sub todo($reason) is export() {
$todo_upto_test_num = $num_of_tests_run + 1;
$todo_reason = '# TODO ' ~ $reason;
}

multi sub skip()is export() { proclaim(1, # SKIP); }
multi sub skip($reason) is export() { proclaim(1, # SKIP  ~ $reason); 
}
multi sub skip($count, $reason) is export() {
for 1..$count {
proclaim(1, # SKIP  ~ $reason);
}
}

multi sub skip_rest() is export() {
skip($num_of_tests_planned - $num_of_tests_run, );
}

multi sub skip_rest($reason) is export() {
skip($num_of_tests_planned - $num_of_tests_run, $reason);
}

sub diag($message) is export() { say '# '~$message; }


multi sub flunk($reason) is export() { proclaim(0, flunk $reason)}


multi sub isa_ok($var,$type) is export() {
ok($var.isa($type), The object is-a '$type');
}
multi sub isa_ok($var,$type, $msg) is export() { ok($var.isa($type), $msg); }

multi sub dies_ok($closure, $reason) is export() {
try {
$closure();
}
proclaim((defined $!), $reason);
}
multi sub dies_ok($closure) is export() {
dies_ok($closure, '');
}

multi sub lives_ok($closure, $reason) is export() {
try {
$closure();
}
proclaim((not defined $!), $reason);
}
multi sub lives_ok($closure) is export() {
lives_ok($closure, '');
}

multi sub eval_dies_ok($code, $reason) is export() {
proclaim((defined eval_exception($code)), $reason);
}
multi sub eval_dies_ok($code) is export() {
eval_dies_ok($code, '');
}

multi sub eval_lives_ok($code, $reason) is export() {
proclaim((not defined eval_exception($code)), $reason);
}
multi sub eval_lives_ok($code) is export() {
eval_lives_ok($code, '');
}


multi sub is_deeply($this, $that, $reason) {
my $val = _is_deeply( $this, $that );
proclaim($val, $reason);
}

multi sub is_deeply($this, $that) {
my $val = _is_deeply( $this, $that );
proclaim($val, '');
}

sub _is_deeply( $this, $that) {

if $this ~~ List  $that ~~ List {
return if +$this.values != +$that.values;
for $this Z $that - $a, $b {
return if ! _is_deeply( $a, $b );
}
return True;
}
elsif

Re: [perl #62366] AutoReply: [PATCH] Add 'no_plan' and die_on_fail to Test.pm

2009-01-14 Thread Ovid
Per a conversation with moritz, this patch fixes an issue with a couple of 
tests failing with the old patch (where I apparently sent the file instead of 
the patch).

It also adds some diagnostics for ok $cond;

There should be more diagnostics available in the future, but I'm on holiday 
soon and I don't know how much time I'll get to work on this.

pmichaud pointed out an issue where new implementations might struggle with a 
full-blown Test.pm leveraging features that they don't use.  Eventually I plan 
to write a separate Makefile target to use a newer Test.pm, but since the tests 
say 'use Test', I'm unsure of how to do that.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

Test.patch
Description: Binary data


Re: Rakudo leaving the Parrot nest

2009-01-14 Thread Ovid
- Original Message 

 From: Patrick R. Michaud pmich...@pobox.com

 Source code repository
 --
 This is the immediate issue at hand, because we need to move Rakudo
 out of the Parrot repository so that it can cleanly move to its new
 home at parrot.org.  Currently Rakudo Perl lives at
 http://svn.perl.org/parrot/trunk/languages/perl6/ , while the 
 spectest suite (on which development/testing depends) lives at
 http://svn.pugscode.org/pugs/t/spec/ .

What's the rationale for the spectest suite to remain in the pugs repository?  
AFAICT, pugs is no longer being actively developed and I wouldn't be surprised 
if many of its spectests currently break and don't have a TODO.  Plus, the way 
fudge works, you have to be able to fudge things against both pugs and rakudo, 
making things rather confusing (and it's not documented very well that I can 
see, so I was royally confused at first).  In fact, I think that might even 
eliminate the need for fudge if done right.

Why not bite the bullet and include those tests in Rakudo?  If they're not 
listed in t/spectest.data, they don't get run.  Plus, it will make it much 
easier for a developer to write tests and to review them because they don't 
need to switch to a different repository or terminal window.  Thus, a developer 
won't need to have (or even know about) a separate repository *just for tests*. 
 That just seems weird.

Merging the test suite and eliminating fudge seems like a great simplification 
to me.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



New Test.pm (not a patch)

2009-01-13 Thread Ovid
OK, I'm tired of submitting bug reports.  Instead, I'll include my new 
'Test.pm' as an attachment rather than a patch.  You can try it locally and see 
if I've just screwed up royally.

Aside from exporting a 'die_on_fail' sub (which is a godsend for debugging), it 
also started adding very primitive have/want diagnostics:

  not ok 28 - 3rd element is trimmed again with no effect # TODO trim on lists
  # have: undef
  # want: baz
  not ok 29 - 0 is not true # TODO expected failures
  # Expected a true value.
  # have: 0
  not ok 30 - expected failure # TODO expected failures
  # Expected a false value.
  # have: [a, b, c]
  not ok 31 -
  # have: [a, b, c]
  # want: [a, b, z]

 
It's not a patch because I got tired of adding exceptions for bugs, but then I 
realized that the bugs might be in my brain :)  Specifically, I started adding 
stuff like this because of lack of a .perl method:

  my $have = $passed.WHAT eq any(Match Exception Iterator)
?? $passed
!! $passed.perl;

Features:

* die_on_fail (no longer hunt back through your terminal for the failure)
* diagnostics on most tests
* eliminate most multi-subs in favor of default $description='' arguments.
* Better diagnostics for boolean ok/nok tests.

It's still an awful, awful hack, but it's a start.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
# Copyright (C) 2007, The Perl Foundation.
# $Id: Test.pm 34904 2009-01-03 23:24:38Z masak $

## This is a temporary Test.pm to get us started until we get pugs's Test.pm
## working. It's shamelessly stolen  adapted from MiniPerl6 in the pugs repo.

# globals to keep track of our tests
our $num_of_tests_run = 0;
our $num_of_tests_failed  = 0;
our $todo_upto_test_num   = 0;
our $todo_reason  = '';
our $die_on_fail  = 0;
our $num_of_tests_planned;

our $*WARNINGS = 0;

# for running the test suite multiple times in the same process
our $testing_started;


## test functions

# Compare numeric values with approximation
sub approx ($x, $y) {
my $epsilon = 0.1;
my $diff = abs($x - $y);
($diff  $epsilon);
}

sub plan($number_of_tests) is export() {
$testing_started  = 1;
$num_of_tests_planned = $number_of_tests;

say '1..' ~ $number_of_tests;
}

sub die_on_fail() is export() {
$die_on_fail = 1;
}

sub pass($desc) is export() {
proclaim(1, $desc);
}

sub fail($desc) is export() {
proclaim(0, $desc);
}

sub ok(Object $passed, $desc='') is export() {
my $diagnostics = diag_bool_true($passed);
proclaim($passed, $desc, $diagnostics);
}

sub nok(Object $passed, $desc='') is export() {
my $diagnostics = diag_bool_false($passed);
proclaim(!$passed, $desc, $diagnostics);
}

sub is(Object $have, Object $want, $desc='') is export() {
my $passed = $have eq $want;
proclaim($passed, $desc, diag_eq($passed, $have, $want));
}

sub isnt(Object $have, Object $want, $desc='') is export() {
my $passed = !($have eq $want);
proclaim($passed, $desc, diag_neq($passed, $have, $want));
}

sub is_approx(Object $have, Object $want, $desc='') is export() {
my $passed = abs($have - $want) = 0.1;
proclaim($passed, $desc, diag_approx($passed, $have, $want));
}

sub todo($reason, $count=1) is export() {
$todo_upto_test_num = $num_of_tests_run + $count;
$todo_reason = '# TODO ' ~ $reason;
}

multi sub skip()is export() { proclaim(1, # SKIP); }
multi sub skip($reason) is export() { proclaim(1, # SKIP  ~ $reason); 
}
multi sub skip($count, $reason) is export() {
for 1..$count {
proclaim(1, # SKIP  ~ $reason);
}
}

multi sub skip_rest() is export() {
skip($num_of_tests_planned - $num_of_tests_run, );
}

multi sub skip_rest($reason) is export() {
skip($num_of_tests_planned - $num_of_tests_run, $reason);
}

sub diag($message) is export() { say '# '~$message; }


multi sub flunk($reason) is export() { proclaim(0, flunk $reason)}


multi sub isa_ok($var,$type) is export() {
ok($var.isa($type), The object is-a '$type');
}
multi sub isa_ok($var,$type, $msg) is export() { ok($var.isa($type), $msg); }

multi sub dies_ok($closure, $reason) is export() {
try {
$closure();
}
proclaim((defined $!), $reason);
}
multi sub dies_ok($closure) is export() {
dies_ok($closure, '');
}

multi sub lives_ok($closure, $reason) is export() {
try {
$closure();
}
proclaim((not defined $!), $reason);
}
multi sub lives_ok($closure) is export() {
lives_ok($closure, '');
}

multi sub eval_dies_ok($code, $reason) is export() {
proclaim((defined eval_exception($code)), $reason);
}
multi sub eval_dies_ok($code) is export() {
eval_dies_ok($code, '');
}

multi sub eval_lives_ok($code, $reason) is export() {
proclaim((not defined eval_exception

Re: New Test.pm (not a patch)

2009-01-13 Thread Ovid
- Original Message 

 From: Moritz Lenz mor...@faui2k3.org

 Ovid wrote:
  OK, I'm tired of submitting bug reports.
 
 Still bug reports are valuable. When you find your motivation again,
 please continue to submit them.

I meant that I was tired for that one evening.  I do plan to come back to 
this :)

  It's not a patch because I got tired of adding exceptions for bugs, but 
  then I 
 realized that the bugs might be in my brain :)  Specifically, I started 
 adding 
 stuff like this because of lack of a .perl method:
  
my $have = $passed.WHAT eq any()
  ?? $passed
  !! $passed.perl;
 
 Maybe ``try({$passed.perl}) // ~$passed'' works better, I hope to find
 tuits today to see if it makes a difference.

Does the try() block return the last evaluated value like Perl 5?  If so, what 
if $passed is undef but doesn't blow up?  Wouldn't that break this?

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Extending classes in a lexical scope?

2009-01-12 Thread Ovid
Let's say two people want to add a 'shuffle' method to all arrays.  Alice wants 
to have it look like this:

  method shuffle (*...@array is rw) {
  @array .= pick(*);
 }

Bob wants it to look like this:

  method shuffle (*...@array is rw) {
  @array = @array[0 .. @array/2] Z @arr...@array/2+1 .. @array];
  }

 
Thus, each wants to do the following, being able to modify the array in place:

  my @array = ^10;
  @array.shuffle;

Is it possible to modify the core Perl6Array class like that (without extra 
keywords)?  If so, is it possible for each programmer to make such a change so 
that it's lexically scoped? 

Oh, and the difference between those, for lurkers:

  perl6 $ perl6 -e 'my @a = a b c d e f g; [...@a[0..@a/2] 
z...@a[@a/2+...@a]].perl.say'
  [a, e, b, f, c, g]
  perl6 $ perl6 -e 'my @a = a b c d e f g; @a .= pick(*); @a.perl.say'
  [g, a, f, c, e, d, b]

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 

 From: Ovid publiustemp-perl6interna...@yahoo.com

  This patch implements the .trim() method for strings.
 
 Now that I'm reading S29, I see there is no .trim() method there.  I got that 
 because it was referenced in pugs in the cookbook (not in tests, though) and 
 I 
 was trying to get the examples to run.  Bummer :(

Sorry for constant spamming, but now that I've put disparate pieces together, I 
see what's going on here.  I'll stop soon, but I am *sick* of rewriting the 
trim() function over and over :)

There are no tests because it's not in the spec.  If there's a spec, I know 
where to write the tests and will happily commit tests for them to Pugs and 
I'll submit a new patch against any-str.pir and t/spectest.data to get them to 
pass.
 

http://tinyurl.com/4xjnh, a mailing list thread where Larry wrote:

: (Replying to p6l instead of p6c as requested.) 
: 
: On Mon, Apr 04, 2005 at 10:39:16AM -0700, Larry Wall wrote: 
:  (Now that builtins are just functions out in * space, we can probably 
:  afford to throw a few more convenience functions out there for common 
:  operations like word splitting and whitespace trimming.  (Specific 
:  proposals to p6l please.)) 

So even though it's not in the spec, it seems like something Larry is not 
entirely opposed to (or wasn't back in 2005).  So here's my proposal (copied to 
p6l):

  =item trim

  our Str multi Str::trim ( Str $string )

  Removes leading and trailing whitespace from a string.

  =cut

I could optionally make the following work:

  $string.trim(:leading0);
  $string.trim(:trailing0);

Setting leading or trailing to false (they default to true) would result in 
either leading or trailing whitespace not being trimmed.  Setting both to false 
would be a no-op.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 


   =item trim
 
   our Str multi Str::trim ( Str $string )
 
   Removes leading and trailing whitespace from a string.
 
   =cut
 
  I could optionally make the following work:
 
   $string.trim(:leading0);
   $string.trim(:trailing0);
 
  Setting leading or trailing to false (they default to true) would result in 
 either leading or trailing whitespace not being trimmed.  Setting both to 
 false 
 would be a no-op.
 
 Unless someone protests loudly, I can add this to S29, and I (or
 someone else with tuits) can implement it in Rakudo.

I've already submitted a patch for Rakudo which implements this for the trivial 
$string.trim and trim($string) case.  The optional :leading and :trailing 
parameters aren't there.

I'm happy to finish the work according to whatever spec is agreed upon. I want 
this badly enough that it's important to me :)

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 


   I could optionally make the following work:
  
$string.trim(:leading0);
$string.trim(:trailing0);

Alternatively, those could be ltrim() and rtrim().  If you need to dynamically 
determine what you're going to trim, you'd couldn't just set variables to do 
it, though. You'd have to figure out which methods to call.  Or all could be 
allowed and $string.trim(:leading0) could all $string.rtrim internally.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 

 From: jesse je...@fsck.com
 
 On Mon, Jan 12, 2009 at 07:01:25AM -0800, Ovid wrote:
 I could optionally make the following work:

  $string.trim(:leading0);
  $string.trim(:trailing0);
  
  Alternatively, those could be ltrim() and rtrim().  
 
 'left' and 'right' are probably not the right names for functions which
 trim leading and/or trailing space, since their meanings get somewhat
 ambiguous if a language renders right-to-left instead of left-to-right
 or vice-versa

Um, er.  Damn.  Now I'm wondering how my leading and trailing trimming 
works with Hebrew.  How are the strings implemented internally?

And then there are languages such as Manchu and Uygher which can be written 
vertically.  http://www.omniglot.com/writing/direction.htm

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 

 From: Larry Wall la...@wall.org

 On Mon, Jan 12, 2009 at 05:04:50AM -0800, Ovid wrote:
 : ...the trivial $string.trim and trim($string) case.
 
 Hmm, I'd think .trim should work like .chomp, and return the trimmed
 string without changing the original.  You'd use $str.=trim to do it
 in place.

In the pir, doesn't the s = self line copy self, thus ensuring that I'm 
changing s and not self?  Or do I need s = clone self (or however it's 
written).

 Can't say I really like the negated options though.  They smell funny.

Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike.  
Suggestions welcome as I can't think of anything better.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 

 From: Geoffrey Broadwell ge...@broadwell.org

 When I saw your proposed syntax above, instead of reading don't trim
 leading/trailing whitespace, I read change the definition of
 'whitespace' to 'codepoint 0' for leading/trailing.
 
 That of course raises the question of how one *would* properly override
 trim's concept of whitespace 

Change your locale to one with a different concept of whitespace (are there 
any?)


Otherwise, would this be trying to stuff too much into one function?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 


  Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike.
   Suggestions welcome as I can't think of anything better.
 
  The .Net framework calls 'em TrimStart and TrimEnd (and has a Trim that does
  both). So maybe trim_start and trim_end if we wanted to take that lead...
 
 How about .trim(:start) and .trim(:end)?

So if:

1.  No params, trim all
2.  :start or :end, only trim that bit (not a negated option :)
3.  If both, goto 1

 
Sound good?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 


 Also `:!start` to imply `:end` unless `:!end` (which in turn
 implies `:start` unless `:!end`)?
 
 I’d like not to have to type `.trim(:start)` when I could just do
 `.ltrim` though.

So what would .ltrim do with this?



בָּרוּךְ שֵׁם כְּבוֹד מַלְכוּתוֹ לְעוֹלָם וָעֶד.

If you can't see that in your client, that's Hebrew from 
http://www.i18nguy.com/unicode/shma.html and means Hear O Israel, the Lord is 
our God, the Lord is One.

Since that's RTL (Right To Left) text, should ltrim remove the leading or 
trailing whitespace?

I like Jonathan's trim_start and trim_end.

Side note:  I'm implementing the tests now, but only for bog-standard .trim.  I 
won't do the rest until we settle this.

So far I only have one failing test:

  is_deeply(trim(()), (), trim on empty list);

Results in:

  not ok 10 - trim on empty list
  # have: 
  # want: []

Note that this output is from my locally hacked version of Test.pm which is 
kind enough to tell you what the failure is.  I'll submit a patch for that 
later.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 

 From: Aristotle Pagaltzis pagalt...@gmx.de

  I like Jonathan's trim_start and trim_end.
 
 Let me ask you first: does a string that runs Right-to-Left start
 at the left and end at the right or start at the right and end at
 the left?
 
 Now to answer your question, *I* know where the *left* side is in
 a string that runs from right to left: it’s at the *left*, same
 as if the string ran from the left to the right, because left is
 at the *left*.
 
 :-)

I see your point, but it complicates the internals of the trim method because 
then I have to detect if a string is RTL and reverse it, then unreverse it when 
done (or something conceptually similar).

I'd rather not toss in said complications for a problem space I don't know very 
well.

On the other hand, this is a core feature, not a quick CPAN jobbie, so it's 
important to get it RIGHT or it will be LEFT out.  (I kill me.  I really do :)

 
Beers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 

 From: Aristotle Pagaltzis pagalt...@gmx.de

 * Austin Hastings [2009-01-12 22:00]:
  How about .trim(:l, :r) with both as the default?
 
 Liveable.

I've just committed the pugs tests for trim.  However, it's just 'trim' with no 
left/right, leading/trailing, Catholic/Protestant implementation.  I'll submit 
a patch for trim with the spectest data updated and work on the rest after the 
dust settles.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



[PATCH] Revised .trim patch

2009-01-12 Thread Ovid
Seems Larry's agreed to the .trim method.  There are bits that are not agreed 
upon, so this patch only implements what we've agreed upon.  It relies on the 
new S29-str/trim.t test in pugs.  I committed that earlier and updated 
t/spectest.data.

 
In other words, the patch is a tad clearer and now has tests.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


trim.patch
Description: Binary data


Re: Extending classes in a lexical scope?

2009-01-12 Thread Ovid
- Original Message 

 From: Moritz Lenz mor...@faui2k3.org

  That is the preferred way to avoid action-at-a-distance in P6.
 
 so if I do that, will a 'my @a' use that new Array class?
 
 Actually I'd prefer it if there were some kind of mechanism to set a
 default implementation type, so that I could write something along these
 lines:
 
 class MyArray is Array { ... }
 use Container :Array;
 
 then is this lexical scope all Array declarations and all Prelude
 operations that return Arrays return one of the type that I specified.


Actually, I'd prefer to go much further than this:

  use Core 'MyCore';

And have that override core classes lexically.
 
That solves the but I want it MY way issue that many Perl and Ruby 
programmers have, but they don't shoot anyone else in the foot.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Trimming arrays

2009-01-12 Thread Ovid
What should this output?

  my @array = '   foo   ', '   bar  ';
  @array .= trim;

  say @array.perl;
 
And what if I have an array of hashes of hashes of arrays?

Currently you can call 'trim' on arrays, but it's a no-op.  Similar issues with 
chomp and friends.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Trimming arrays

2009-01-12 Thread Ovid
- Original Message 

 From: Larry Wall la...@wall.org

 :   my @array = '   foo   ', '   bar  ';
 :   @array .= trim;
 : 
 :   say @array.perl;
 :  
 : And what if I have an array of hashes of hashes of arrays?
 : 
 : Currently you can call 'trim' on arrays, but it's a no-op.  Similar issues 
 with chomp and friends.
 
 It should probably say No such method.  We have hyperops now to apply
 scalar operators to composite values explicitly:
 
 @array».=trim


Won't that fail with 'No such method' on an array of hashes? Or are hyperops 
applied recursively?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Extending classes in a lexical scope?

2009-01-12 Thread Ovid
- Original Message 

 From: Jon Lang datawea...@gmail.com

  Actually, I'd prefer to go much further than this:
 
   use Core 'MyCore';
 
  And have that override core classes lexically.
 
  That solves the but I want it MY way issue that many Perl and Ruby 
 programmers have, but they don't shoot anyone else in the foot.
 
 Since 'use' imports its elements into the current lexical scope, the
 version-based approach can do this.
 
 The only catch that I can think of has to do with derived classes:
 does the existence of a customized version of a class result in
 same-way-customized versions of the classes that are derived from the
 original class?  That is, if I added an updated version of Foo, and
 Bar has previously been defined as being derived from Foo, would I get
 a default updated version of Bar as well?  Or would I have to
 explicitly update each derived class to conform to the updated base
 class?


I'm not sure I understand you.  If 'Bar' inherits from 'Foo' and 'Foo' has 
extended the core Array class to lexically implement a .shuffle method, then I 
would expect 'Bar' to have that also.  There are two things involved:

1.  Liskov should be respected, when appropriate 
(http://www.oreillynet.com/onlamp/blog/2008/02/the_liskov_substitution_princi.html)
2.  'Bar' is coupled to 'Foo' and needs to know 'Foo's implementation (a 
charming anti-inheritance argument).  See #1 :)

Or did you mean something completely different?
 
Note that Liskov is great, but has issues at times when composition is unclear.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message 

 From: jason switzer jswit...@gmail.com

 If we wanted language dependent version, use :leading, :trailing, and :both.
 That will require each implementation properly handle the language
 variations.
 
I think :start and :end are my favorites.  Huffman++ (maybe :begin and :end for 
consistency?).

Still raises the question of what to do with arrays of hashes of arrays with 
@array  .= trim;

I can't trim keys of pairs because they're used as unique identifiers in hashes 
and conflicts will occur.  So recursive trimming needs have a special case for 
keys or it needs to not be allowed (and thus fail with AoHoA and similar 
complex data structures).

 By the way, good work on this. Everyone loves useful string functions.

Thanks.  It's been lots of fun :)

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


[PATCH] Add .trim method

2009-01-11 Thread Ovid
This is an update to my last patch (which you may not see because I sent it 
from the wrong email address).  Here are my updated notes:

This patch implements the .trim() method for strings.

Problem:   I don't like the magic number '32

  not_whitespace = is_cclass 32, s, start

But I couldn't figure this out:

  $I0 = is_cclass .CCLASS_WHITESPACE, target, pos

I
was getting an 'unknown parrot op' or something like that (too tired to
recompile and find out the exact error message).  I can't figure out
how to get parrot to recognize that.

Many thanks to moritz++ for handholding on IRC.

Oh, there are no tests because I couldn't find any pugs tests for this :( 
What's the appropriate procedure for this?  However, all tests pass and a small 
test program passed (including calling trim() as a function).

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


trim.patch
Description: Binary data


[PATCH]: implement .trim method

2009-01-11 Thread Ovid
This patch implements the .trim() method for strings.

Two problems:

1.  I don't like the double-negative, but I was unsure how to get rid of it.

  unless not_whitespace goto done

2.  I don't like the magic number '32

  not_whitespace = is_cclass 32, s, start

 
$I0 = is_cclass .CCLASS_WHITESPACE, target, pos

I was getting an 'unknown parrot op' or something like that (too tired to 
recompile and find out the exact error message).  I can't figure out how to get 
parrot to recognize that.

Many thanks to moritz++ for handholding on IRC.

Oh, there are no tests because I couldn't find any pugs tests for this :( 
What's the appropriate procedure for this?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


trim.patch
Description: Binary data


Not a bug?

2009-01-11 Thread Ovid
I really don't think this is a bug, but it did confuse the heck out of me at 
first.  This *is* expected behavior due to how {} is interpolated in strings, 
yes?

  $ perl6 -e 'my $foo = foo;say  ~ $foo ~ '
  foo
  $ perl6 -e 'my $foo = foo;say { ~ $foo ~ }'
   ~ foo ~ 

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [PATCH] Add .trim method

2009-01-11 Thread Ovid
- Original Message 


 This patch implements the .trim() method for strings.

Now that I'm reading S29, I see there is no .trim() method there.  I got that 
because it was referenced in pugs in the cookbook (not in tests, though) and I 
was trying to get the examples to run.  Bummer :(


Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [perl #61990] [BUG] setset .WHAT returns incorrect value

2009-01-06 Thread Ovid
- Original Message 

 From: Jonathan Worthington jonat...@jnthn.net

subset Even of Int where { not $_ % 2 };
my Even $num = 2;
say $num;
say $num.WHAT;
  
  
  Output:
  
2
Int
   I'm expecting:
  
2
Even
  
   
 I think the current behaviour is correct (or at least, implemented to match 
 my 
 understanding of the Perl 6 type system). You're asking for the type of the 
 value stored in $x, which is an Int.
 
 Even is not a real type, but rather a refinement type. It is set as a 
 constraint on what may be held by the container. To get hold of that (though 
 I 
 don't think we implement any way right now) you probably would write 
 $x.VAR.type 
 or some such (I'm not sure exactly what the name of the method on the 
 container 
 that hands this back should be).

Really?  It subset looks to me like a new type definition, built on an existing 
type.  If that was the case, then this would look normal:

  my Int $foo; say $foo.WHAT;  # Int
  my Odd $bar; say $bar.WHAT;  # Odd

 
That *looks* right to me, particularly since what comes after the my seems 
like a type declaration.  By your logic, .WHAT refers to the value, not the 
container, which seems odd.  That being said:

  my $foo = 3; say $foo; # Int
  $foo = 'stuff'; say $foo; # Str

So that's probably bad coding (reusing a variable for different types) but it's 
legal.  So maybe this is the correct behavior, but I expect it's going to 
confuse people.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Bug or feature? Hash autovivification

2008-12-31 Thread Ovid
Just stumbled across this, but I can't tell from S09 if this is a bug or 
feature:

  $ ./perl6 -e 'my %foo; if %fooa {}; say %foo.perl'
  {a = undef}

 
I wasn't expecting auto-vivification there.  The examples in S09 use HoH 
instead of a flat hash:

But these bindings do autovivify:

   my %hash;
   my $val := %hashfoobar;

   my @array;
   my $cap = \...@array[0][0]; # $cap is a Capture object ‐ see S02
   my :($obj) := $cap;   # @array[0][0] created here

   my @array;
   foo(@array[0][0]);
   sub foo ($obj is rw) {...}  # same thing, basically

   my %hash;
   %hashfoobar = foo; # duh

So is this a bug?

Revision: 34706

$ uname -a
Darwin curtis-poes-computer-3.local 9.5.1 Darwin Kernel Version 9.5.1: Fri Sep 
19 16:19:24 PDT 2008; root:xnu-1228.8.30~1/RELEASE_I386 i386

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Hangman in Perl 6

2008-12-31 Thread Ovid
I wrote a hangman game in Perl 6.  Suggestions are very welcome.  Some issues 
with it are from things I don't understand.  Others are due to bugs or 
limitations in Rakudo.

  http://use.perl.org/~Ovid/journal/38191

 
All in all, I'm quite pleased with how things are coming along.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [perl #61772] AutoReply: Slurpy array 'is copy' returns incorrectly.

2008-12-28 Thread Ovid
Forgot to add the revision and computer info:


$ svn info; uname -a
Path: .
URL: https://svn.perl.org/parrot/trunk
Repository Root: https://svn.perl.org/parrot
Repository UUID: d31e2699-5ff4-0310-a27c-f18f2fbe73fe
Revision: 34446
Node Kind: directory
Schedule: normal
Last Changed Author: kjs
Last Changed Rev: 34446
Last Changed Date: 2008-12-27 21:17:55 + (Sat, 27 Dec 2008)

Darwin curtis-poes-computer-3.local 9.5.1 Darwin Kernel Version 9.5.1:
Fri Sep 19 16:19:24 PDT 2008; root:xnu-1228.8.30~1/RELEASE_I386 i386


Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Perl 6 pos() function?

2008-12-27 Thread Ovid
I'm trying to replicate the following behavior in Perl 6, but can't figure out 
a natural way to do this (the task is filling in guessed letters for a 
hangman game):

while ( $word =~ /$letter/g ) {
$guess[ pos($word) - 1 ] = $letter;
}

What would be the canonical Perl 6 way of doing this?  Preferably one which 
works with the current state of Rakudo :)


Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Perl 6 pos() function?

2008-12-27 Thread Ovid
- Original Message 

 From: Daniel Ruoso dan...@ruoso.com

   my $word = 'banana';
   my @guess = ;
   $word ~~ /a/;
   @guess[$/.from] = 'a';
   say @guess;

So far my workarounds for this problem are failing because as soon as you take 
your code and refactor:

  my $word  = 'banana';
 
my @guess =  ? ? ? ? ? ? ;
  my $letter = 'a';
 
$word ~~ / $letter /;
  @guess[$/.from] = $letter;
  say @guess;

 
(I *think* that's the correct syntax?)

But that gives the following error:

Statement not terminated properly at line 4, near $letter /

Revision 34446 on OS X Darwin.  Is this a known failure?  I think it's not 
supposed to work yet, but I unsure from the tests.  If that's the case, the 
only work around I can think of is to split the word and individually compare 
each letter's ord() value.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [perl #61052] [BUG]: r33482 Can't run 'make realclean' in languages/perl6 directory

2008-12-05 Thread Ovid
- Original Message 

 From: Moritz Lenz [EMAIL PROTECTED]

 (Just out of curiosity, do you need 'make realclean' in
 languages/perl6/? Most of the time a simple 'make' works for me, or a
 'make clean'. I never needed realclean in Rakudo, only in parrot so far).

No, I don't need to do that. It comes from my 'rebuild' script and that's just 
finger memory on my part.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [perl #60850] r33207: Multiple spectest failures on OS X

2008-11-26 Thread Ovid
- Original Message 


 On Tue Nov 25 23:38:58 2008, [EMAIL PROTECTED] wrote:
  t/spec/S12-methods/default-trait.t   (Wstat: 0
  Tests: 6 Failed: 1)
Failed test:  2
  
 I'd be especially interested in the test output of this one (or to know
 if it's no longer failing with latest Rakudo). Since I was just working
 on that recently, and can't reproduce a failure here.

I'll try to get to this later, but after work, I'm heading out with friends.  
If anyone else has OS X and can reproduce this, that would be fantastic.  I 
won't be home any time soon.

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [perl #60850] r33207: Multiple spectest failures on OS X

2008-11-26 Thread Ovid


- Original Message 

 From: [EMAIL PROTECTED] via RT [EMAIL PROTECTED]

 Thanks for testing. :-)
 
 On Tue Nov 25 23:38:58 2008, [EMAIL PROTECTED] wrote:
  t/spec/S12-methods/default-trait.t   (Wstat: 0
  Tests: 6 Failed: 1)
Failed test:  2
  
 I'd be especially interested in the test output of this one (or to know
 if it's no longer failing with latest Rakudo). Since I was just working
 on that recently, and can't reproduce a failure here.

t/spec/S12-methods/default-trait.t .. 
oh yes
oh yes
oh yes
1..6
ok 1 - 'is default' trait makes otherwise ambigous method dispatch live
not ok 2 - 'is default' trait tie-breaks on method dispatch
ok 3 - 'is default' trait makes otherwise ambigous method dispatch live
ok 4 - 'is default' trait on subs
ok 5 - basic sanity with arity based dispatch and slurpies
ok 6 - is default trait wins against empty slurpy param
Failed 1/6 subtests 

Test Summary Report
---
t/spec/S12-methods/default-trait.t (Wstat: 0 Tests: 6 Failed: 1)
  Failed test:  2
Files=1, Tests=6,  1 wallclock secs ( 0.02 usr  0.01 sys +  1.17 cusr  0.08 
csys =  1.28 CPU)
Result: FAIL

The failing test:

  class Something {
  multi method doit(Int $x){ 2 * $x };
  multi method doit(Int $x) is default { 3 * $x };
  }

  my $obj = Something.new();
  lives_ok { $obj.doit(3) }, 'is default' trait makes otherwise ambigous 
method dispatch live;
  is $obj.doit(3), 9, 'is default' trait tie-breaks on method dispatch;  
  
$obj.doit(3) returns 6, not 9.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [perl #60510] Bad plan: t/spec/S29-conversions/ord_and_chr.rakudo

2008-11-13 Thread Ovid
--- On Thu, 13/11/08, Patrick R. Michaud [EMAIL PROTECTED] wrote:

 Again, this is all with r32625, YMMV with other revisions
 (and please
 report whatever other clues you may find).

Ah, sorry.  I should have known better :)

r32580

$ uname -a
Darwin curtis-poes-computer-2.local 9.5.1 Darwin Kernel Version 9.5.1: Fri Sep 
19 16:19:24 PDT 2008; root:xnu-1228.8.30~1/RELEASE_I386 i386

Now this test passes (r32629), but the Perl 6 test suite is still failing.  
Now, however, I can't tell which test fails.  The output was confusing enough 
to me that I've copied it to a file and attached it (teeing the spectest 
rusults to a file was spectacularly disappointing. It doesn't play well with 
tee).

Cheers,
Ovid
perl6 $ make spectest
../../parrot  perl6.pbc --target=pir --output=Test.pir Test.pm
cd t/spec  svn up
US03-junctions/misc.t
US03-operators/ternary.t
Aintegration/real-strings.t
Updated to revision 23000.
perl t/harness --fudge --keep-exit-code --jobs --tests-from-file=t/spectest.data
t/spec/S02-builtin_data_types/array_extending.t  ok 
t/spec/S02-builtin_data_types/anon_block.rakudo  ok 
===(  45;6  0/?   1/45  0/? )===Use of 
uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
t/spec/S02-builtin_data_types/array_ref.rakudo . ok 
===(  90;7   1/97  0/?  0/? )===Use of 
uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
t/spec/S02-builtin_data_types/array.rakudo . ok 
t/spec/S02-builtin_data_types/bool.t ... ok 
t/spec/S02-builtin_data_types/catch_type_cast_mismatch.rakudo .. ok 
t/spec/S02-builtin_data_types/assigning-refs.rakudo  ok 
t/spec/S02-builtin_data_types/flattening.rakudo  ok 
===( 269;14  0/?   1/32  0/? )==Use of 
uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
t/spec/S02-builtin_data_types/hash_ref.rakudo .. ok 
===( 301;17   1/58  0/?  0/? )==Use of 
uninitialized value
Use of uninitialized value
Use of uninitialized value
Use of uninitialized value
t/spec/S02-builtin_data_types/hash.rakudo .. ok 
t/spec/S02-builtin_data_types/multi_dimensional_array.rakudo ... ok 
t/spec/S02-builtin_data_types/nested_pairs.t ... ok 
t/spec/S02-builtin_data_types/nested_arrays.t .. ok 
t/spec/S02-builtin_data_types/mixed_multi_dimensional.rakudo ... ok 
===( 495;24  0/?  0/?  1/8 )Use of 
uninitialized value
t/spec/S02-builtin_data_types/subscripts_and_context.rakudo  ok 
t/spec/S02-builtin_data_types/num.rakudo ... ok 
t/spec/S02-builtin_data_types/type.rakudo .. ok 
t/spec/S02-literals/array-interpolation.rakudo . ok 
===( 590;29   1/79  0/?  0/? 
)==Undefined value shifted from empty range
t/spec/S02-builtin_data_types/range.rakudo . ok 
t/spec/S02-literals/hash-interpolation.rakudo .. ok 
t/spec/S02-literals/hex_chars.t  ok 
t/spec/S02-literals/char-by-number.rakudo .. ok 
t/spec/S02-literals/listquote-whitespace.rakudo  ok 
t/spec/S02-literals/pair-boolean.t . ok 
===( 741;36  0/?   1/14  0/? )==Use of 
uninitialized value
Use of uninitialized value
t/spec/S02-literals/listquote.rakudo ... ok 
t/spec/S02-literals/autoref.rakudo . ok 
t/spec/S02-literals/pairs.rakudo ... ok 
t/spec/S02-literals/string-interpolation.t . ok 
===( 860;461/135  0/?  0/? )Use of 
uninitialized value
t/spec/S02-literals/quoting.rakudo . ok 
t/spec/S02-magicals/dollar-underscore.t  ok 
t/spec/S02-literals/underscores.t .. ok 
t/spec/S02-magicals/dollar_bang.rakudo . ok 
t/spec/S02-names_and_variables/varnames.t .. ok 
t/spec/S02-names_and_variables/fmt.rakudo

Re: [perl #60510] Bad plan: t/spec/S29-conversions/ord_and_chr.rakudo

2008-11-13 Thread Ovid
--- On Thu, 13/11/08, Mark J. Reed [EMAIL PROTECTED] wrote:

 Failed Test  Stat Wstat Total Fail 
 List of Failed
 
 t/spec/S12-class/declaration-order.t0 6 20 
 ??
 1490 subtests skipped.
 
 Failed 1/219 test scripts. 0/6484 subtests failed.
 Files=219, Tests=6484, 1224 wallclock secs (661.02 cusr +
 28.94 csys =
 689.96 CPU)

Aha!  Mark, what version of Test::Harness are you running?  This looks like 2.X 
version output and I'm running 3.15.  There might be a bug in the newer version 
which is losing that information.

My best friend from the US arrives in a few hours, though, so there's not 
likely to be much follow up from me.  Sorry.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Parrot doesn't build on OS X

2008-11-01 Thread Ovid
For the past few days, Parrot has failed to build on my MacBook.  Today I moved 
my parrot directory and did a fresh svn checkout.  perl Configure.pl ran fine 
without problem. make does fine until about here:

$ make
Compiling with:
xx.c
/usr/bin/gcc-4.0 loads of output skipped...
make -C compilers/pge
perl -MExtUtils::Command -e rm_f PGE.pbc ../../runtime/parrot/library/PGE.pbc
perl -e  PGE/builtins_gen.pir
../../parrot -o PGE.pbc --output-pbc PGE.pir
../../parrot ../../runtime/parrot/library/PGE/Perl6Grammar.pir  
--output=PGE/builtins_gen.pir PGE/builtins.pg
make[1]: *** [PGE.pbc] Bus error
make[1]: *** Deleting file `PGE.pbc'
make: *** [compilers.dummy] Error 2
 
$ uname -a
Darwin curtis-poes-computer-2.local 9.5.0 Darwin Kernel Version 9.5.0: Wed Sep  
3 11:29:43 PDT 2008; root:xnu-1228.7.58~1/RELEASE_I386 i386

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Known Bug in Rakudo?

2008-10-30 Thread Ovid
This code:

  class Point {
  has $.x is rw;
  has $.y is rw;

  method get_string () {
  return $.x, $.y;
  }
  }

  my Point $point .= new( :x1.2, :y-3.7 );
  say $point.x;
  say $point;

Generates this output:

  1.2
  get_string() not implemented in class 'Point'
  current instr.: 'print' pc 14726 (src/gen_builtins.pir:9076)
  called from Sub 'say' pc 14748 (src/gen_builtins.pir:9086)
  called from Sub '_block11' pc 152 (EVAL_12:53)
  called from Sub 'parrot;PCT;HLLCompiler;eval' pc 864 
(src/PCT/HLLCompiler.pir:498)
  called from Sub 'parrot;PCT;HLLCompiler;evalfiles' pc 1138 
(src/PCT/HLLCompiler.pir:627)
  called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1317 
(src/PCT/HLLCompiler.pir:716)
  called from Sub 'parrot;Perl6;Compiler;main' pc 17077 (perl6.pir:179)
  *** glibc detected *** double free or corruption (!prev): 0x084eaaf0 ***

This is Parrot 0.8.0.

  $ uname -a
  Linux critix 2.6.8-2-686-smp #1 SMP Tue Aug 16 12:08:30 UTC 2005 i686 
GNU/Linux

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: Parrot on mobile platforms?

2008-10-23 Thread Ovid
--- On Thu, 23/10/08, Gabor Szabo [EMAIL PROTECTED] wrote:

 Don't you think it would be important to start working
 in this direction?
 Maybe to try to get someone work on this or to get
 sponsorship
 in that direction?

I can't speak for Android, but I know one of the constraints on the iPhone is 
memory.  This, as I recall, is part of the reason why they don't have garbage 
collection available and force people to manage memory directly (this, I might 
add, is a pain).  Since I generally don't worry about memory, I've no idea if 
Parrot is a memory hog.

That being said, I can't imagine Apple would be terribly keen to endorse 
anything which requires jail breaking the phone.  Don't we have contacts in 
Apple?  Getting official approval for trying this out might be a nice thing.  
In fact, I already know an iPhone developer who would be a great fit for a 
challenge like this (if he's interested).

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




Re: [perl #60016] [PATCH] Make basic Perl 6 tests pass

2008-10-21 Thread Ovid
--- On Tue, 21/10/08, James Keenan via RT [EMAIL PROTECTED] 

 \ This basic test suite will fail.  That's
 because of this test program:
  
t/00-parrot/06-op-inplace.t
  
 
 I've reported this a couple of times in
 http://rt.perl.org/rt3/Ticket/Display.html?id=59634 -- but
 no one paid
 attention.
 
 Since you're proposing a patch, I'll merge 59634
 into this one.

Thanks.  Hopefully this time there will be some traction because there does 
appear to be a bug in Perl 6, as evidenced by this one-liner:

  perl6 $ ../../parrot perl6.pbc -e 'my $x = 3; $x **= 2; say $x'
  3

Unless, of course, this isn't supposed to be implemented yet, but that seems 
strange since it's in the basic tests.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Running Perl 6 Tests

2008-10-20 Thread Ovid
I've been doing some work integrating Perl 6 into vim and now I'm trying to 
figure out how to run individual Perl 6 tests.  It appears that the incantation 
is along the lines of:

  perl t/harness --verbosity 1 t/01-sanity/02-counter.t

However, in digging further, I found this:

  perl t/harness --verbosity 1 t/02-test-pm/1-basic.t

That starts off with Statement not terminated properly at line 87, near 
(\Hello Wo and goes downhill from there.

In fact, in reading through the Makefile, I don't see that this gets run unless 
you do 'make testtest' (added by particle back in Dec 2007).  This doesn't 
appear to be documented.  Is it supposed to be run?  Should those Perl 6 tests 
be valid?

Also, the way that t/00-parrot/06-op-inplace.t is written forces the test 
numbers to be out of sequence.  This causes make test to fail, even though 
it's merely a parse error.  The Test.pm module appears to work (I've only 
checked it superficially), so why not use that to make some of these tests a 
bit easier to write?  Are we trying to avoid loading modules while testing core 
features?

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Fw: Running Perl 6 Tests

2008-10-20 Thread Ovid
It would help if I sent this to the correct mailing list.  Oops.

Cheers,
Ovid

--- On Mon, 20/10/08, Ovid [EMAIL PROTECTED] wrote:

 I've been doing some work integrating Perl 6 into vim
 and now I'm trying to figure out how to run individual
 Perl 6 tests.  It appears that the incantation is along the
 lines of:
 
   perl t/harness --verbosity 1 t/01-sanity/02-counter.t
 
 However, in digging further, I found this:
 
   perl t/harness --verbosity 1 t/02-test-pm/1-basic.t
 
 That starts off with Statement not terminated
 properly at line 87, near (\Hello
 Wo and goes downhill from there.
 
 In fact, in reading through the Makefile, I don't see
 that this gets run unless you do 'make testtest'
 (added by particle back in Dec 2007).  This doesn't
 appear to be documented.  Is it supposed to be run?  Should
 those Perl 6 tests be valid?
 
 Also, the way that t/00-parrot/06-op-inplace.t is written
 forces the test numbers to be out of sequence.  This causes
 make test to fail, even though it's merely a
 parse error.  The Test.pm module appears to work (I've
 only checked it superficially), so why not use that to make
 some of these tests a bit easier to write?  Are we trying to
 avoid loading modules while testing core features?
 
 Cheers,
 Ovid
 --
 Buy the book -
 http://www.oreilly.com/catalog/perlhks/
 Tech blog- http://use.perl.org/~Ovid/journal/
 Twitter  - http://twitter.com/OvidPerl
 Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: Running Perl 6 Tests

2008-10-20 Thread Ovid
--- On Mon, 20/10/08, Moritz Lenz [EMAIL PROTECTED] wrote:



  Also, the way that t/00-parrot/06-op-inplace.t is
 written forces the test numbers to be out of sequence.  This
 causes make test to fail, even though it's
 merely a parse error.  The Test.pm module appears to work
 (I've only checked it superficially), so why not use
 that to make some of these tests a bit easier to write?  Are
 we trying to avoid loading modules while testing core
 features?
 
 The 01-sanity/ tests predate module loading.
 The real testing is to run 'make
 spectest', which loads a bunch of
 tests from the pugs repository, prepares and run them.
 
 If you want to run those individually, you can simply say
 $ make t/spec/S02-literals/radix.t

Fair enough.  From playing around with this, it appears that all Perl 6 tests 
can be run with:

  perl t/harness --verbosity 1 --fudge --keep-exit-code $testname

Is it an accident that this works for regular test files?  If not, I can 
integrate this into vim easily and since module loading works, 
t/00-parrot/06-op-inplace.t can be updated with use Test; to at least ensure 
that make perl6 passes and people don't get confused when trying to build.  
I'd be happy to update that test and send a patch.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: Fw: Running Perl 6 Tests

2008-10-20 Thread Ovid
--- On Mon, 20/10/08, jerry gay [EMAIL PROTECTED] wrote:

 yes, 00-parrot tests are prerequisites to running Test.pm.
 they can't use the module to perform their tests.
 it does indeed look like the test numbers are out of order.
 ...time passes...
 it seems infix:**= is broken. the fix isn't
 obvious to me.
 perplexing... doubly so as t/spec/S03-operators/assign.t
 passes these.

Well, darn.  I just submitted a patch that uses Test.pm.  Not only does that 
make my patch wrong, but I didn't understand the semantics of all of the 
strange assignments (+^=?), so I assumed their values were correct.  Bummer.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [perl #60016] AutoReply: [PATCH] Make basic Perl 6 tests pass

2008-10-20 Thread Ovid
OK, I've updated the patch.  I've made the following assumptions:

1.  I cannot load modules.
2.  I cannot use subroutines.
3.  I cannot use inline ops for the test counter (since that's what
is being tested)

The problem is that I've made the tests pass by assuming that the value of $a 
at each point is the correct value.  I'm assuming from what Jerry has pointed 
out that these number should be sequential.  It's a trivial fix to remedy this 
in the tests, but I didn't want to try and second-guess what was going on.

I think this patch (or something similar) is important as those who want to 
play with Rakudo will see a test failure if they run 'make test' as the README 
instructs.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

perl6tests.patch
Description: Binary data


Re: [perl #60016] AutoReply: [PATCH] Make basic Perl 6 tests pass

2008-10-20 Thread Ovid
Sorry for the patch spam.  I'm embarrassed that I didn't have this correct the 
first time (hey, YOU stay home and write tests for a strange platform while 
sick)

The test will now fail, but they'll fail for the correct reason:  **= is being 
misparsed, as pointed out earlier.

You might not notice the tests failing, but that's because make test seems to 
run the harness 3 times and the failing test is in the first run.  If you don't 
notice this, you won't notice these tests failing.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

perl6tests.patch
Description: Binary data


Re: Should Cgrep and Creverse work in CAny ?

2008-06-30 Thread Ovid
--- On Sun, 29/6/08, Patrick R. Michaud [EMAIL PROTECTED] wrote:

 Do Cgrep and Creverse act like the
 Cjoin method, in that
 they work for CAny object and not just objects of
 type CList?
 
 In other words,, should  C $x.grep(...)   work even
 if $x isn't normally a list type?

If I understand you correctly, I think you're asking if grep and map can be 
applied to junctions?  I would say yes.  We don't want to mutate junctions in 
place as this would break their parallelism, but I've found that I sometimes 
need to pass junctions around and build new junctions based on the values of 
old junctions.  grep and map would make that trivial.

If I've misunderstood, feel free to print this out and burn it :)

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Should Cgrep and Creverse work in CAny ?

2008-06-30 Thread Ovid
--- On Mon, 30/6/08, Ovid [EMAIL PROTECTED] wrote:
 --- On Sun, 29/6/08, Patrick R. Michaud
 [EMAIL PROTECTED] wrote:
 
  Do Cgrep and Creverse act like the
  Cjoin method, in that
  they work for CAny object and not just objects
 of
  type CList?
  
  In other words,, should  C $x.grep(...)   work
 even
  if $x isn't normally a list type?
 
 If I understand you correctly, I think you're asking if
 grep and map can be applied to junctions?  I would say yes. 

I just noticed you included 'reverse' in that list of methods.  I thought 
junctions were inherently unordered, thus making reverse kind of useless (which 
leads me even more to believe that I've misunderstood the question).

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: [perl #56236] [BUG]: Unable to 'make perl6' on OS X 10.4 PPC

2008-06-24 Thread Ovid
--- James Keenan via RT [EMAIL PROTECTED] wrote:

 On Mon Jun 23 19:20:57 2008, [EMAIL PROTECTED] wrote:
  Failed to 'make perl6' at r 27371:  May 07.
 
 I tried again, and 'make perl6' succeeded at r27371.
 
 The plot thickens!

w00t!  I'll try this when I get home tonight.  This is great news.

Cheers,
Ovid

--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [perl #56236] [BUG]: Unable to 'make perl6' on OS X 10.4 PPC

2008-06-24 Thread Ovid
--- Ovid [EMAIL PROTECTED] wrote:

  I tried again, and 'make perl6' succeeded at r27371.
  
  The plot thickens!
 
 w00t!  I'll try this when I get home tonight.  This is great news.

Nope.  'make test' and 'make perl6' both return the following:

  ../../parrot  -o perl6.pbc perl6.pir
  src/interpreter.c:1030: failed assertion
  'interp-op_count == core-op_count'
  make: *** [perl6.pbc] Abort trap

Exact same thing as before.  I was so frustrated that I moved my parrot
directory and grabbed a fresh check out and tried again.  Still fails.

I'm going nuts over this :(

Cheers,
Ovid

--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [perl #56236] [BUG]: Unable to 'make perl6' on OS X 10.4 PPC

2008-06-24 Thread Ovid
Forget everything I wrote.  I missed a couple of files in my cleaning. 
I got rid of them, did a 'make clean  make perl6' and now everything
is just dandy.

Thanks for the help.

Cheers,
Ovid

--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Re: [perl #56236] [BUG]: Unable to 'make perl6' on OS X 10.4 PPC

2008-06-24 Thread Ovid
--- chromatic [EMAIL PROTECTED] wrote:

  Nope.  'make test' and 'make perl6' both return the following:
 
../../parrot  -o perl6.pbc perl6.pir
src/interpreter.c:1030: failed assertion
'interp-op_count == core-op_count'
make: *** [perl6.pbc] Abort trap
snip
 Guess: you have a libparrot.so (or .dylib, or whatever Mac OS X
 thinks looks 
 good with a black turtleneck) somewhere getting loaded before 
 blib/lib/libparrot.so.
snip
 I really did think I fixed that bug though... but if you can trace
 the dynamic 
 library loading of your process, you can confirm or deny this.

Bingo!  Don't know how to trace that, but a quick locate confirmed an
earlier install.  I manually deleted the offending files.  Now it
compiles, but it still doesn't appear to work :)  As far as I can tell,
I'm following the instructions from the README correctly.

  perl6 $ cat hello.pl 
  say Hello, world!;
  perl6 $ ./perl6 hello.pl 
  Null PMC access in get_string()
  current instr.: 'parrot;P6metaclass;add_parent' pc 119
(runtime/parrot/library/P6object.pir:137)
  called from Sub 'parrot;P6metaclass;add_parent' pc 241
(runtime/parrot/library/P6object.pir:215)
  called from Sub 'parrot;P6metaclass;register' pc 411
(runtime/parrot/library/P6object.pir:295)
  called from Sub 'parrot;Str;onload' pc 859 (src/gen_builtins.pir:584)
  called from Sub 'parrot;Perl6::Compiler;main' pc -1 ((unknown
file):-1)

I get the same error even if I do ../../parrot perl6.pbc hello.pl.

Cheers,
Ovid

--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Bugs or Unimplemented Features?

2008-06-24 Thread Ovid
I'm trying to figure out the best way of knowing which features are
implemented.  Looking through the tests in languages/perl6/t/ is a bit
disappointing as some things I know have been implemented aren't there
(e.g., types on sub signatures).  Should I be looking elsewhere?

So for right now, I'm looking at this:

  sub foo(Int $x) { 
say $x 
  }
  foo(4);

That works just fine, so I know we have types on signatures.  But now
this fails:

  # remove the 'Int' and this works
  sub fact (Int $n) {
if 0 == $n {
  return 1;
}
else {
  return $n * fact($n - 1);
}
  }

  say fact(5);

The failure is at runtime, not compile time (full output below), but
I'm not sure how to proceed since I don't know if this is supposed to
work yet.  Do I consult tests?  Follow the Rakudo blog?  Religiously
read this list?  (the latter's not much of an option because I love to
take breaks from email from time to time).

Cheers,
Ovid  

Null PMC access in type()
current instr.: 'fact' pc 334 (EVAL_15:127)
called from Sub '_block11' pc 34 (EVAL_15:17)
called from Sub 'parrot;PCT::HLLCompiler;eval' pc 806
(src/PCT/HLLCompiler.pir:481)
called from Sub 'parrot;PCT::HLLCompiler;evalfiles' pc 1088
(src/PCT/HLLCompiler.pir:610)
called from Sub 'parrot;PCT::HLLCompiler;command_line' pc 1267
(src/PCT/HLLCompiler.pir:699)
called from Sub 'parrot;Perl6::Compiler;main' pc 12318 (perl6.pir:174)
perl6(27829) malloc: ***  Deallocation of a pointer not malloced:
0x31c1750; This could be a double free(), or free() called with the
middle of an allocated block; Try setting environment variable
MallocHelp to see tools to help debug
perl6(27829) malloc: ***  Deallocation of a pointer not malloced:
0x6bb04b; This could be a double free(), or free() called with the
middle of an allocated block; Try setting environment variable
MallocHelp to see tools to help debug

--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Building Junctions from Junctions

2008-06-23 Thread Ovid
Hi all,

I use Perl6::Junction in Perl 5 and recently the author implemented the
values method on junctions.  I needed this because I sometimes find
that I need to do something conceptually similar to this:

  my $number = any( 0 .. 19 );
  while ($number-values) {
my $rand int(rand(20));
if ( $number == $random_number ) {

  # handle some task and discard the number
  $number = any( grep { $_ != $rand } $number-values );
}
  }

In other words, sometimes I have code which receives a junction and
needs to provide a new junction based on the values of the old
junction, but with some values removed.

How do I do that in Perl 6?  I can't see that in the docs.  Clearly we
don't this to be done destructively as I suspect this will break
autothreading, but building new junctions based on old junctions seems
reasonable.

Cheers,
Ovid

--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Personal blog- http://publius-ovidius.livejournal.com/
Tech blog- http://use.perl.org/~Ovid/journal/
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6 
Official Parrot Wiki - http://www.perlfoundation.org/parrot


Re: Graph for Rakudo Blog Post about Passing Tests

2008-06-19 Thread Ovid
--- Moritz Lenz [EMAIL PROTECTED] wrote:

 Attached is an updated version, as well as an example chart it
 creates.
 This is not as pretty as the previous version, but it's more
 informative.
 If there are significant number of failed tests, I could also include
 their number.
 
 Any comments?

Looks great.  However, from a testing perspective, I'm wondering why
there is such a huge number of skipped tasks.  Shouldn't those be TODO
tasks?  Skips are really easy to ignore and it's virtually impossible
to know if they'll ever pass but TODO tests unexpectedly succeeding
tend to stand out.

That being said, skips should be in place if, say, you have a Win32
test on Linux, but skips should be rare.  Here almost half the tests
are skips and I don't know why.

Cheers,
Ovid

--
Buy the book  - http://www.oreilly.com/catalog/perlhks/
Personal blog - http://publius-ovidius.livejournal.com/
Tech blog - http://use.perl.org/~Ovid/journal/


  1   2   3   4   >