collections: ConsStack, a persistent stack with shared tails (C7) #198
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
ConsStack<Item>: an implementation ofStackas a persistent cons list, so that a copy (var rest = stack) shares its tail andpush/popare O(1) with no copy (COLLECTIONS.md section 3.3 table, section 3.10 point 4). The tour (section 6, question 6) shows it doing what aListcannot.Acceptance criteria
public type ConsStack<Item> with Stack<Item>, From<Iterate<Item>>;push,pop,peek,length,iterate(top first),clear,Equals/HashasArrayStack.ConsStack.of(...)/ literal throughFromas forArrayStack.ArrayStackfor keeping many versions.Seed impact
None. A new public type in
std/collectionswritten in plain TorbScript over aList; no syntax change, no new native, no runtime change (runtime/list.cstays the one storage, COLLECTIONS.md section 3.10 point 5), and the compiler looks up none of the new names by string (section 6a). Not breaking: only additions.Size
One PR, one
feat(collections)commit (plus tests and docs in the same commit or a secondtest/docsone).Common to the C7 types
std/collections/src/lib.trb(public use ...), doc comments with the cost profile of the implementation, asArrayQueuehas.tests/conformance/(.trb+.expected), run natively and in the VM, in the style ofqueue-grows.trb.benchmarks/(one small program plus its C counterpart, seebenchmarks/README.md) against the array implementation. It is a measurement, not a gate.skills/regenerated when docs change; the worker does not run gates locally, CI does.Source
RingList,ConsStack,BankersQueue,Heap(C7) #139RingList,ConsStack,BankersQueue,Heap(C7) #139[loop:torbscript] claim implement by session:loop-torbscript-20261008 until 2026-10-08T20:05:00Z
[loop:torbscript] implement: PR #202 open, CI green, next: review
==on two concrete stack values fails to compile #209