develooper Front page | perl.perl6.language | Postings from December 2003

RE: Properties -- distributive, predeclared, post-applied....??

Thread Next
Hodges, Paul
December 4, 2003 16:12
RE: Properties -- distributive, predeclared, post-applied....??
Message ID:
How about

  use Baz; # assume object type
  my property foo;
  my @bar of Baz is false but foo; # maybe not what you meant?

If you apply a trait like false to an array, I expect it to apply to the
"array instance object" itself and not the content, so that 
  push @bar,;
  if @bar    { print "stuff"; } else { print "empty"; } # oops! false!
  if @bar[0] { print " oops"; } else { print " ok";   } # oops! not false!
would print "empty oops" instead of "stuff ok". 

I'd *like* to be able to predeclare a trait or property to be distributed
across any values placed in this array, but only this array. For example, it
would be nice if I could have the default aspects of false and foo be
applied to any Baz that gets stuck into @bar, but obviously this isn't the
syntax to do it. I could make Baz's new() do it, but I don't want *ALL* Baz
objects to be false and foo...just the ones in @bar. So, what I need is
something more like

  my @bar of Baz;
  @bar.STORE.wrap { my $r = call; return $r >>but=<< (false,foo); }

But I'm not sure C<$r >>but=<< (false,foo)> works, and I really wanted to
figure out a way to do it all in the declaration. Maybe it could be

  my @bar of Baz will do STORE.wrap { call >>but=<< (false,foo); }

but I'm not sure call will behave as an lvalue and still set up the
appropriate return, I don't expect @bar to accept "will do", and I don't
think "will do" is where the wrap should go. I'm just trying to wrap my
brain around this brick and I can't find all the references that tell me all
the little pieces so that I can compare them for a closer approximation,

"The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential, proprietary, and/or
privileged material.  Any review, retransmission, dissemination or other use
of, or taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited.  If you received
this in error, please contact the sender and delete the material from all

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About