Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

RE: Re: Dreaming of Post Interpolation

by mdillon (Priest)
on May 30, 2000 at 20:52 UTC ( [id://15439]=note: print w/replies, xml ) Need Help??


in reply to Re: Dreaming of Post Interpolation
in thread Dreaming of Post Interpolation

YES!

this is the cleanest i've seen yet. the only thing that breaks this is unbalanced brackets, but in a 'sub interpolate', it's easy enough to get around such restrictions.

on a side note, the Interpolate module doesn't really help much for BBQ's problem. this solution, however, gets perl to do real double-quotish interpolation on an arbitrary scalar value.

Replies are listed 'Best First'.
RE: RE: Re: Dreaming of Post Interpolation (*)
by BBQ (Curate) on May 30, 2000 at 21:44 UTC
    Yeah, the Interpolat module wasn't as good as what it looked like from the examples. It just does a few tricks with hashes, and seems to be directed towards maintainin string formats more than actually doing heavy linkage.

    I think that what I was looking for is a new data state. Something that would cascade through whatever assignments had been done before. My numeric example was probably the best way to demonstrate. Come to think of it, cascade sounds like a cool name. Imagine it:
    cascade $n = 1; my $m = $n*2; my $o = $m*2; my $s = "$n $m $o\n"; print $s; $n = 2; print $s; ^d 1 2 4 2 4 8
    now would THAT be cool? Does anyone know if there a perl ideas/wishlist somewhere?

    #!/home/bbq/bin/perl
    # Trust no1!
      Hmm. Seems to me that this could be done with a fancy Tie somehow. Not quite as you have posted it though....Perhaps if $m, $o, and $s were also cascaded...
      How far would you want this to go? While the above example could be done, I can see it getting messy with subroutine calls. For example:
      $n=1; #we have no idea which variables should be cascaded. $subref=sub { return $n *3 }; print &$subref, "\n"; $n=2; print &$subref, "\n";
      Will that output
      3
      6
      ?.
      Stream of conciousness: the Monitor package uses a tie on a variable to track when a variable is changed...can we track when it is accessed, and turn on cascading for any lvalue, etc? (I see dire consequences on the stack/heap, but...) Then when any such value is modified, you could go through the cascade stack and reset every value. It would go nuts on code like:
      use Cascade; cascade $n; cascade $m; $n=1; $m=$n; $n=$m+1;
      Because $m is altered by $n, and thus when we change $n, we recalc $m, which is in turn set by $n, so we recalc....

      But I guess this isn't much different from screwing your reference count by doing a $a=\$a (except of course that that doesn't hang).

      All speculation anyway, since I don't believe that there is any way to find what lvalue is affected by a variable reference.

      The trouble is, you'd have to completely scrap the way Perl handles assignments.

      For $foo = $bar + 1, the rhs is evaluated first and the result is stored in $foo. What you want is to store the rhs expression in $foo (ie, more or less a sub ref).

      And, as swiftone says, every variable that has a cascaded variable on the rhs of its assignment is forced to become a cascade variable itself, with potentially dire results. Perhaps meltdown would be a better name :)

        Define potentially dire results. :)

        I only see this becoming a problem if you didn't think out your code before hand and just slopped everything in (which I do quite frequently btw). Having this new feature in the language wouldn't necessarily mean that everyone would use it, but it would guarantee yet another jump in the flexibility that perl is known for!

        I see your point on assignment of the lhs vs. rhs, but I would assume that if a new datatype were created for this purpose, error handling would be done in quite a different manner. Maybe even set a new readonly variable! (has $^Y been reserved yet?)

        I keep referencing back to spreadsheets (especially Excel) every time I look at the examples and alternatives everyone posted. It seems alot of monks were quite antipathetic about this idea, but then again I don't know anyone that uses all of the funtions in perl.

        #!/home/bbq/bin/perl
        # Trust no1!
      this is already possible with tie, although not quite so transparently. however, i'm sure that creative use of 'use overload' could be used to achieve the desired effect.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-23 17:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found