Ron,

Execute the following and say what's your feeling -;

#!env perl
use Marpa::R2;

my $grammar = ":start ::= test\ntest ::= 'x'\n";
my $input = 'x';
my %hash = (grammar => Marpa::R2::Scanless::G->new( { source => \$grammar 
}) );

Marpa::R2::Scanless::R->new($hashp);
Marpa::R2::Scanless::R->new($hashp);


Le samedi 21 décembre 2013 20:14:31 UTC+1, rns a écrit :
>
> The first thing that came to mind was 
>
>
> my $self = shift; 
>
>
> Not sure if this fully applies here though.
>
>
> On Sat, Dec 21, 2013 at 7:48 PM, Jeffrey Kegler <
> [email protected] <javascript:>> wrote:
>
>>  I am forwarding the comment below from Jean-Damien into the group for 
>> feedback.
>>  
>> My sense of the matter is that Perl methods using named argument hashes 
>> are entitled to consume them in the process.  That means that after
>>  
>> $hashp = { ... repeatedly useful things };
>> my $recognizer = Marpa::R2::Scanless::R->new($hashp);
>>
>>  reuse of $hashp cannot be relied on to work, because Marpa::R2's 
>> methods may consume the hash pointed to by $hashp. (Marpa often needs to 
>> process its arguments in stages, and finds its useful to track those 
>> already processed by deleting elements.)  Note that the user can get around 
>> this by copying the hash, which moves the overhead for these unusual 
>> argument manipulations from application to user, which to my mind is a good 
>> thing.
>>
>> Anyone else have a sense of this matter?  Simply stating your personal 
>> preference is OK, but I'll give greater weight to evidence of best 
>> practices, traditions, etc.
>>
>> -- jeffrey
>>
>> -------- Original Message --------  Subject: Re: [Marpa--R2] Work on 
>> multiple lexers: t+, but noisy (f9d2b50)  Date: Sat, 21 Dec 2013 
>> 08:00:51 -0800  From: jddurand <[email protected]> <javascript:>  
>> Reply-To: 
>> jeffreykegler/Marpa--R2 
>> <reply+c-4923070-46b158946abddd67de008743caef1226be890a0d-173...@reply.github.com><javascript:>
>>   To: 
>> jeffreykegler/Marpa--R2 <[email protected]> <javascript:>  
>>
>>
>> Playing with user's arguments has side-effects. The line:
>>
>> delete $args[0]->{grammar};
>>
>> in particular is disastrous for callers that are storing a reference to a 
>> precompiled grammar, not having a reference to it anywhere else in this 
>> program than in the hash given in input to R->new().
>>
>> For example, if the grammar is precompiled and referenced only in a hash 
>> used as a R->new() parameter, then Scanless will happily destroy the 
>> precompiled grammar.
>>
>> Example with the perl6 advent calendar where I modified the arguments to 
>> R->new(). Look to $hashp in the source code at 
>> https://gist.github.com/jddurand/8071223
>>
>> Output is:
>>
>> 2♥ 5♥ 7♦ 8♣ 9♠                           : OK
>> 'grammar' name argument to scanless_r->new() is undefined
>>   It should be a ref to Marpa::R2::Scanless::G
>> Marpa::R2 exception at /tmp/perl6advent.day18.with.marpa.pl line 22.
>>
>> —
>> Reply to this email directly or view it on 
>> GitHub<https://github.com/jeffreykegler/Marpa--R2/commit/f9d2b50d9226c918738e9760c64c2893d6d13cc8#commitcomment-4923070>
>> .
>>
>>  
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "marpa parser" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to