On Tue, 12 Mar 2002, Luke Palmer wrote: > Hello everyone. > > I just subscribed to this list. My name's Luke and I'm a perl > devotee. And I'm starting out with a bang. Here goes: > > I have just read through exegesis 3, and I found the bit about > defining your own new operators (eg. operator:*#@&) to be a little > strange. Not confusing, but esoteric and random. What functionality > does this provide to the language other than "It's cool." >
For once, PDL hijacks some Perl 5 operators in very abusive ways: http://pdl.perl.org/ So, it could use some more operators added to the language. It is possible that the Perl 6 operators set can compensate for it. However, defining new operators is a very good feature which I already thought of as missing in most languages I encountered. Regards, Shlomi Fish > I think, if anything, it would make things more confusing. Suppose a > module that implemented, say, a vector (disregarding that this isn't > really needed) provided a new operator .prod for dot product. What > would happen in the following case: > > use Vector; > $v = new Vector; > $v.prod $j; > > Does that last statement mean $v.prod($j), or ($v) .prod ($j)? Not to > mention, how is the user supposed to know that she can't say > $v.prod($j)? > > What about the example in the exegesis: 'operator:*#@&'? Take the > following code: > > $f *#@& > $g; > > What does this mean? Does this mean $f * $g with #@& as a comment, or > does it mean $f *#@& $g? But anyway, those are just language semantics > that could be worked out one way or another. The big confusion lies in > documentation and memory (human memory, that is). When your reading > through documentation for this Vector class, which would you rather > see? > > Vector provides an operator `.prod' for computing dot > products. It has the same precedence as the Perl binary * > operator. It also provides the xprod operator which has the same > precedence as Perl's binary + operator. > > --or-- > > Vector provides two methods, dot and cross, which compute the > dot product and the cross product, respectively, on their > arguments. > > The latter has significantly less to remember, using the > ever-so-familiar method, rather than entering two new operators with > precedences and all into your knowledge base. > > Also I think that these new operators would add a new level of > obfuscation to the language when it's not intended to be > obfuscated. When one encounters the *#@& operator, one must consult > the documentation for that operator, while method names are forced (at > least for people with any good taste) to make a small amount of sense. > > Not to mention the extra strain on the lexer, not that it matters > much. > > But in general, I suggest that the whole roll-your-own operator thing > be stripped from Perl 6. Not completely, however. I like the idea of > overloading existing operators, which has long been a part of the > language. I also kind of like the idea of defining infix > operators. But I think that would come back to the whole complication > with precedences again, which I don't find much elegance in. > > In summary, roll-your-own operators seem to be a contrived attempt at > being revolutionary, without providing much practicality. > > Not to bash them or anything :-P > > Luke Palmer, > [EMAIL PROTECTED] > -- ---------------------------------------------------------------------- Shlomi Fish [EMAIL PROTECTED] Home Page: http://t2.technion.ac.il/~shlomif/ Home E-mail: [EMAIL PROTECTED] He who re-invents the wheel, understands much better how a wheel works.