Add index-of string primitive: spec, Python, JS, rebootstrap
(index-of s needle from?) returns first index of needle in s, or -1. Optional start offset. Specced in primitives.sx, implemented in both hand-written primitives.py and bootstrapper templates, rebootstrapped. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -299,6 +299,10 @@ def prim_slice(coll: Any, start: int, end: Any = None) -> Any:
|
||||
return coll[start:]
|
||||
return coll[start:int(end)]
|
||||
|
||||
@register_primitive("index-of")
|
||||
def prim_index_of(s: str, needle: str, start: int = 0) -> int:
|
||||
return str(s).find(needle, int(start))
|
||||
|
||||
@register_primitive("starts-with?")
|
||||
def prim_starts_with(s, prefix: str) -> bool:
|
||||
if not isinstance(s, str):
|
||||
|
||||
Reference in New Issue
Block a user