Skip to content

Commit e194136

Browse files
committed
add anti array
1 parent dfa3c63 commit e194136

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/compile/invert/un.rs

+31
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ pub static ANTI_PATTERNS: &[&dyn InvertPattern] = &[
292292
),
293293
&MatrixDivPat,
294294
&NoUnder(AntiCouplePat),
295+
&NoUnder(AntiArrayPat),
295296
&AntiFillPat,
296297
&AntiTrivial,
297298
&AntiRepeatPat,
@@ -929,6 +930,36 @@ inverse!(AntiCouplePat, input, _, Prim(Couple, span), {
929930
Ok((input, inv))
930931
});
931932

933+
inverse!(
934+
AntiArrayPat,
935+
input,
936+
asm,
937+
ref,
938+
Array {
939+
len,
940+
inner,
941+
boxed,
942+
allow_ext,
943+
prim,
944+
span
945+
},
946+
{
947+
let mut inner = un_inverse(inner.as_slice(), asm)?;
948+
inner.prepend(Node::Unpack {
949+
count: *len,
950+
unbox: *boxed,
951+
allow_ext: *allow_ext,
952+
span: *span,
953+
prim: *prim,
954+
});
955+
let inv = Node::from_iter([
956+
Mod(Dip, eco_vec![inner.sig_node()?], *span),
957+
ImplPrim(MatchPattern, *span),
958+
]);
959+
Ok((input, inv))
960+
}
961+
);
962+
932963
inverse!(ContraCouplePat, input, _, Prim(Couple, span), {
933964
let inv = Node::from_iter([
934965
ImplPrim(UnCouple, span),

tests/units.ua

+3
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ Test!(ₙ:)
286286
⍤⤙≍ 2 ⌝⊟ 1 [1 2]
287287
⍤⤙≍ 1 ⊙◌°⊸⊟ [1 2] 2
288288

289+
# Anti array
290+
⍤⤙≍ {2 3} {⌝⊟₃ 1 [1 2 3]}
291+
289292
# Select inverses
290293
⍤⤙≍ [0 1 1 2] ⊙◌°⊸⊏ [1 2 2 3] [1 2 3 2]
291294
⍤⤙≍ [0 0 0] ⊙◌°⊸⊏ [..1_2] [1_2 3_4 1_2]

0 commit comments

Comments
 (0)