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

Reduced && ([&&] and [and]) is not implemented #1886

Closed
p6rt opened this issue Jun 27, 2010 · 4 comments
Closed

Reduced && ([&&] and [and]) is not implemented #1886

p6rt opened this issue Jun 27, 2010 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 27, 2010

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

Searchable as RT76206$

@p6rt
Copy link
Author

p6rt commented Jun 27, 2010

From kapranoff@gmail.com

Since && and "and" are special-cased for short-circuiting automatic
reduction does not happen.

Here a simple patch "by analogy".

Index​: S03-metaops/reduce.t

--- S03-metaops/reduce.t (revision 31194)
+++ S03-metaops/reduce.t (working copy)
@​@​ -111,6 +111,16 @​@​
  is (~ [\||] 0, 0, 3, 4, 5), "0 0 3 3 3", "[\\||] works";
}

+#?rakudo skip 'implement [&&] and [and]'
+{
+ my @​array = (Mu, Mu, 0, 3, Mu, 5);
+ my @​array1 = (2, 3, 4);
+ nok ([&&] @​array), "[&&] works with 1 false";
+ is ([&&] @​array1), 4, "[&&] works";
+ nok ([and] @​array), "[and] works with 1 false";
+ is ([and] @​array1), 4, "[and] works";
+}
+
# not currently legal without an infix subscript operator
# {
# my $hash = {a => {b => {c => {d => 42, e => 23}}}};

Inline Patch
diff --git a/src/core/operators.pm b/src/core/operators.pm
index ecdd356..4ad0884 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -553,10 +553,12 @@ our multi sub infix:<X>($a, $b) { &infix:<X>($a.list,
$b.list) }

# if we want &infix​:<||> accessible (for example for meta operators), we
need
# to define it, because the normal || is short-circuit and special cased by
-# the grammar. Same goes for 'or'
+# the grammar. Same goes for 'or', '&&' and 'and'

our multi sub infix​:<||>(Mu $a, Mu $b) { $a || $b }
our multi sub infix​:<or>(Mu $a, Mu $b) { $a or $b }
+our multi sub infix​:<&&>(Mu $a, Mu $b) { $a && $b }
+our multi sub infix​:<and>(Mu $a, Mu $b) { $a and $b }

# Eliminate use of this one, but keep the pir around for
# the moment, as it may come in handy elsewhere.

--
Alex Kapranoff.

@p6rt
Copy link
Author

p6rt commented Jun 29, 2010

From @jnthn

On Sun Jun 27 14​:21​:34 2010, kapranoff@​gmail.com wrote​:

Since && and "and" are special-cased for short-circuiting automatic
reduction does not happen.

Here a simple patch "by analogy".

Applied patch and tests, thanks.

Jonathan

@p6rt
Copy link
Author

p6rt commented Jun 29, 2010

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 29, 2010

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

@p6rt p6rt closed this as completed Jun 29, 2010
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant