in reply to Re: Re: Re: Re: Using Perl6 patterns/grammar definition for <I>output</I>?
in thread Using Perl6 patterns/grammar definition for 'output'?
This is probably the type of code that would have been instantiated by the hash approach; but is more flexible, and allows for more powerful formating concepts (the visitor can maintain state between the things that it outputs).class MyFormat is CORE::GrammarVisitor { my $fh is public; method date ($node) { $fh.printf("%04d-%02d-%02d", $node ^. qw(year month day)) } } $0.traverse(MyFormat.new(fh=>$*STDOUT)); # default ctor?
But going back to the hash-based approach, I think that it is possible to do something like:
I think this would be kinda scary though.my $sub = sub {print $value}; $sub.MY{'$value'} = 42; $sub();
--Dave
Update: Fixed typo: MY{'$date'} becomes MY{'$value'}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^5: Using Perl6 patterns/grammar definition for <I>output</I>?
by John M. Dlugosz (Monsignor) on Sep 06, 2002 at 15:49 UTC |