aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-10-02 14:42:51 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-10-02 14:42:51 -0400
commit54e336e30f2112dc2cb0c1b85dd153667680e550 (patch)
tree6d933b3479c08e7d2f0ec00a40badcfbdb28002e /compile.c
parentc8c137639c99793a7a2136f2bdc8de903bf4b5ec (diff)
Update array:sample() to use optional weights and do more error checking
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index 5077d499..89a480e7 100644
--- a/compile.c
+++ b/compile.c
@@ -2620,8 +2620,9 @@ CORD compile(env_t *env, ast_t *ast)
} else if (streq(call->name, "sample")) {
CORD self = compile_to_pointer_depth(env, call->self, 0, false);
arg_t *arg_spec = new(arg_t, .name="count", .type=INT_TYPE,
- .next=new(arg_t, .name="weights", .type=Type(ArrayType, .item_type=Type(NumType)),
- .default_val=FakeAST(Array, .item_type=new(type_ast_t, .tag=VarTypeAST, .__data.VarTypeAST.name="Num"))));
+ .next=new(arg_t, .name="weights", .type=Type(ArrayType, .item_type=Type(NumType)),
+ .default_val=FakeAST(Null, .type=new(type_ast_t, .tag=ArrayTypeAST,
+ .__data.ArrayTypeAST.item=new(type_ast_t, .tag=VarTypeAST, .__data.VarTypeAST.name="Num")))));
return CORD_all("Array$sample(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ",
padded_item_size, ")");
} else if (streq(call->name, "shuffle")) {