Since Perl is changing from -> to . (a change I welcome).  It might be
interesting to ask ourselves if there is any benefit from langauges like C++
or OCL that use both the -> and the .

>From OCL's point of view the -> is used for "meta" level things such as
iterations over collections.  The . is used for actual object method calls.

>From C++'s point of view, there is really no need for two different
operators (one for pointers and the other for stack allocated).  However,
the reason is primarily historical as it adopted the syntax from C.
Nevertheless, C++ benefits from this syntax becuase it allows things to
overload the -> operator thereby allowing smart pointers and such while the
.. operator cannot be overloaded to ensure correct binding semantics.

I was wondering if Perl6 could take advantage of this type of idea and have
some sort of way to overload operator "."

I could see something like:

method operator.( $self: $function ) {
  if( $function eq "inc" ) { ++%self.funcount{$_[2]}; }
  else { $self.inc( $function ) }
}

That would count how many times you called each function.

The problem then is when you call a method or access a data member inside
operator "." then it becomes infinitely recursive.  Nevertheless it would be
really nice if this type of functionality could be achieved fairly simply.

Any ideas?

Tanton

Reply via email to