Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by dakkar (Hermit)
on Mar 28, 2003 at 18:18 UTC ( [id://246528]=note: print w/replies, xml ) Need Help??


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 (Paladin) on Mar 28, 2003 at 18:51 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246528]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2024-04-18 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found