Code Comments
Programming Forum and web based access to our favorite programming groups.I've read Synopsis and I wondered why to treat max and min as operator. IMHO, view them as list functions is more reasonable. Like below: @test.max is clearer than @test[0] max @test[1] or [max] @test. Any reply would be really appreciated and will much help me learn perl6. Thanks in advance!
Post Follow-up to this messageOn Tue, Apr 1, 2008 at 1:44 AM, Xiao Yafeng <xyf.xiao@gmail.com> wrote: > I've read Synopsis and I wondered why to treat max and min as > operator. IMHO, view them as list functions is more reasonable. Like > below: > > @test.max Which is how you would probably call it in Perl6. Or else max(@test) > > is clearer than > > @test[0] max @test[1] or [max] @test. Which is not legal Perl6. "max" and "min" may be called "operators", but that doesn't mean they're INFIX operator. In Perl6, just like in Perl5, all the builtin "functions" are really defiend as operators, including "print" etc. But you can always call an operator as if it were a function/method, and in most cases you will. pugs> [1,2,3].max 3 pugs> min(1,2,3) 1 -- Mark J. Reed <markjreed@mail.com>
Post Follow-up to this messageOn Tue, Apr 1, 2008 at 5:39 AM, Mark J. Reed <markjreed@mail.com> wrote: > Perl5, all the builtin "functions" are really defiend as operators, "defined", even. (However fiendishly.) Anyway, "function" vs "operator" is mostly a difference in terminology that makes no difference in practice, but I believe it is technically the "operator"-ness of these apparent functions that allows you to call them without parentheses: pugs> max 1, 2, 3 3 -- Mark J. Reed <markjreed@mail.com>
Post Follow-up to this messageHaloO, Mark J. Reed wrote: > Anyway, "function" vs "operator" is mostly a difference in terminology I'm not sure what the defined difference between function and operator is in Perl 6 but I make a very clear distinction. An operator is acting an *one* type, that is &op:(::T,T-->T) while a function is a mapping of different types &f:(::S,::T-->::R). IOW, Operator does Function but not the converse. So overloading an operator with inhomogenous types should not change the abstract properties of the operator but be a convenient form to upgrade the operants. > that makes no difference in practice, but I believe it is technically > the "operator"-ness of these apparent functions that allows you to > call them without parentheses: This is more about syntax than the distinction between operator and function. To me max is a commutative and associative operator. That is it could be defined in the pre-, post and infix slots. (max 1,2,3) == (1 max 2 max 3) == (1,2,3max) == (1,2,3\ max) == ([max] 1,2,3) == ((1,2,3)max) Note that (1,2,3.max) === (1,2,3 .max) === ((1,2),(3.max)) because .max tightens the precedence above that of comma and the return type becomes a list instead of a num. Regards, TSa. -- The Angel of Geometry and the Devil of Algebra fight for the soul of any mathematical being. -- Attributed to Hermann Weyl
Post Follow-up to this messageOn Tue, Apr 01, 2008 at 05:39:36AM -0400, Mark J. Reed wrote: > On Tue, Apr 1, 2008 at 1:44 AM, Xiao Yafeng <xyf.xiao@gmail.com> wrote: > > Which is how you would probably call it in Perl6. Or else > > max(@test) > > Which is not legal Perl6. "max" and "min" may be called "operators", > but that doesn't mean they're INFIX operator. "min" and "max" are infix operators in Perl 6. From Synopsis 3: : * Minimum and maximum : : $min0 min $min1 : $max0 max $max1 I think they're defined as operators because of some of the other features one can get from it, beyond just the [max] reduction: $c = $a max $b; # versus $c = ($a, $b).max; $d max= $e; # versus $d = ($d, $e).max; @c = @a »max« @b; # larger element of @a and @b @e = @a »max» 100; # each element is at least 100 Pm
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.