Skip to content

Commit 79d4915

Browse files
feat: arr_fill(value, n) builtin
Create an array of n copies of any value — works with strings, ints, floats, dicts, arrays, null. Essential for initializing fixed-size arrays and creating batch prompt lists. arr_fill("hello", 3) -> ["hello", "hello", "hello"] arr_fill(0, 5) -> [0, 0, 0, 0, 0] arr_fill(null, 4) -> [null, null, null, null] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c402419 commit 79d4915

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

omnimcode-core/src/interpreter.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,7 @@ impl Interpreter {
23382338
// Polish round
23392339
| "str_pad_left" | "str_pad_right" | "arr_zip" | "arr_unique"
23402340
| "arr_take" | "arr_drop" | "arr_count" | "arr_repeat"
2341-
| "arr_zeros" | "arr_ones" | "arr_chunk" | "arr_flatten"
2341+
| "arr_fill" | "arr_zeros" | "arr_ones" | "arr_chunk" | "arr_flatten"
23422342
| "arr_enumerate" | "arr_window"
23432343
// Meta-evaluation
23442344
| "eval_omc" | "eval_omc_fresh" | "eval_omc_ctx" | "omc_source"
@@ -5321,6 +5321,16 @@ impl Interpreter {
53215321
Ok(Value::Array(HArray::from_vec(items)))
53225322
}
53235323
// arr_zeros(n) — array of n zeros (HInt). NumPy idiom.
5324+
// arr_fill(value, n) — array of n copies of value. Works with any Value.
5325+
"arr_fill" => {
5326+
if args.len() < 2 {
5327+
return Err("arr_fill requires (value, n)".to_string());
5328+
}
5329+
let v = self.eval_expr(&args[0])?;
5330+
let n = self.eval_expr(&args[1])?.to_int().max(0) as usize;
5331+
let items: Vec<Value> = (0..n).map(|_| v.clone()).collect();
5332+
Ok(Value::Array(HArray::from_vec(items)))
5333+
}
53245334
"arr_zeros" => {
53255335
if args.is_empty() {
53265336
return Err("arr_zeros requires (n)".to_string());
@@ -14517,7 +14527,7 @@ pub(crate) const HEAL_BUILTIN_NAMES: &[&str] = &[
1451714527
"par_map", "par_filter", "par_reduce", "par_for",
1451814528
"arr_zip", "arr_unique",
1451914529
"arr_take", "arr_drop", "arr_count", "arr_repeat",
14520-
"arr_zeros", "arr_ones", "arr_chunk", "arr_flatten",
14530+
"arr_fill", "arr_zeros", "arr_ones", "arr_chunk", "arr_flatten",
1452114531
"arr_enumerate", "arr_window",
1452214532
// Meta-evaluation
1452314533
"eval_omc", "eval_omc_fresh", "eval_omc_ctx", "omc_source",

0 commit comments

Comments
 (0)