spec: vector primitive — complete type signatures in spec/primitives.sx
All 10 vector primitives now have :as type annotations on every parameter, :returns types, and :doc strings. make-vector gains optional fill annotation; vector uses :rest for its variadic args; vector-ref/set! document bounds error. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -54,7 +54,9 @@ Steps:
|
||||
primitives in `hosts/ocaml/sx_primitives.ml` (or equivalent); wire into evaluator.
|
||||
Note: Vector type + most prims were already present; added bounds-checked vector-ref/set!
|
||||
and optional start/end to vector-copy. 10/10 vector tests pass (r7rs suite).
|
||||
- [ ] Spec: add vector entries to `spec/primitives.sx` with type signatures and descriptions.
|
||||
- [x] Spec: add vector entries to `spec/primitives.sx` with type signatures and descriptions.
|
||||
All 10 vector primitives now have :as type annotations, :returns, and :doc strings.
|
||||
make-vector: optional fill param; vector-copy: optional start/end (done prev step).
|
||||
- [ ] JS bootstrapper: implement vectors in `hosts/javascript/platform.js` (or equivalent);
|
||||
ensure `sx-browser.js` rebuild picks them up.
|
||||
- [ ] Tests: 40+ tests in `spec/tests/test-vectors.sx` covering construction, ref, set!,
|
||||
@@ -196,5 +198,6 @@ Brief each language's loop agent (or do inline) after rebasing their branch onto
|
||||
|
||||
_Newest first._
|
||||
|
||||
- 2026-04-25: Phase 1 spec step done — all 10 vector primitives in spec/primitives.sx have full :as type annotations, :returns, :doc; make-vector optional fill param added.
|
||||
- 2026-04-25: Phase 1 OCaml step done — bounds-checked vector-ref/set!, vector-copy now accepts optional start/end, spec/primitives.sx doc updated. 10/10 r7rs vector tests pass, 4747 total (394 pre-existing hs-upstream fails unchanged).
|
||||
- 2026-04-25: Phase 0 complete — stopped CL/APL/Ruby/Tcl loops (all 4 idle at shell); confirmed E38 (tokenizer :end/:line) and E39 (WebWorker stub) both have implementation commits.
|
||||
|
||||
@@ -170,15 +170,15 @@
|
||||
|
||||
(define-primitive
|
||||
"make-vector"
|
||||
:params ((n :as number))
|
||||
:params ((n :as number) (fill :as any :optional true))
|
||||
:returns "vector"
|
||||
:doc "Create vector of size n, optionally filled.")
|
||||
:doc "Create vector of length n, each element initialised to fill (default nil).")
|
||||
|
||||
(define-primitive
|
||||
"vector"
|
||||
:params ()
|
||||
:params (:rest (elts :as any))
|
||||
:returns "vector"
|
||||
:doc "Create vector from arguments.")
|
||||
:doc "Construct a vector from its arguments.")
|
||||
|
||||
(define-primitive
|
||||
"vector?"
|
||||
@@ -190,31 +190,31 @@
|
||||
"vector-length"
|
||||
:params ((v :as vector))
|
||||
:returns "number"
|
||||
:doc "Number of elements.")
|
||||
:doc "Number of elements in vector v.")
|
||||
|
||||
(define-primitive
|
||||
"vector-ref"
|
||||
:params ((v :as vector) (i :as number))
|
||||
:returns "any"
|
||||
:doc "Element at index.")
|
||||
:doc "Element at 0-based index i. Error if out of bounds.")
|
||||
|
||||
(define-primitive
|
||||
"vector-set!"
|
||||
:params ((v :as vector) (i :as number) (val :as any))
|
||||
:returns "nil"
|
||||
:doc "Set element at index.")
|
||||
:doc "Mutate element at index i to val. Error if out of bounds.")
|
||||
|
||||
(define-primitive
|
||||
"vector->list"
|
||||
:params ((v :as vector))
|
||||
:returns "list"
|
||||
:doc "Convert vector to list.")
|
||||
:doc "Convert vector to a fresh list.")
|
||||
|
||||
(define-primitive
|
||||
"list->vector"
|
||||
:params ((l :as list))
|
||||
:returns "vector"
|
||||
:doc "Convert list to vector.")
|
||||
:doc "Convert list to a fresh vector.")
|
||||
|
||||
;; --------------------------------------------------------------------------
|
||||
;; Core — Predicates
|
||||
@@ -223,7 +223,7 @@
|
||||
"vector-fill!"
|
||||
:params ((v :as vector) (val :as any))
|
||||
:returns "nil"
|
||||
:doc "Fill all elements.")
|
||||
:doc "Set every element of v to val in place.")
|
||||
|
||||
(define-primitive
|
||||
"vector-copy"
|
||||
|
||||
Reference in New Issue
Block a user