New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] perlop: document that it is the operator that determines the operation #12921
Comments
From @moritzIMHO this is important to understanding how operators work in Perl 5, |
From @moritz0001-document-that-it-is-the-operator-that-determines-the.patchFrom 2fbfb0b04603b2ef347dcf3eaf33504665de38e0 Mon Sep 17 00:00:00 2001
From: Moritz Lenz <moritz@faui2k3.org>
Date: Sun, 21 Apr 2013 16:11:06 +0200
Subject: [PATCH] document that it is the operator that determines the
operation
In many other dynamic languages it is the operator plus the type of the
first operand, so it is worth mentioning.
---
pod/perlop.pod | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/pod/perlop.pod b/pod/perlop.pod
index 40402be..1fed7f1 100644
--- a/pod/perlop.pod
+++ b/pod/perlop.pod
@@ -5,6 +5,22 @@ perlop - Perl operators and precedence
=head1 DESCRIPTION
+In Perl, the operator determines what operation is performed,
+independent of the type of the operands. For example C<$a + $b>
+is always a numeric addition, and if C<$a> or C<$b> do not contain
+numbers, and attempt is made to convert them to numbers first.
+
+This is in contrast to many other dynamic languages, where the
+operation is determined by the type of the first argument. It also
+means that Perl has two versions of some operators, one for numeric
+and one for string comparison. For example C<$a == $b> compares
+two numbers for equality, and C<$a eq $b> compares two strings.
+
+There are a few exceptions though: C<x> can be either string
+repetition or list repetition, depending on the type of the left
+operand, and C<&>, C<|> and C<^> can be either string or numeric bit
+operations.
+
=head2 Operator Precedence and Associativity
X<operator, precedence> X<precedence> X<associativity>
--
1.7.10.4
|
From tchrist@perl.comMoritz Lenz (via RT) <perlbug-followup@perl.org> wrote
Absent any operator overloading on object operands. --tom |
The RT System itself - Status changed from 'new' to 'open' |
From perrettdl@googlemail.com"and attempt is made" should read "an attempt is made" Daniel On 21 April 2013 15:14, Moritz Lenz <perlbug-followup@perl.org> wrote:
|
From @ap* Moritz Lenz <perlbug-followup@perl.org> [2013-04-21 20:35]:
This one is not…
… at all like these. The meaning of `x` is dependent only on whether there are parentheses It is as though Perl 5 has two different repetition operators that just Regards, |
From @moritzOn 04/26/2013 10:45 PM, A. Pagaltzis via RT wrote:
so, how would you formulate it? (There is even a third one: reverse() does either list reversal or |
From @ap* Moritz Lenz <moritz@faui2k3.org> [2013-05-06 20:35]:
After thinking about this for a long time, I went back to the didactic Is it the goal here to instil encyclopædic knowledge of Perl arcana? Is it useful to alert the novice to exceptions that cause problems? In these terms, `x` and `reverse` are neither truly exceptions nor do Didactically it therefore seems best to me to consider those two as So I would write something like this: Beware of some notable unfortunate exceptions though: the bitwise This also goes beyond just giving the reader information, to giving them Regards, |
From @moritzOn 05/27/2013 06:32 PM, A. Pagaltzis via RT wrote:
Where would the encyclopaedic knowledge about Perl operators be, if not
They don't? Of course they are. They are cases where it's not the
I'm fine with your proposed changes, though not with your reasoning Cheers, |
From @apHi Moritz, * Moritz Lenz <moritz@faui2k3.org> [2013-05-29 02:30]:
It already is mentioned in the respective sections on `x` (and in the
I said “in these terms” they are not exceptions, i.e. they are not Only the bitwise operators (and smartmatch…) are exceptional in that
Well then. :-) I mean it’s doable to mention `x` as an exception there too, but to my Regards, |
From @tonycozOn Fri Apr 26 13:45:11 2013, aristotle wrote:
That's not entirely true, () x acts non-() x in scalar context: $ perl -le '@x = qw(a b); $, = ","; sub f { (@x) x 5 } print scalar f(); Thanks, applied as ae3f739 with the and Tony |
@tonycoz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#117689 (status was 'resolved')
Searchable as RT117689$
The text was updated successfully, but these errors were encountered: