in reply to Create a new operator, get LHS
How would one get the LHS (in the above case var) so I can use it in whatever implementation I decide to use?
If you want a real infix in operator, you will have to hack the perl parser, namely perly.y, toke.c and related files.
You could overload an existing infix operator with a in subroutine, but in your programs you would still use the overloaded operator (not in), which then just behaves as in, and your $var has to be blessed to that end.
There's a notation which at least looks similar to infix - method call:
$var->in(@list)
- but $var has to be blessed here, too, into the package into which the in method has been compiled:
package in { sub new { bless \$_[1],$_[0] } sub in { my $t = shift; scalar grep { $$t eq $_ } @_ } }; my $var = in->new(7); print "yup\n" if $var->in( 0 .. 8 ); __END__ yup
Not very tingly. Sorry about that.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Create a new operator, get LHS (lexical method)
by LanX (Saint) on Aug 26, 2015 at 13:37 UTC | |
by shmem (Chancellor) on Aug 26, 2015 at 17:36 UTC | |
by LanX (Saint) on Aug 26, 2015 at 22:38 UTC |