You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
find_index of [list, fn] (lib/list.eigs, Add find_index to lib/list.eigs #193) covers the predicate case, but costs one closure call per element through the interpreter, and writing (fn x: x == needle) for plain membership is ceremony.
Structural equality already exists in the language core ([1,2] == [1,2] is true, dicts compare structurally, match relies on it) — this proposal is just exposing that existing comparison over a list scan.
The DAW port keeps Python-set-like collections as lists with structural dedup: selected clip refs are [track_index, lane_index, clip_index] lists, selected note indices are numbers. Every select/deselect/delete/move operation does membership tests and value removal. We hand-rolled the three obvious helpers in src/core/util.eigs (ds_list_contains, ds_list_index_of, ds_list_remove_value) as interpreter-speed loops; every consumer project porting code from a language with list.index / in / remove will re-write the same three.
What to add
list_index_of of [[10, [1,2], 30], [1,2]] # 1 (structural equality)
list_index_of of [[10, 20], 99] # -1
list_contains of [[10, 20], 20] # 1
Open to this living in lib/list.eigs instead if a C builtin is unwanted — but the C version gets the same value_equals the VM already uses for ==, for free, and stays fast on selection-sized lists inside render loops.
list_remove_value of [list, v] (remove first structural match, mutating, return 1/0) would complete the trio; happy to split it out if scope should stay minimal.
Summary
There is no C-backed way to find a value in a list. The two near-misses are deliberate non-solutions:
index_of/containsare string-only, and correctly return-1/0for list operands since String predicates (index_of,contains,starts_with,ends_with) silently coerce non-string args to "" and report spurious matches #316 — so they can't be extended without breaking that fixed contract.find_index of [list, fn](lib/list.eigs, Addfind_indexto lib/list.eigs #193) covers the predicate case, but costs one closure call per element through the interpreter, and writing(fn x: x == needle)for plain membership is ceremony.Structural equality already exists in the language core (
[1,2] == [1,2]is true, dicts compare structurally,matchrelies on it) — this proposal is just exposing that existing comparison over a list scan.Motivation (consumer: InauguralSystems/DeslanStudios)
The DAW port keeps Python-
set-like collections as lists with structural dedup: selected clip refs are[track_index, lane_index, clip_index]lists, selected note indices are numbers. Every select/deselect/delete/move operation does membership tests and value removal. We hand-rolled the three obvious helpers insrc/core/util.eigs(ds_list_contains,ds_list_index_of,ds_list_remove_value) as interpreter-speed loops; every consumer project porting code from a language withlist.index/in/removewill re-write the same three.What to add
Open to this living in lib/list.eigs instead if a C builtin is unwanted — but the C version gets the same
value_equalsthe VM already uses for==, for free, and stays fast on selection-sized lists inside render loops.list_remove_value of [list, v](remove first structural match, mutating, return 1/0) would complete the trio; happy to split it out if scope should stay minimal.Definition of done (mirroring #193's shape)
src/builtins.creusing the VM's structural comparison;-1/0on no match; non-list first arg raises (no silent coercion, per the String predicates (index_of,contains,starts_with,ends_with) silently coerce non-string args to "" and report spurious matches #316 lesson).Environment
82ab2ae.