http://www.perlmonks.org?node_id=639652


in reply to [Perl 6] Even more freedom for custom operators?

I read recently about a "juxtaposition operator" in Fortress. This is the (overloadable) operator that allows "A x" to mean "A multiplied by x". Coupled with the ability to use unicode for things like sums, etc., it makes a beautiful syntax for mathematicians.
  • Comment on Re: [Perl 6] Even more freedom for custom operators?

Replies are listed 'Best First'.
Re^2: [Perl 6] Even more freedom for custom operators?
by ikegami (Patriarch) on Sep 18, 2007 at 15:34 UTC

    I don't know about Perl 6, but Perl 5 parses code differently based on whether an operator or expression is expected. This probably makes such an operator impossible to implement. Worse yet, the context dependency happens with every basic math operator:

    $y = 2+$x; # + = addition operator $y = +$x; # + = disambiguation operator $y = 2-$x; # - = subtraction operator $y = -$x; # - = arithmetic negation operator $y = 1*FOO; # * = multiplication operator $y = *FOO; # * = Glob sigil $y = 1/... # / = division operator $y = /... # / = match operator

    How would you write something as simple as "$A multiplied by the negation of $x" using this operator?

Re^2: [Perl 6] Even more freedom for custom operators?
by blazar (Canon) on Sep 18, 2007 at 15:17 UTC
    [...] it makes a beautiful syntax for mathematicians.

    Very true! But I think it will never fit into Perl. For the likes of ambrus there are J and K, one of which must be the language he used in his cool reply to a post of mine.