Skip to content

Add method-call sugar for collection builtins (xs.len() style) #34

@synapticvoid

Description

@synapticvoid

Summary

Support method-call syntax as sugar over existing collection builtins.

Proposal

  • xs.len() desugars to len(xs)
  • xs.contains(v) desugars to contains(xs, v)
  • xs.get(i) desugars to get(xs, i)
  • xs.add(v) desugars to add(xs, v)
  • xs.remove(i) desugars to remove(xs, i)

Rules

  • Sugar only: behavior and types must match the builtin forms exactly
  • Mutability checks are unchanged (e.g. add/remove require mutable receiver)
  • No user-defined extension methods in this issue

Scope (Minimal)

  • Parser: keep existing obj.method(args) shape
  • Type checker: resolve supported collection methods to builtin signatures
  • Interpreter: dispatch method calls to builtin implementations

Acceptance Criteria

  • const n = [1,2,3].len(); behaves like len([1,2,3]);
  • var xs = [1,2]; xs.add(3); behaves like add(xs, 3);
  • const xs = [1,2]; xs.add(3); fails with mutability error
  • Unknown methods (e.g. xs.foo()) fail with type error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions