|
|
@@ -128,6 +128,19 @@ func list_remove(l, x, first=false) {
|
|
|
}
|
|
|
}
|
|
|
set_pseudomethod("list.remove", list_remove)
|
|
|
+func list_index(l, x, many=false) {
|
|
|
+ if type(l) != "list"
|
|
|
+ throw TypeError("expected first argument to be: list, but got: " + type(l))
|
|
|
+
|
|
|
+ var r = []
|
|
|
+ for var i = 0; i < len(l); i++
|
|
|
+ if l[i] == x
|
|
|
+ list_push(r, i)
|
|
|
+
|
|
|
+ return many? r: r? r[0]: -1
|
|
|
+}
|
|
|
+set_pseudomethod("list.index", list_index)
|
|
|
+set_pseudomethod("tuple.index", func (t, x): list_index(list(t), x))
|
|
|
func list_join(l) {
|
|
|
if type(l) != "list"
|
|
|
throw TypeError("expected first argumient to be: list, but got: " + type(l))
|
|
|
@@ -201,6 +214,7 @@ set_pseudomethod("list.shift", list_shift)
|
|
|
set_pseudomethod("list.unshift", list_unshift)
|
|
|
set_pseudomethod("list.insert", list_insert)
|
|
|
set_pseudomethod("list.delete", list_delete)
|
|
|
+set_pseudomethod("list.__sub", func (l, e): list_delete(list_copy(l), e))
|
|
|
func slice(l) {
|
|
|
if type(l) !in ("list", "string", "bytes", "ustr")
|
|
|
throw TypeError("expected first argument to be: list, string, bytes or ustr, but got: " + type(l))
|
|
|
@@ -396,6 +410,19 @@ set_pseudomethod("list.filter", func (xs, f): filter(f, xs))
|
|
|
set_pseudomethod("tuple.filter", func (xs, f): filter(f, xs))
|
|
|
set_pseudomethod("string.filter", func (xs, f): filter(f, xs))
|
|
|
set_pseudomethod("bytes.filter", func (xs, f): filter(f, xs))
|
|
|
+func tuple_delete(t, x) {
|
|
|
+ if type(t) != "tuple"
|
|
|
+ throw TypeError("expected first argument to be: tuple, but got: " + type(t))
|
|
|
+
|
|
|
+ var r = []
|
|
|
+ for var e of t
|
|
|
+ if e != x
|
|
|
+ list_push(r, e)
|
|
|
+
|
|
|
+ return tuple(r)
|
|
|
+}
|
|
|
+set_pseudomethod("tuple.delete", tuple_delete)
|
|
|
+set_pseudomethod("tuple.__sub", tuple_delete)
|
|
|
func str_index(s, w) {
|
|
|
if s == "" || w == ""
|
|
|
return -1
|