diff --git a/site/src/tutorial.rs b/site/src/tutorial.rs index f34c1ad0..40a8c7ca 100644 --- a/site/src/tutorial.rs +++ b/site/src/tutorial.rs @@ -1019,8 +1019,8 @@ fn TutorialAdvancedStack() -> impl IntoView {

"In general, planet notation as complex as the mathematical function example above should only be used when it is necessary. For examples like that with 4+ values, it is. However, when working with fewer values, you can get very far with just "" and "". Maybe sprinkle some ""s and ""s in there too."

- -

"As you write more Uiua code, you'll find that there is a pattern you'll encounter over and over again. It involves calling a function, then calling another function that re-uses an argument to the first function."

+ " and " +

"As you write more Uiua code, you'll find that there is a kind of pattern you'll encounter over and over again. It involves calling a function, then calling another function that re-uses an argument to the first function."

"One simple example is getting ""n"" numbers between ""0"" and ""1"". One way you may think to solve this is with "" and ""."

// Should fail

"This solution works, but as the style diagnostic suggests, it is not quite idiomatic."

diff --git a/src/algorithm/mod.rs b/src/algorithm/mod.rs index f754d72d..ac3d2e24 100644 --- a/src/algorithm/mod.rs +++ b/src/algorithm/mod.rs @@ -276,10 +276,10 @@ where return Ok(()); } if expand_fixed && arr.row_count() == 1 && ctx.scalar_fill::().is_err() { - let fixes = (arr.shape.iter()) - .take_while(|&&dim| dim == 1) - .count() - .min(arr.shape.len()); + let mut fixes = (arr.shape.iter()).take_while(|&&dim| dim == 1).count(); + if fixes == arr.rank() { + fixes = (fixes - 1).max(1) + } let same_under_fixes = (target.iter().skip(fixes)) .zip(arr.shape[fixes..].iter()) .all(|(b, a)| b == a); @@ -402,7 +402,7 @@ where } let a_shape = a.shape().clone(); let b_shape = b.shape().clone(); - let a_err = fill_array_shape(a, b.shape(), true, ctx).err(); + let a_err = fill_array_shape(a, &b_shape, true, ctx).err(); let b_err = fill_array_shape(b, &a_shape, true, ctx).err(); if shape_prefixes_match(&a.shape, &b.shape) { Ok(()) diff --git a/src/algorithm/pervade.rs b/src/algorithm/pervade.rs index 8b6f2feb..b3d00cf1 100644 --- a/src/algorithm/pervade.rs +++ b/src/algorithm/pervade.rs @@ -112,7 +112,7 @@ where // A is fixed if a.row_count() == 1 && b.row_count() != 1 { let fix_count = a.shape.iter().take_while(|&&d| d == 1).count(); - if b.rank() > fix_count { + if b.rank() > fix_count && b.rank() >= a.rank() { if (a.shape().iter()) .zip(b.shape()) .skip(fix_count) @@ -148,7 +148,7 @@ where // B is fixed if a.row_count() != 1 && b.row_count() == 1 { let fix_count = b.shape.iter().take_while(|&&d| d == 1).count(); - if a.rank() > fix_count { + if a.rank() > fix_count && a.rank() >= b.rank() { if (a.shape().iter()) .zip(b.shape()) .skip(fix_count) diff --git a/tests/units.ua b/tests/units.ua index 71f60409..9bd32749 100644 --- a/tests/units.ua +++ b/tests/units.ua @@ -14,16 +14,16 @@ ⍤⟜≍: ↯2_0_2e ×2↯2_0_2e # Fixed pervasive math -+ ¤100_200 [[1_2 3_4] [5_6 7_8] [9_10 11_12]] -⍤⟜≍: [[101_102 203_204] [105_106 207_208] [109_110 211_212]] -+ ¤¤100_200 [[1_2 3_4] [5_6 7_8] [9_10 11_12]] -⍤⟜≍: [[101_202 103_204] [105_206 107_208] [109_210 111_212]] -⍤⟜≍: [11_12_13 24_25_26] + 10_20 [1_2_3 4_5_6] -⍤⟜≍: [11_22_33 14_25_36] + ¤10_20_30 [1_2_3 4_5_6] -⍤⟜≍: [3_2_1 4_3_2 5_4_3] - ¤[1 2 3] [4 5 6] +⍤⟜≍: ⊃≡++ ¤100_200 [[1_2 3_4] [5_6 7_8] [9_10 11_12]] +⍤⟜≍: ⊃≡≡++ ¤¤100_200 [[1_2 3_4] [5_6 7_8] [9_10 11_12]] +⍤⟜≍: ⊃≡++ 10_20 [1_2_3 4_5_6] +⍤⟜≍: ⊃≡++ ¤10_20_30 [1_2_3 4_5_6] +⍤⟜≍: ⊃≡-- ¤[1 2 3] [4 5 6] ⍤⟜≍: 0_3 △ +¤ ↯3 0 ↯0_3 0 ⍤⟜≍: 1_3 △ +¤ ↯3 0 ↯1_3 0 -⍤⟜≍: ⇡10 + ¤¤0 ⇡10 +⍤⟜≍: ⊃≡≡++ ¤¤0 ⇡10 +⍤⟜≍: ⊃≡++ [0_1_2 3_4_5] ¤ [0_3_6 1_4_7 2_5_8] +⍤⟜≍: ⊃≡++ ¤ [0_1_2 3_4_5 6_7_8] [0_3_6 1_4_7 2_5_8] ⍤⟜≍: [11_12_13 21_22_23 31_32_33 41_42_43] + ¤[1 2 3] [10 20 30 40] ⍤⟜≍: [11_21_31_41 12_22_32_42 13_23_33_43] + ⊙¤[1 2 3] [10 20 30 40] ⍤⟜≍: [11_22_33 41_52_63] + ¤[1 2 3] [10_20_30 40_50_60]