|P is for Practical|
Implementing (elisp-like) buffers in Perl 6: how to do buffer-localisation of arbitrary package variables?by jonadab (Parson)
|on Mar 28, 2003 at 16:36 UTC||Need Help??|
I've been thinking for a really long time that my dream language would have a lot of the features of Perl (hashes, fexible syntax, and so forth) and certain key features of other languages, most especially the object model from Inform and buffers (and the companion features that make them useful, such as markers and a standard library of functions to manipulate them) from Emacs lisp.
With me so far? Okay, so I've been reading the Apocalypse articles, and while the objects in Perl6 may not be quite exactly like the ones in Inform, they're going to be so much closer than the Perl 5 object model that they'll probably do. But that leaves buffers...
So I was thinking, hey, with this nice flexible object model, could we implement buffers in Perl6 as a module and throw it on CPAN? So I started thinking about how that would work...
A buffer, obviously, would be an object. The text it would store in some member data structure or another, and then it would also store other state, like string properties, a list of markers, metadata that applies to the whole buffer (filename if any, EOL mode, major mode, and so forth). So far so good. Markers are pretty easy, as long as all changes to the textual contents of the buffer go through methods on the buffer class, which have access to the buffer's list of all markers on the buffer. (Markers are their own class, of course, and know what buffer they point to as well as where, and moving them to point elsewhere goes through a member function that checks things like taking them off the old buffer's list if you point them into a new buffer.)
So, a class for buffers, a class for markers, ...
So far so good; I think all that could be easy enough to implement (though it would be a fairly large project, but also highly worth doing), but I ran into trouble when I started to think about making variables buffer-local. For buffers to be as useful as they are in elisp, it needs to be possible to give any package variable (from any package) a buffer-local value that applies whenever a certain buffer is the current buffer. (The current buffer presumably would be an important package var maintained by the buffers package.) And if a variable is buffer-local to the current buffer, then any assignments to it alter the buffer-local value, unless explicit steps are taken to set the default (global) value.
I thought about the syntactic warpage that the Apocalypse articles keep talking about, but I don't think any amount of syntax can accomplish this, because it's a semantic thing: *anything* that either retrieves or changes the value of any variable needs to check first to see if it's buffer-local to the current buffer (unless the variable is either lexically scoped or temporized, in which case those values take precedence).
So what I want to ask the monks (especially those who know more about Perl6 than I do) is, will it be possible via some other mechanism I don't know about or don't understand to do this as a module (or perhaps as a pragma or whatever -- I'm a little fuzzy on some of those distinctions) without having it in the core language? If so, approximately how?
Oh, and if not, how would we go about raising the issue now (while Perl6 is still set in Jello, rather than marble)? I'd really like to have a mechanism for this, because... well, it would just make for some very cool abilities. And to wait for Perl7 would be torment :-)