Skip to content

Value-based list search: list_index_of / list_contains builtins (structural equality, C-backed) #543

Description

@InauguralPhysicist

Summary

There is no C-backed way to find a value in a list. The two near-misses are deliberate non-solutions:

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.

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 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.

Definition of done (mirroring #193's shape)

  1. Builtins in src/builtins.c reusing the VM's structural comparison; -1/0 on 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).
  2. Assertions covering: hit at 0 / middle / end, miss, empty list, structural hit on nested list/dict elements, number vs string never equal.
  3. Rows in docs/BUILTINS.md → Lists.

Environment

  • EigenScript 0.29.0, HEAD 82ab2ae.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions