[Dbix-class] RFC - merits of overloading ops versus not doing so

Darren Duncan darren at darrenduncan.net
Mon Apr 19 00:06:52 GMT 2010


Darren Duncan wrote:
> Thank you to both G. Wade Johnson and Rob Kinyon for your replies to my 
> RFC; they have been very helpful.  I think what I will do in light of 
> this is add overloading for math and string functions + shorthands ("+" 
> parses into the same thing as "sum()" anyway) now, but not yet for 
> collection types, and see how that goes. -- Darren Duncan

As an addendum, last night's CPAN-released version 0.118.0 of the Muldis D 
language spec has incorporated the results of this discussion; specifically, the 
math and string functions and shorthands were consolidated and otherwise 
refactored, but no such changes were made to the collection-type operators at 
this time.

Again thank you for your feedback.

The primary change of this release was the introduction of the 2 mixin types 
(roles) "Numeric" (composed by "Int","Rat") and "Stringy" ("Blob","Text",etc), 
which came with 15 and 2 virtual functions each, and otherwise refactoring of 
the numeric functions, and refactoring the special shorthand syntax in the 
concrete grammars for numeric and stringy types; almost all of the shorthands 
were renamed; most of those are infix, a few prefix or postfix.

Here is a table showing all of the numeric and stringy operators having 
shorthands, mapping their new names and existences to the old ones:

     Numeric : Int, Rat

     Now | Example              | Function             | Before
         |                      |                      | Int   | Rat
     ----+----------------------+----------------------+-------+------
     ||  | || $x                | abs                  | i||   | r||
     +   | $x + $y + $z         | sum                  | i+    | r+
     -   | $x - $y              | diff                 | i-    | r-
     |-| | $x |-| $y            | abs_diff             | i|-|  | r|-|
     *   | $x * $y * $z         | product              | i*    | r*
     /   | $x / $y              | frac_quotient        | (N/A) | r/
     div | $x div $y round Down | whole_quotient       | i/    | (N/A)
     mod | $x mod $y round Down | remainder            | % mod | (N/A)
     ^   | $x ^ $y              | power_with_whole_exp | (N/A) | (N/A)

     just Int

     Now | Example   | Function      | Before
     ----+-----------+---------------+------------
     exp | $x exp $y | Integer.power | i^
     i!  | $x i!     | factorial     | (no change)

     just Rat

     Now   | Example             | Function       | Before
     ------+---------------------+----------------+------------
     **    | $x ** $y round ...  | Rational.power | r^
     log   | $x log $y round ... | log            | (no change)
     e**   | e** $x round ...    | natural_power  | e^
     log-e | $x log-e round ...  | natural_log    | (no change)

     Stringy : Blob, Text, Array, String, Name, NameChain, Comment

     Now | Example      | Function    | Before
         |              |             | Blob | Text | Array
     ----+--------------+-------------+------+------+------
     ~   | $a ~ $b ~ $c | catenation  | b~   | t~   | a~
     x   | $a x $z      | replication | b-x  | t-x  | a-x

See these urls for the main additions or changes:

- http://search.cpan.org/dist/Muldis-D/lib/Muldis/D/Core/Numeric.pod

- http://search.cpan.org/dist/Muldis-D/lib/Muldis/D/Core/Stringy.pod

- 
http://search.cpan.org/dist/Muldis-D/lib/Muldis/D/Dialect/PTMD_STD.pod#FUNCTION_INVOCATION_ALTERNATE_SYNTAX_EXPRESSIONS

-- Darren Duncan



More information about the DBIx-Class mailing list