feat: reverse List.insert argument order to index-first, value-second

The `List.insert` method signature is changed from `insert(item, index)` to `insert(index, item)`, aligning with standard practice in most languages. All documentation, core implementation, and test files are updated to reflect the new parameter order. The `validateIndex` call now reads the index from slot 1 instead of slot 2, and the value is read from slot 2.
This commit is contained in:
Bob Nystrom
2015-03-16 16:18:59 +00:00
8 changed files with 24 additions and 24 deletions
+4 -4
View File
@@ -376,7 +376,7 @@ DEF_PRIMITIVE(class_supertype)
// Object has no superclass.
if (classObj->superclass == NULL) RETURN_NULL;
RETURN_OBJ(classObj->superclass);
}
@@ -690,11 +690,11 @@ DEF_PRIMITIVE(list_insert)
ObjList* list = AS_LIST(args[0]);
// count + 1 here so you can "insert" at the very end.
int index = validateIndex(vm, args, list->count + 1, 2, "Index");
int index = validateIndex(vm, args, list->count + 1, 1, "Index");
if (index == -1) return PRIM_ERROR;
wrenListInsert(vm, list, args[1], index);
RETURN_VAL(args[1]);
wrenListInsert(vm, list, args[2], index);
RETURN_VAL(args[2]);
}
DEF_PRIMITIVE(list_iterate)