Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

question on max | min op
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!

Report this thread to moderator Post Follow-up to this message
Old Post
Xiao Yafeng
04-01-08 12:59 PM


Re: question on max | min op
On 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>

Report this thread to moderator Post Follow-up to this message
Old Post
Mark J. Reed
04-01-08 12:59 PM


Re: question on max | min op
On 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>

Report this thread to moderator Post Follow-up to this message
Old Post
Mark J. Reed
04-01-08 12:59 PM


Re: question on max | min op
HaloO,

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

Report this thread to moderator Post Follow-up to this message
Old Post
TSa
04-01-08 12:59 PM


Re: question on max | min op
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Patrick R. Michaud
04-02-08 12:02 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL 6 Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:48 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.