-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Michele Dondi wrote:
| I don't know if this is already provided by current specifications, but | since I know of Perl6 that is will support quite a powerful system of | function prototyping ("signatures"?), I wonder wether it will be possible | to specify a (finite number of) argument(s) on the left of functions, thus | allowing to create user-defined operators. I had tried sml (a functional | language) and despite its being really simple if compared to Perl, it | provided this functionality...
If SML is anything like Haskell, user-defined operators are really just syntactic sugar around normal function definitions, with appropriate allowances in the grammar for arbitrary operators to exist and be parsed correctly.
Haskell also has an interesting backticks operator, which turns any two-argument function into an infix operator, and is generally used for readability purposes. Thus, although you can do modulus with the 'mod' function like this:
mod 3 4
you can also write
3 `mod` 4
which can be handy when trying to get an arithmetic-type feel to your programs. I doubt Perl would need something like this though. Haskell of course also lets you do things like
infixr 3 +++
which defines a right-associative infix operator at precedence level 3, denoted by the token '+++'
and later you can say something like
(+++) :: Num a => a -> a -> a x +++ y = x + y
which defines the +++ operator to have exactly the same effect as + (although probably with different precedence, I have no idea what the numeric precedence level of + is in Haskell, and indeed if + is right or left associative, as I always get those two muddled up, so that might be different too) when applied to numbers. Pretty pointless really, unless you wanted a tight-binding + or a backwards one, but you get the idea. Most combinator parsing libraries use user-defined operators to denote parser combination and choice, and GUI libraries tend to use them to denote things like signal connection, property setting and so forth.
Wrangling this back to some sort of on-topicness, it would be great if Perl could have user-defined operators that actually work properly. I'm thinking new operator characters (Unicode's got lots left), and also the ability to define short-circuit operators like C's && and || (I can't remember what they've become in Perl 6, did they change? I seem to remember them changing). Not being able to do this is a major weakness in C++'s operator overloading, because it effectively means that && and || are untouchable unless you really want to mess with other people's heads, and demonstrate the only point operator overloading has against it (that is the potential disruption of expected semantics; this is all IMO of course).
So can we at least have the ability to define short-circuit operators, even if we can't define new ones?
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (Darwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFA2rP20UvYjCBpIlARAsFKAJoCBjgP8+wmbQP3XO1HLD+6AC43DQCfVvj3 kTT9cYnblCADyVCWCrpcpD0= =G7FE -----END PGP SIGNATURE-----