David Mertens
2014-09-29 12:55:38 UTC
Hey everyone,
The Perl documentation on lvalue subs mentions Sentinel
<https://metacpan.org/pod/Sentinel>, a CPAN distribution which provides a
simple mechanism for controlling modification of an lvalue by "="
assignment. This is the simplest module I have seen to date with this
behavior. It achieves this behavior by overriding the get and set magic
methods (and the free magic method, for cleanup of course) for the scalar.
I would bet that if we set the same magic methods in our core pdl creation
method(s), we could get "=" assignment to Just Work. (Side note: this would
work regardless of how we do lvalue handling.)
The only trick then would be to make sure that somebody could reuse the
same $variable_name to refer to completely different piddles, rather than
croaking on mismatched thread dimensions.
I have considered the silent, unintended failure of "=" to be a wart in
PDL. It should at least warn, in a way that I can control.
Thoughts?
David
The Perl documentation on lvalue subs mentions Sentinel
<https://metacpan.org/pod/Sentinel>, a CPAN distribution which provides a
simple mechanism for controlling modification of an lvalue by "="
assignment. This is the simplest module I have seen to date with this
behavior. It achieves this behavior by overriding the get and set magic
methods (and the free magic method, for cleanup of course) for the scalar.
I would bet that if we set the same magic methods in our core pdl creation
method(s), we could get "=" assignment to Just Work. (Side note: this would
work regardless of how we do lvalue handling.)
The only trick then would be to make sure that somebody could reuse the
same $variable_name to refer to completely different piddles, rather than
croaking on mismatched thread dimensions.
I have considered the silent, unintended failure of "=" to be a wart in
PDL. It should at least warn, in a way that I can control.
Thoughts?
David
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan