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


in reply to Implementing (elisp-like) buffers in Perl 6: how to do buffer-localisation of arbitrary package variables?

Hmmm... prototype-based programming?

Something like Self (or NewtonScript), where your objects inherit not from classes but from prototypes (usually one, but it can be extended), and each object is more-or-less a hash (with subrefs for methods), and you search for a value, given the key, starting from the invocant (which is passed to each method call unchanged) up through the proto chain.

$obj1={ _proto=>$base_obj, do_something=>sub{ print $_[0]->get('string')}, string=>'object one'}; $obj2={ _proto=>$obj1, change=>sub{ $_[0]->set('string',$_[1])}}; $obj2->call('do_something'); $obj2->call('set','object two'); $obj2->call('do_something'); $obj1->call('do_something'); __END__ would print: object one object two object one

This would work since the get walks the proto chain, but set sets thing directly on the invocant.

Of course you can clean up the syntax using AUTOLOAD and tied hashes, but that's just sugar.

In your case, you'll have each buffer as an object, with proto=>$BaseBuffer, and each "mode" will add itself to the proto chain: on reading, the value will be the mode's default, on writing you'll get a "buffer-local" variable.

-- 
        dakkar - Mobilis in mobile
  • Comment on Re: Implementing (elisp-like) buffers in Perl 6: how to do buffer-localisation of arbitrary package variables?
  • Download Code

Replies are listed 'Best First'.
Re: Re: Implementing (elisp-like) buffers in Perl 6: how to do buffer-localisation of arbitrary package variables?
by jdporter (Chancellor) on Mar 28, 2003 at 18:51 UTC