Skip to content

Commit

Permalink
make un repeat require a count inside
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 23, 2024
1 parent 55fba48 commit ffcc6a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ This version is not yet released. If you are reading this on the website, then t
- [`join ⊂`](https://uiua.org/docs/join) will rank differences greater than 1 can now extend the smaller array
- [`un °`](https://uiua.org/docs/un) [`join ⊂`](https://uiua.org/docs/join) is now easier to combine with other inverses
- [`repeat ⍥`](https://uiua.org/docs/repeat) can now repeat a negative number of times, which will repeat the inverse
- [`un °`](https://uiua.org/docs/un) [`repeat ⍥`](https://uiua.org/docs/repeat) now requires the repetition count to be inside the [`un °`](https://uiua.org/docs/un) function
- This makes the inverted signature correct
- [`inventory ⍚`](https://uiua.org/docs/inventory) no longer does [`each ∵`](https://uiua.org/docs/each)-like behavior
- This got in the way more than it helped
- Add the experimental [`triangle ◹`](https://uiua.org/docs/triangle) modifier, which calls a function on shrinking suffixes of an array's rows
Expand Down
25 changes: 13 additions & 12 deletions src/algorithm/invert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2125,22 +2125,23 @@ fn invert_repeat_pattern<'a>(
input: &'a [Instr],
comp: &mut Compiler,
) -> Option<(&'a [Instr], EcoVec<Instr>)> {
let (input, mut instrs) = Val.invert_extract(input, comp)?;
match input {
[Instr::PushFunc(f), repeat @ Instr::Prim(Primitive::Repeat, span), input @ ..] => {
let instrs = f.instrs(&comp.asm).to_vec();
let inverse = invert_instrs(&instrs, comp)?;
let inverse = make_fn(inverse, *span, comp)?;
let f_instrs = f.instrs(&comp.asm).to_vec();
let inverse = invert_instrs(&f_instrs, comp)?;
instrs.extend(inverse);
let inverse = make_fn(instrs, *span, comp)?;
Some((input, eco_vec![Instr::PushFunc(inverse), repeat.clone()]))
}
[Instr::PushFunc(inv), Instr::PushFunc(f), Instr::ImplPrim(ImplPrimitive::RepeatWithInverse, span), input @ ..] => {
Some((
input,
eco_vec![
Instr::PushFunc(f.clone()),
Instr::PushFunc(inv.clone()),
Instr::ImplPrim(ImplPrimitive::RepeatWithInverse, *span),
],
))
[Instr::PushFunc(inv), Instr::PushFunc(f), Instr::ImplPrim(ImplPrimitive::RepeatWithInverse, span), input @ ..] =>
{
instrs.extend([
Instr::PushFunc(f.clone()),
Instr::PushFunc(inv.clone()),
Instr::ImplPrim(ImplPrimitive::RepeatWithInverse, *span),
]);
Some((input, instrs))
}
_ => None,
}
Expand Down

0 comments on commit ffcc6a6

Please sign in to comment.