feat: quote, nth

This commit is contained in:
2026-07-25 22:18:07 +02:00
parent 0e134957af
commit a789528026
4 changed files with 71 additions and 20 deletions
+30
View File
@@ -193,3 +193,33 @@ int builtin_ceil(Nodes args, Scopes *scopes, Node *result) {
result->as_number = ceil(args.items[0].as_number);
return 0;
}
int builtin_nth(Nodes args, Scopes *scopes, Node *result) {
UNUSED(scopes);
if (args.count != 2) {
printf("'nth' expects two arguments!\n");
return 1;
}
Node node_idx = args.items[0];
if (node_idx.kind != NODE_KIND_NUMBER) {
printf("'nth' expects an index as the first argument!\n");
return 1;
}
Node node_list = args.items[1];
if (node_list.kind != NODE_KIND_LIST) {
printf("'nth' expects a list as the second argument!\n");
return 1;
}
uint64_t idx = node_idx.as_number;
if (idx >= node_list.as_list->count) {
printf("Index out of bounds!");
return 1;
}
*result = node_list.as_list->items[idx];
return 0;
}