Skip to content
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] document that range operator cannot be overloaded #12910

Closed
p5pRT opened this issue Apr 11, 2013 · 10 comments
Closed

[PATCH] document that range operator cannot be overloaded #12910

p5pRT opened this issue Apr 11, 2013 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 11, 2013

Migrated from rt.perl.org#117573 (status was 'resolved')

Searchable as RT117573$

@p5pRT
Copy link
Author

p5pRT commented Apr 11, 2013

From @moritz

Hi all,

attached patch documents some pitfalls wrt '..' not being overloadable
and bigints. It was triggered by the discussion at
http​://www.perlmonks.org/?node_id=1028141, though I've run into the same
limitation before.

I've tried to match bigint.pm's weird style of using initial tabs and
then two spaces for indentation, but I'm not mad at anybody who wants to
reformat the patch before pushing it :-)

Cheers,
Moritz

@p5pRT
Copy link
Author

p5pRT commented Apr 11, 2013

From @moritz

0001-document-that-.-can-not-be-overloaded.patch
From 3685d53313de808905a9d0940b19af7d0079f675 Mon Sep 17 00:00:00 2001
From: Moritz Lenz <moritz@faui2k3.org>
Date: Thu, 11 Apr 2013 15:06:32 +0200
Subject: [PATCH] document that .. can not be overloaded

Also document that this means that ranges and bigint.pm do not mix perfectly.
---
 dist/bignum/lib/bigint.pm |   14 ++++++++++++++
 lib/overload.pm           |    4 ++++
 2 files changed, 18 insertions(+)

diff --git a/dist/bignum/lib/bigint.pm b/dist/bignum/lib/bigint.pm
index 38aa7da..647cb29 100644
--- a/dist/bignum/lib/bigint.pm
+++ b/dist/bignum/lib/bigint.pm
@@ -608,6 +608,20 @@ This method only works on Perl v5.9.4 or later.
 
 =over 2
 
+=item ranges
+
+Perl does not allow overloading of ranges, so you can neither safely use
+ranges with bigint endpoints, nor is the iterator variable a bigint.
+
+	use 5.010;
+	for my $i (12..13) {
+	  for my $j (20..21) {
+	    say $i ** $j;  # produces a floating-point number,
+	                   # not a big integer
+	  }
+	}
+
+
 =item in_effect()
 
 This method only works on Perl v5.9.4 or later.
diff --git a/lib/overload.pm b/lib/overload.pm
index ce339cd..66ca940 100644
--- a/lib/overload.pm
+++ b/lib/overload.pm
@@ -1675,6 +1675,10 @@ coincides with the current one.
 
 Barewords are not covered by overloaded string constants.
 
+=item *
+
+The range operator C<..> cannot be overloaded.
+
 =back
 
 =cut
-- 
1.7.10.4

@p5pRT
Copy link
Author

p5pRT commented Apr 11, 2013

From @moritz

... and another one; I didn't catch the omission in the first sentence
of the DESCRIPTION at first.

@p5pRT
Copy link
Author

p5pRT commented Apr 11, 2013

From @moritz

0001-bigint.pm-be-more-accurate-in-the-docs.patch
From 885880792e6acc2853062aa549334f598cf6dc3c Mon Sep 17 00:00:00 2001
From: Moritz Lenz <moritz@faui2k3.org>
Date: Thu, 11 Apr 2013 15:17:04 +0200
Subject: [PATCH] [bigint.pm] be more accurate in the docs

---
 dist/bignum/lib/bigint.pm |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/dist/bignum/lib/bigint.pm b/dist/bignum/lib/bigint.pm
index 647cb29..bb0ae69 100644
--- a/dist/bignum/lib/bigint.pm
+++ b/dist/bignum/lib/bigint.pm
@@ -328,8 +328,8 @@ bigint - Transparent BigInteger support for Perl
 
 =head1 DESCRIPTION
 
-All operators (including basic math operations) are overloaded. Integer
-constants are created as proper BigInts.
+All operators (including basic math operations) except the range operator C<..>
+are overloaded. Integer constants are created as proper BigInts.
 
 Floating point constants are truncated to integer. All parts and results of
 expressions are also truncated.
-- 
1.7.10.4

@p5pRT
Copy link
Author

p5pRT commented Apr 11, 2013

From [Unknown Contact. See original ticket]

... and another one; I didn't catch the omission in the first sentence
of the DESCRIPTION at first.

@p5pRT
Copy link
Author

p5pRT commented Apr 11, 2013

@moritz - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 11, 2013

From @jkeenan

On Thu Apr 11 06​:18​:12 2013, moritz wrote​:

... and another one; I didn't catch the omission in the first sentence
of the DESCRIPTION at first.

Moritz,

+1 on both patches; I tested the example in the first and observed that
I got the same result with 'use bigint' and without same.

But since I'm not an expert on overloading or on bigint, I'd appreciate
a second opinion before applying.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Apr 13, 2013

From @rjbs

Looks good.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Apr 14, 2013

From @jkeenan

On Sat Apr 13 09​:02​:03 2013, rjbs wrote​:

Looks good.

Applied, after bumping version numbers, in commit
45e230d.

Closing ticket.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Apr 14, 2013

@jkeenan - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant