Reverse the argument order of List.insert
The previous order, insert(element, index), was counter-intuitive. I'm not aware of any list API that uses this order. I've checked: * Ruby Array.insert(index, obj...) * JavaScript array.splice(start, deleteCount[, item1[, item2[, ...]]]) * C++ / QList::insert(int i, const T & value) * C++ / std::vector::insert * Lua table.insert (list, [pos,] value) * C# List<T>.Insert(int index, T item) * Java Interface List<E>.add(int index, E element) * Python list.insert(i, x) So it seemed to me more like an oversight in Wren.
This commit is contained in:
+4
-4
@@ -380,7 +380,7 @@ DEF_PRIMITIVE(class_supertype)
|
||||
|
||||
// Object has no superclass.
|
||||
if (classObj->superclass == NULL) RETURN_NULL;
|
||||
|
||||
|
||||
RETURN_OBJ(classObj->superclass);
|
||||
}
|
||||
|
||||
@@ -694,11 +694,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)
|
||||
|
||||
Reference in New Issue
Block a user