Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hmm, where to begin...

First of all, the executive summary: I think it'll be doable one way or another.

As Elian pointed out, if you want other people to understand what you're wanting, you might have to couch it in non-editor terms. (That being said, I used to hack around with Gosling's Emacs, so I know what you're saying.) Stated more generically, what you're asking for is a way to parameterize the lookup of variable names such that a particular generic variable name can refer to different specific variables at different times.

Perl has several mechanisms built in that get you most of the way there. As jdporter points out, package variables are thread local by default, so each thread gets its own copies of unshared variable. However, I don't think you necessarily want to tie a buffer to a thread.

As dakkar points out, you can get parameterized variables by using objects, where the attributes of the object can define themselves however they want. Perl 6 is trying to make object attributes work as much as possible like ordinary variables, so it might be acceptable to you to write $b.variable.

We've already said that you can curry classes into modules by assuming an invocant, so you could have a chunk of code that can even assume the $b. on the front. But then you don't get the sigils.

There's a mechanism built into regexes that variables of the form $?foo are kept in the current $0 object. That probably works outside of regexes as well.

Ordinary package variables don't support what you want, but if there were a way to declare a package using a global variable, then it'd be possible to compile variables in that scope to use that global variable as part of the variable's lookup strategy.

So there really are lots of ways to get the semantics you want. Which really means that you are asking for syntactic warpage after all. What you're asking for is that variables within a particular scope have a different lookup strategy than ordinary Perl names. So it'd be pretty easy to install a rule in the parser's grammar that lets you declare a variable using a new declarator that specifies a different "lifetime" for the variable. We currently have "my", "our", and "state" variables. You could set up a new declarator that declares buffer variables, and then binds the name however you jolly well please, using any of the parameterization methods we mentioned earlier to do the semantic warpage underneath.

If you want to discuss building a particular syntax in as standard, that should probably be discussed on the perl6-language mailing list.


In reply to Re: Implementing (elisp-like) buffers in Perl 6: how to do buffer-localisation of arbitrary package variables? by TimToady
in thread Implementing (elisp-like) buffers in Perl 6: how to do buffer-localisation of arbitrary package variables? by jonadab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 08:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found