[Southampton-pm] A case for custom infix operators

James Raspass jraspass at gmail.com
Fri Mar 21 13:27:48 PDT 2014


Ooo that's cunning, that module that Duncan just linked to uses overloading
of constants (docs:
http://perldoc.perl.org/overload.html#Overloading-Constants ).

This allows it to turn the string '1/2' into a Number::Fraction object at
compile time. Very clever.

I wonder what the scope is, surely just constants in the calling packing,
what if more than one imported packages set up similar constant
overloading? I can't imagine this is a very used feature of Perl. Cool
never-the-less.


On 21 March 2014 20:17, Duncan Garland <duncan.garland at ntlworld.com> wrote:

>
> http://search.cpan.org/~davecross/Number-Fraction-2.00/lib/Number/Fraction.pm
>
>
>
> Don't know if this is relevant, but Number::Fraction was conceived as a
> demonstration of operator overloading.
>
>
>
> *From:* Southampton-pm [mailto:southampton-pm-bounces+duncan.garland=
> ntlworld.com at pm.org] *On Behalf Of *James Raspass
> *Sent:* 21 March 2014 20:12
> *To:* southampton-pm at pm.org
> *Subject:* [Southampton-pm] A case for custom infix operators
>
>
>
> Inspired by this in Python - http://legacy.python.org/dev/peps/pep-0238
>
>
>
> I wanted to see how easily an integer dividing operator could be added to
> Perl.
>
>
>
> This implementation is a bit of a hack. I'm sure Tim'll appreciate the
> blessed scalar ref :P
>
>
>
> What do people think? It would be nice to have first class support for
> custom operators in Perl, there has been some discussion on P5P but it
> never went anywhere -
> http://www.nntp.perl.org/group/perl.perl5.porters/2013/08/msg205547.html
>
>
>
> [jraspass at gibson ~]$ ./div.pl
>
> 3.33333333333333
>
> 3
>
> 3.33333333333333
>
> 3
>
> 3.33333333333333
>
> 3
>
> 3.33333333333333
>
> 3
>
>
>
> PS we should really get an IRC channel :)
>
>
>
> James
>
> _______________________________________________
> Southampton-pm mailing list
> Southampton-pm at pm.org
> http://mail.pm.org/mailman/listinfo/southampton-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/southampton-pm/attachments/20140321/37aa60e1/attachment.html>


More information about the Southampton-pm mailing list