Simplifying somewhat (ok, a heck of a lot), an rvalued:

    $foo is bar

or

    $foo : bar

is syntactic sugar for:

    bar($foo)

with some extra magic for handling a properties hash
associated with $foo's value, in particular resetting the
hash when $foo's value changes.

Right?

Basically, perl will (do the equivalent of) define a sub bar
if it doesn't exist, then call bar, and bar can attach some
data to the value in $foo, or update some data attached
to the value in $foo, and will always return $foo.

Right?

If I got the above badly wrong, the rest of this post
probably won't make sense.

I also presume it would make sense to alias $_ to $foo
in (the method associated with) bar. (Is that intended?)

---------

One could generalize so that bar can do as above, but
doesn't _have_ to do as above, ie it doesn't have to
attach data to $foo's value or update that data; it can
return a value other than $foo; and it can change the
value of $foo. Basically, an rvalued:

    $foo : bar

becomes a syntactically and cognitively cheap way, and
a cognitively very different way, of calling bar on $foo, a
cheapness and difference that amplifies if one applies
several of these:

    $foo : bar baz qux

instead of

    qux(baz(bar($foo)))

I realize this isn't particularly appealing, but bare with me
a little longer.

So, in:

    $foo : bar

bar in this context is not a property, but instead a more
general "post" or similar (alluding to the notion that it is
a bit like a postfix sub as well as (possibly) having the
sticky note aspect.)

So, to recap:

    $foo : bar;

means bar is posted to $foo. $foo's value may change
or stay the same. The return value may be $foo's, either
before or after posting, or some other value. $foo's value
may now have an attached bar postit.

Presumably bar can be a block, method, or expression:

    $foo : { code };
    $foo : method;

More interestingly:

    @foo : bar;

posts bar (expression, sub, block) to each element of
@foo. An alternate to 'for (@foo) bar' for single dim
arrays, and a syntactically cheap way to iterate over
entire multi-dim arrays (I'm assuming here that 'for'
won't, by default at least, iterate over all dimensions.)

    @foo : bar;
    @foo := bar;
    @foo = @foo : bar;

are possibly just alternate ways of saying the same thing.

    $foo := bar;
    $foo = $foo : bar;

are also probably alternate ways of saying the same
thing, but are not necessarily the same as:

    $foo : bar;

as the latter could return a value other than $foo.


Reply via email to