But... that's exactly what arrayref-overloading does. I believe you can base your matrix class entirely on that. You'd access a matrix object $m like this
Yes, yes, yes, diotalevi pointed that out already, I updated the root node, and I'm still D'oh'ing.
The syntax is pure Perl. Your's is more compact and closer to conventional mathematical notation. In fact, I like it and will keep it in mind for future matrix work.
Whoa! Although that was somewhat a minor detail in my post, I'm happy that something good is getting out of it and I feel honoured, and I'm not joking!
It's really all about me being a nut for not having much experience with overload, reading its documentation quickly and making a wrong assumption. Had I read all of it, I would have of course known better.
Boo! That spoils most of the inside-out fun. Your objects rely on their body being a coderef, never mind how you access properties. Your class is hybrid to begin with and can't easily accomodate (inheritance-wise) a foereign class.
No, Anno, why do you say so? My objects IMHO do not rely on being coderefs. The implementation of some methods does, but as an option. One should not care about that and only be concerned about the interface anyway, shouldn't she? Indeed the coderef thingy only provides a shortcut that can, not that must, be used. Granted, sub-deref overloading is a much better means to obtain the same shortcut. (If the shortcut itself is part of the interface as opposed to an implementation detail, I suppose using it in derived classes would be legitimate as well.) Anyway, can't you have a derived class with code such as the following?
# -*- Perl -*- use strict; use warnings; package Matrix::Named; use Scalar::Util qw/refaddr/; use base 'Matrix'; { my %name; sub name { my $id=refaddr shift; @_ ? $name{$id}=shift : $name{$id}; } sub DESTROY { delete $name{refaddr shift} } } sub new { my $class = shift; my $name = pop; bless(Matrix->new(@_) => $class)->init($name); } sub init { my ($obj,$name)=@_; $obj->name($name); $obj; } # ...
In reply to Re^2: Agile syntax (abuse?)
by blazar
in thread Agile syntax (abuse?)
by blazar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |