Re: extending built-in classes

2018-09-24 Thread Joseph Brenner
Thanks, yes that's one of the first approaches I looked at, but there's
still that extra "does" step before you can say $x.tellall;



On Sat, Sep 22, 2018 at 2:39 PM, Curt Tilmes  wrote:

> On Sat, Sep 22, 2018 at 5:30 PM Larry Wall  wrote:
>
>> On Sat, Sep 22, 2018 at 11:40:13AM -0700, Joseph Brenner wrote:
>> : Sounds good, thanks.
>>
>> Well, yes, *sounds* good.  :-)
>>
>> Monkey patching is allowed but discouraged in Perl 6, because Ruby.
>>
>
> Mixed in roles:
> https://docs.perl6.org/language/objects#Mixins_of_roles
> may be helpful as well.
>
> You can add a role not just to a class, but to an instance of any other
> class.
>
> my $x = "something";
> say $x.WHAT;
> role MyDebugRole { method mydebugthing { say "mydebugthing" } }
> $x does MyDebugRole;
> say $x.WHAT;
> $x.mydebugthing;
>
> (Str)
> (Str+{MyDebugRole})
> mydebugthing
>
> $x will totally act like it used to, but anywhere you like, now you can
> call .mydebugthing() on it.
>
> Pretty cool.
>
> Curt
>
>


Re: extending built-in classes

2018-09-24 Thread Brandon Allbery
There's a certain aspect of "there is nothing so permanent as a temporary
hack" here.

On Tue, Sep 25, 2018 at 12:19 AM Joseph Brenner  wrote:

> Larry Wall  wrote:
>
> > Joseph Brenner wrote:
> >> Sounds good, thanks.
>
> >   Well, yes, *sounds* good.  :-)
> >   Monkey patching is allowed but discouraged in Perl 6, because Ruby.
>
> But I *like* being evil.
>
> But as I was trying to make clear, it's not something I'm planning on
> using in production (unlike Ruby).
>
>
>
>

-- 
brandon s allbery kf8nh
allber...@gmail.com


Re: extending built-in classes

2018-09-24 Thread Joseph Brenner
Larry Wall  wrote:

> Joseph Brenner wrote:
>> Sounds good, thanks.

>   Well, yes, *sounds* good.  :-)
>   Monkey patching is allowed but discouraged in Perl 6, because Ruby.

But I *like* being evil.

But as I was trying to make clear, it's not something I'm planning on
using in production (unlike Ruby).


Re: Grammar doesn't seem to match any token

2018-09-24 Thread Ralph Mellor
Do you use Grammar::Tracer and especially Grammar::Debugger?
I'd say a TOP rule is... don't leave TOP without them.

--
raiph


Re: Grammar doesn't seem to match any token

2018-09-24 Thread Brad Gilbert
I recommend to default to using `token` rather than `rule` or `regex`.

If you need backtracking, use `regex`

If you have a lot of parts that match whitespace use `rule` (generally
used for combining other tokens.)
On Sun, Sep 23, 2018 at 7:13 PM Patrick R. Michaud  wrote:
>
> I suspect the rule:
>
> rule other { .  }
>
> means that in
>
> $input = '~i << my $w = Weaver.new();
> Weave.parse($input, :actions($w));
>
> the "other" rule cannot match the "Y" or the "Z" because there would need to 
> be a space between them.  The use of "rule" as a regex declarator implies 
> that spaces in the regex source are :sigspace, which means that whitespace in 
> the rule prevents two word characters from being adjacent at that point and 
> any available whitespace is consumed.
>
> Change "rule" to "token" on these rules and I suspect you'll get  to 
> match (although  will also end up matching the space after the "i" in 
> the text string, since white spaces are no longer significant).  Or try just 
> changing the  rule to be a token and leave the others as rules.
>
> Phrased another way, the  rule as written now is roughly equivalent to 
> writing
>
>token other { .  \s* }
>
> which will match a word character only when it's not immediately followed by 
> another word character.
>
> Pm
>
>
> On Sun, Sep 23, 2018 at 08:01:31PM -0400, yary wrote:
> > Let's see.
> >
> > If you have my $input = '~i o<<<', then  matches.
> >
> >  'rule' turns on :sigspace. If you use 'token' instead of 'rule' then
> >  matches.
> >
> > I don't quite have the full picture of what's happening.
> >
> > -y
> >
> > On Sun, Sep 23, 2018 at 7:07 PM, Mark Carter  wrote:
> >
> > > My grammar doesn't seem to match the 'other' rule. What's wrong with it?
> > >
> > > grammar Weave {
> > > token TOP {   * }
> > > rule el {   |  |   }
> > > rule lt { '<'  }
> > > rule tilde { '~' \S+ }
> > > rule other { .  }
> > > }
> > >
> > > class Weaver {
> > > has Str $.outstr;
> > >
> > > method TOP   ($/) { make $ ; put("top called") ; put($) }
> > > method el($/) { put($/) }
> > > method tilde ($/) { say 'tilde called' }
> > > method lt($/) { make '' ; put(''); $!outstr ~= 'X' }
> > > method other ($/) { $!outstr ~= '.'; say 'other called'; put('.');
> > > }
> > >
> > > }
> > >
> > > $input = '~i << > > my $w = Weaver.new();
> > > Weave.parse($input, :actions($w));
> > > say $w.outstr; # outputs XXX
> > >
> > > It never once says 'other called'. It seems to be matching the '<' signs
> > > OK, and I think the '~' is OK, too. It's just any other token that it's 
> > > not
> > > matching.
> > >