PREV Mutating meaning: What?! NEXT


Mutating meaning

  • The idea is that some sort of declaration can change the meaning of subsequent code.

  • Pragmas do it:
    use integer;
    print (0.3 + 1.2);
    The + sign takes on a different meaning when use integer is in scope. It does integer addition rather than floating point addition.

  • use strict is a pragma which restricts the meaning of your code, rather than actually changing it. If the strict 'refs' pragma is in scope, then when we see an expression like $$foo we can be sure that $foo is a reference rather than a string.

    An ambiguity has been eliminated by prohibiting one of the possible meanings: symbolic reference.

  • Pragmas can only work by co-operating with the perl core, but...
  • It's possible, to some extent, to write pure modules which can change the meaning of code. I'll call them Mutagenic Modules.

  • There's a hotchpotch of mechanisms in Perl, each of which allows us to change the meaning of a particular type of operation. We'll look at some of these in the next section.

  • Dave Cross's Symbol::Approx::Sub is, of course, a mutagenic module. So is Abigail's Pythonesque.

  • Brian Ingerson's Inline and Damian Conway's Switch are both examples of modules which add extra syntax to the language, but couldn't ever change the meaning of existing programs. So I'd say they aren't truly mutagenic, and I'll call them language extensions. We'll see that some of the techniques that are useful for writing mutagenic modules can also be used to extend the language.

  • There is also a family of modules which change the code syntax, often very radically. Damian's Lingua::Romana::Perligata, Evil Dave's Pony and so on. I'll call them translator modules. They're not the same as mutagenic modules. >>