http://qs321.pair.com?node_id=617882


in reply to [Perl 6] Any provision for a "dereferencing object"?

If you reverse their order, it's simply a closure:

$dereferencer = { $^moose.<foo>[1]<bar><baz>[3] }; $dereferencer($datastructure);

Otherwise, you're looking for something like adding $datastructure to a prototype class with $dereferencer as a method, kinda quirky.

Update: two syntactical clarifications. {foo} is wrong because Perl 6 has no barewords; use either {'foo'} or the shorthand above that exploits the list quote operator. $^moose is just a placeholder variable, a scalable extension of the hardcoded $a and $b of sort comparators. There are other ways to express this idea.

Update II (more to the point): I said quirky, but of course I didn't mean impossible. If you're dead set on .<foo>[1]<bar><baz>[3] as a method you can sure compose $datastructure to a role that implements it. Unless I'm messing up the syntax (in which case I hope to be corrected):

role Profound { method dereferencer ($x) { $x.<foo>[1]<bar><baz>[3] } +} ($datastructure but Profound).dereferencer;