Collection interfaces, comparison helpers, iteration utilities, and view slicing helpers.


Interfaces and conversions

Index exposes at and size; Iter exposes next and may expose size; View exposes iter, size, and slice, with at and index optional. next returns item valid; the item is meaningful only when valid is TRUE.

isDirtyOrDynamic

(object -- cond) Returns TRUE when either isDirty or isDynamic returns TRUE for object.
  • Reads through the input reference.
  • This is not a general unknown-value test: a stable Struct containing both known and unknown solid fields can return FALSE.

isIndex

(object -- cond) Tests whether the dereferenced schema has both at and size fields.
  • The result is a known schema-shape condition; it tests field presence, not current field values or method callability.

isIter

(object -- cond) Tests whether the dereferenced schema has a next field.
  • size is not required by this predicate.
  • The result is known and tests field presence, not method callability.

isView

(object -- cond) Tests whether the dereferenced schema has iter, size, and slice fields.
  • at and index are optional for this predicate.
  • The result is known and tests field presence, not method callability.

schemaNameBeginsWith

(object text -- cond) Tests whether object's SCHEMA_NAME field begins with text.
  • An absent field returns FALSE without processing text.
  • Otherwise, the field and prefix must be known, non-NIL Text. The field need not be static.

Known issue: with an unknown initial offset, makeTupleIter over a tuple of Ref items can return the wrong reference while valid is TRUE; keep the initial offset known for such tuples. With a stable unknown initial offset, tuples of Text or Code items are rejected at compile time; use a known initial offset for those as well.


Built-in source adaptation

Array adapters use a reference to contiguous item storage and a logical size. Tuple adapters use zero-based field ordinals. Text adapters expose UTF-8 code units as Nat8 items.

makeArrayIndex, makeArrayIter, makeArrayView, toTextIter, toTextView, makeTupleIndex, makeTupleIter and makeTupleView borrow their backing storage; keep it alive, at the same address, and large enough for the selected range while using the adapter or a reference derived from it.

Unknown bounds are checked at run time only when DEBUG is enabled; disabling DEBUG does not make out-of-bounds access valid. The size inputs of makeArrayIndex, makeArrayIter, makeArrayView, toTextIter and toTextView must be nonnegative; a negative input reports invalid size. The makeTupleIndex, makeTupleIter and makeTupleView size checks report size is out of bounds.

makeArrayIndex

(data size -- index) Constructs an Index over size contiguous items beginning at data.
  • at accepts a zero-based key and returns a reference to the selected item. Item references are mutable only through a mutable data reference and a mutable adapter access path.
  • size returns the requested logical size.
  • A key outside the range produces key is out of bounds.

Remarks

  • A known size is stored as a static field; a stable unknown size remains a run-time value. If the count is read from unstable storage, pass a snapshot made with new rather than the unstable reference.

makeArrayIter

(data size -- iter) Constructs a forward Iter over size contiguous items beginning at data.
  • Each successful next returns the current item as a reference and TRUE, then advances the stored data reference and decrements the remaining size. Item references are mutable only through a mutable data reference and a mutable adapter access path.
  • After the requested items are consumed, next returns an item whose value is not meaningful and FALSE.
  • size returns the remaining item count.

Remarks

  • A known size is carried as a known count; an unknown size is evaluated at run time.

makeArrayView

(data size -- view) Constructs a View over size contiguous items beginning at data.
  • at returns a reference; index and iter construct the corresponding array adapters over the same range. Item references are mutable only through a mutable data reference and a mutable adapter access path.
  • slice takes offset size and returns the selected subview without changing the original view.
  • An invalid key, offset, or subview size reports key is out of bounds, offset is out of bounds, or size is out of bounds, respectively.

toTextIter

((data size) -- iter) Constructs a forward iterator from one two-field Struct containing an item reference and a count.
  • Supply one Struct containing data followed by size. References retain data's item schema; an immutable data reference or access path does not become mutable.
  • For Text, toIter and toView supply an immutable Nat8 reference and a UTF-8 code-unit count.
  • Successful next returns the current item as a reference and TRUE; size returns the remaining count. After exhaustion, the item is not meaningful and FALSE is returned.

toTextView

((data size) -- view) Constructs a View from one two-field Struct containing an item reference and a count.
  • Supply one Struct containing data followed by size. References retain data's item schema; an immutable data reference or access path does not become mutable.
  • For Text, toIter and toView supply an immutable Nat8 reference and a UTF-8 code-unit count.
  • The view exposes iter, size, and slice; its iterator returns references whose mutability follows the data reference and access path.
  • Slicing reports offset is out of bounds or size is out of bounds when its arguments exceed the view.

Remarks

  • The size must be a stable value. If the count is read from unstable storage, pass a snapshot made with new rather than the unstable reference.

makeTupleIndex

(tuple offset size -- index) Constructs an Index over size fields beginning at tuple field offset.
  • at adds the key to the stored offset and reads that tuple field. A non-static In-place field produces a view whose mutability follows the access path; static and Ref-like fields follow the field-read rules.
  • The key must satisfy 0 <= key < size; otherwise the diagnostic is key is out of bounds.
  • size returns the requested field count. The offset and size ranges must remain within the tuple; invalid arguments report offset is out of bounds or size is out of bounds.

Remarks

  • The size must be a stable value. If the count is read from unstable storage, pass a snapshot made with new rather than the unstable reference.
  • The initial offset must be a stable value. Snapshot an offset read from unstable storage with new, subject to the tuple-schema restrictions.
  • Unknown field positions require uniform field schemas. Keep positions known when selecting heterogeneous fields.
  • A stable unknown initial offset is not supported for Text or Code fields.
  • Known issue: with an unknown initial offset, a tuple of Ref fields can select the wrong reference. Keep the initial offset known for such tuples.

makeTupleIter

(tuple offset size -- iter) Constructs a forward iterator over size tuple fields beginning at offset.
  • next visits selected fields in increasing ordinal order and returns item valid; the item is meaningful only while valid is TRUE.
  • Before exhaustion, size gives the remaining selected-field count.
  • The offset and size ranges must stay within the tuple; failures report offset is out of bounds or size is out of bounds.

Known issue: an unsuccessful next can advance beyond the selected range and make size negative; do not use size after FALSE.

Remarks

  • With a known offset, a non-static In-place field produces a view whose mutability follows the access path; static and Ref-like fields follow the field-read rules. Unknown field positions require uniform field schemas; keep positions known when selecting heterogeneous fields.
  • A stable unknown initial offset is not supported for Text or Code fields. Keep the initial offset known for those as well.
  • See the known-issue note above before using an unknown offset with tuple Ref, Text, or Code fields.

makeTupleView

(tuple offset size -- view) Constructs a view over size tuple fields beginning at offset.
  • at reads offset + key; a non-static In-place field produces a view whose mutability follows the access path, while static and Ref-like fields follow the field-read rules. index and iter adapt the same selected range.
  • The key must satisfy 0 <= key < size; otherwise the diagnostic is key is out of bounds.
  • slice returns a nested tuple view relative to the current view.
  • The offset and size ranges must stay within the tuple; invalid arguments report offset is out of bounds or size is out of bounds.

Remarks

  • The size must be a stable value. If the count is read from unstable storage, pass a snapshot made with new rather than the unstable reference.
  • The initial offset must be a stable value. Snapshot an offset read from unstable storage with new, subject to the tuple-schema restrictions.
  • Unknown field positions require uniform field schemas. Keep positions known when selecting heterogeneous fields.
  • A stable unknown initial offset is not supported for Text or Code fields.
  • Known issue: with an unknown initial offset, a tuple of Ref fields can select the wrong reference. Keep the initial offset known for such tuples.

toIndex

(source -- index) Converts a built-in tuple, an Index, or an object exposing index to an Index.
  • Built-in tuple adaptation takes precedence, followed by a direct Index, then the index method.
  • A built-in tuple becomes a zero-based tuple index. For a direct Index, new is used when there is no DIE field; otherwise the supplied object is used directly. An object with an index field uses that field.
  • Unsupported input raises the compile-time message Built-in tuple, Index, or Indexable expected.
  • Built-in tuple adaptation borrows the tuple's storage. Keep it alive, at the same address, and large enough for the selected range while using the adapter or its derived references. Do not assume that other conversion results are borrowed; follow the source type's ownership contract.

toIter

(source -- iter) Converts built-in text, built-in tuples, direct Iter values, or objects exposing iter to an Iter.
  • Text and built-in tuple adaptation take precedence, followed by a direct Iter, then the iter method.
  • Text is adapted as an immutable UTF-8 code-unit iterator; a built-in tuple becomes a tuple iterator.
  • For a direct Iter, an immutable view uses new when copyable, and a mutable view uses new when movable. Otherwise, the supplied iterator is used directly. An object with an iter field uses that field.
  • Unsupported input raises the compile-time message Built-in text, tuple, Iter, or Iterable expected.
  • Built-in Text and tuple adaptation borrows the backing storage. Keep it alive, at the same address, and large enough for the selected range while using the adapter or its derived references. Do not assume that other conversion results are borrowed; follow the source type's ownership contract.

toView

(source -- view) Converts built-in text, built-in tuples, or direct View values to a View.
  • Built-in text and tuple adaptation take precedence, followed by a direct View.
  • Text becomes an immutable UTF-8 code-unit view; a built-in tuple becomes a tuple view.
  • For a direct View, new is used when there is no DIE field; otherwise the supplied object is used directly. The view is accepted by its iter/size/slice shape; optional at and index are not required.
  • Unsupported input raises the compile-time message Built-in tuple or View expected.
  • Built-in Text and tuple adaptation borrows the backing storage. Keep it alive, at the same address, and large enough for the selected range while using the adapter or its derived references. Do not assume that other conversion results are borrowed; follow the source type's ownership contract.

makeObjectIter

(object method -- iter) Constructs an object-field iterator that applies method to the object and each field ordinal.
  • method is a callable stored as a static field, with stack effect (object ordinal -- item). It runs through a call boundary.
  • next increments from ordinal zero and returns TRUE while fields remain; at the end it returns () FALSE.
  • size returns the number of fields not yet visited.

objectFields

(object -- iter) Iterates over an object's fields as {key value} records.
  • Each record's key is the field name and value is the field-read result: a view for a non-static In-place field, a value for a static field, or a copied Ref-like value. A view's mutability follows the access path.
  • The iterator ends with () FALSE.

objectKeys

(object -- iter) Iterates over an object's field names in ordinal order.
  • Each successful item is the field-name text; the iterator ends with () FALSE and exposes remaining field count through size.

objectValues

(object -- iter) Iterates over an object's field values in ordinal order.
  • A non-static In-place field produces a view whose mutability follows the access path; a static field produces a value. Ref-like fields are copied according to the field-read rules.
  • The iterator ends with () FALSE and exposes remaining field count through size.

Matching and branching

<

(left right -- cond) Reports whether left is less than right, including lexicographic comparison of supported iteration sources.
  • The collection overload requires each operand to be Text or a Struct without less or greater fields. Both operands must also be accepted by toIter. A less or greater field on either operand excludes this overload, even if it is not applicable on that side.
  • The control adapters use right.less or left.greater.
  • The collection overload converts both operands with toIter and compares items in order; equal common prefixes make the shorter source less.
  • The result is a Cond; unsupported item comparisons remain subject to the selected comparison overload's requirements.
  • Known limitation: comparing Text with a built-in tuple can fail to compile even when their item schemas match. For byte storage, use an array iterator rather than the tuple adapter.

=

(left right -- cond) Reports whether two supported iteration sources contain equal items in equal-length order.
  • The collection overload requires at least one Struct operand and no equal field on either operand. Both operands must be accepted by toIter. Text-to-Text equality and objects with equal use other overloads.
  • The control adapters use right.equal or left.equal.
  • The collection overload converts both operands with toIter, compares corresponding items, and requires both sources to end together.
  • Different lengths or a differing item returns FALSE; an empty source equals an empty source.
  • Known limitation: comparing Text with a built-in tuple can fail to compile even when their item schemas match. For byte storage, use an array iterator rather than the tuple adapter.

>

(left right -- cond) Reports whether left is greater than right, including lexicographic comparison of supported iteration sources.
  • The collection overload requires each operand to be Text or a Struct without less or greater fields. Both operands must also be accepted by toIter. A less or greater field on either operand excludes this overload, even if it is not applicable on that side.
  • The control adapters use right.greater or left.less.
  • The collection overload converts both operands with toIter and compares items in order; equal common prefixes make the longer source greater.
  • The result is a Cond and follows the selected item-comparison overload's requirements.
  • Known limitation: comparing Text with a built-in tuple can fail to compile even when their item schemas match. For byte storage, use an array iterator rather than the tuple adapter.

case

(... value descriptors -- ...) Selects and runs the first branch whose descriptor equals value, or the final fallback branch.
  • descriptors is one Struct of alternating match values and actions, followed by one fallback action. Supply at least the fallback.
  • Matches are tested from the first pair forward.
  • The selected action runs through a call boundary without an automatically supplied argument. Its stack effect determines the selector's effect on the surrounding stack. Branches controlled by an unknown condition must leave matching stack shapes.
  • The fallback runs when no match is found. A descriptor Struct containing only its final branch therefore always runs that branch.

cond

(... value descriptors -- ...) Calls the first action whose predicate accepts value, or the final fallback action.
  • descriptors is one Struct of alternating predicates and actions, followed by one fallback action. Supply at least the fallback.
  • Each predicate runs through a call boundary, consumes value, and returns one Cond; the first true result selects its following action.
  • The selected action runs through a call boundary without an automatically supplied argument. Its stack effect determines the selector's effect on the surrounding stack. Branches controlled by an unknown condition must leave matching stack shapes.

cond0

(... descriptors -- ...) Selects and runs the first action whose no-argument predicate is true, or an optional fallback action.
  • descriptors is one Struct of alternating no-argument predicates and actions, optionally followed by a fallback action.
  • Predicates run through call boundaries and return one Cond; the first true result selects its following action.
  • The selected action runs through a call boundary without an automatically supplied argument. Its stack effect determines the selector's effect on the surrounding stack. Branches controlled by an unknown condition must leave matching stack shapes.
  • With no match and no fallback, the surrounding stack is unchanged. An empty Struct does nothing.

Search result conventions

The sequence search helpers convert their operands with toIter. Ordinals are zero-based, and an exhausted item returned with FALSE is not inspected.

beginsWith

(source prefix -- cond) Reports whether source starts with the complete prefix sequence.
  • An empty prefix returns TRUE; a nonempty prefix cannot match a shorter source.

contains

(source pattern -- cond) Reports whether pattern occurs as a contiguous subsequence of source.
  • An empty pattern returns TRUE; a pattern longer than the source returns FALSE.
  • The pattern source must support a fresh traversal for each attempted match. Look-ahead requires an independent copy of the remaining source iterator.
  • An operand without size must support a finite sizing traversal of an independent iterator copy.
  • Known limitation: searching a tuple containing unknown values for a multi-item built-in Tuple can fail to compile. Use array adapters over the storage for run-time subsequence searches.

endsWith

(source suffix -- cond) Reports whether source ends with the complete suffix sequence.
  • An empty suffix returns TRUE; a suffix longer than the source returns FALSE.
  • An operand without size must support a finite sizing traversal of an independent iterator copy.

find

(source pattern -- ordinal) Returns the first zero-based ordinal where pattern begins in source.
  • Matching is contiguous and leftmost; an empty pattern matches at ordinal 0.
  • If no match exists, the result is the source size, not -1.
  • The pattern source must support a fresh traversal for each attempted match. Look-ahead requires an independent copy of the remaining source iterator.
  • An operand without size must support a finite sizing traversal of an independent iterator copy.
  • Known limitation: searching a tuple containing unknown values for a multi-item built-in Tuple can fail to compile. Use array adapters over the storage for run-time subsequence searches.

findOneOf

(source patterns -- sourceOrdinal patternOrdinal) Finds the first source position whose remaining sequence begins with one of the candidate patterns.
  • patterns is an iteration of pattern sources; candidates are tested in pattern ordinal order at each source position.
  • The candidate collection must support a fresh traversal at each source position. Each candidate check requires an independent copy of the remaining source iterator.
  • An operand without size must support a finite sizing traversal of an independent iterator copy.
  • The result contains the first matching source ordinal followed by the matching pattern ordinal.
  • If no candidate matches, the result is the source size followed by -1.

Known issue: an empty source with a nonempty collection of nonempty patterns reaches Static loop count limit (256) reached instead of returning 0 -1; handle an empty source separately.

findOrdinal

(source predicate -- ordinal) Returns the first zero-based source ordinal whose predicate returns true.
  • The predicate is called through a call boundary for each item and must consume the item and return a Cond.
  • If no predicate match exists, the result is -1.

findOrdinalStatic

(iter predicate ordinal -- result) Recursively searches an Iter, starting at ordinal, for the first item satisfying predicate.
  • Supply the initial ordinal, normally 0, after the iterator and predicate; recursion increments it after a false predicate result.
  • The predicate runs through a call boundary, consumes one item, and returns one Cond. A true predicate returns the current ordinal; an exhausted iterator returns -1.

Remarks

  • Recursive processing must terminate during compilation. Item values, predicate results, and the final result need not be known.

Iteration helpers

Unknown bounds are checked at run time only when DEBUG is enabled; disabling DEBUG does not make out-of-bounds access valid.

Transformers return new iterator objects. Consumers exhaust a converted source or compute an aggregate. A body called through a call boundary receives the current item as a reference; the inline static consumer does not create that call boundary.

fibonacci

(previous current -- iter) Creates an unbounded iterator that yields the current value and advances the pair by Fibonacci addition.
  • The first next returns the supplied current; each later item is the next sum after the state advances to (current previous + current).
  • Each item is returned as a value copy followed by TRUE; this iterator has no size field.

iota

(start -- iter) Creates an unbounded iterator that yields successive values beginning at start.
  • Each next returns the current value, increments the internal counter by one, and returns TRUE.
  • Items are value copies and the iterator has no size field.

countIter

(source count -- iter) Wraps a source iterator and increments count after each successful item.
  • The wrapped source is converted with toIter; its items and valid flags are forwarded unchanged.
  • The supplied counter is incremented only when valid is TRUE, and a mutable counter reference is updated in place.
  • If the source has size, the wrapper exposes the same size.

enumerate

(source start -- iter) Wraps a source iterator and pairs each item with an increasing ordinal.
  • Each successful item is a Dict with key set to the current ordinal and value set to the source item; the ordinal starts at start and increments after each valid item.
  • The value field retains a source reference's mutability; a by-value In-place item becomes an In-place field.
  • If the source has size, the wrapper exposes the same size.

filter

(source predicate -- iter) Returns an iterator containing only source items accepted by predicate.
  • The predicate is called through a call boundary for each candidate and must consume the item and return a Cond.
  • Rejected items are skipped until an accepted item or source exhaustion; accepted references retain their mutability, and by-value items are returned by value.
  • The result does not expose a size field, because filtering changes the count.

headIter

(source size end -- iter) Creates an iterator over at most size source items.
  • A converted source with size is capped at its remaining count. Otherwise, the wrapper counts successful items. A negative size reports invalid size.
  • While items remain, next forwards source items and valid flags. At the limit, it supplies the end item with FALSE.
  • If an unsized source ends before the limit, its invalid result is forwarded without using end.
  • A non-callable end is read as the end item; a callable end has stack effect (-- item). It is read or called on each invalid result supplied by the wrapper, not as a one-shot notification.
  • When validity is unknown, successful and end items must have matching schemas, including Ref versus In-place.
  • The result exposes size only when the converted source does.

joinIter

(sources transform end -- iter) Zips the source iterators, unpacks each tuple of aligned items into transform, and returns the transformed results.
  • sources is converted by wrapIter. transform runs through a call boundary, consumes one item per source in source order with the last source's item on top, and returns one item.
  • Advancement follows wrapIter; the transform runs only for a valid tuple of items. The end provider supplies each invalid result.
  • A non-callable end is read as the end item; a callable end has stack effect (-- item). Using end is not a one-shot notification: it is read or called on each invalid result.
  • When validity is unknown, successful and end items must have matching schemas, including Ref versus In-place.
  • When every source exposes size, the result size is the minimum source size.

map

(source transform end -- iter) Applies transform to each source item and returns the transformed iterator.
  • The source is converted with toIter; transform is called through a call boundary with the current item, consumes that item, and returns one mapped item. Source references retain their mutability.
  • When the source produces an invalid result, end supplies the item returned with FALSE. A non-callable end is read as the end item; a callable end has stack effect (-- item). It is read or called on each invalid result, not as a one-shot notification.
  • When validity is unknown, successful and end items must have matching schemas, including Ref versus In-place.
  • If the source exposes at, the result exposes at and applies transform to selected items; if the source exposes size, the result forwards that size.

wrapIter

(sources -- iter) Creates a zip iterator over the iterators contained in sources.
  • Each source is converted with toIter; a successful next returns a tuple containing one item from every source and TRUE.
  • Each next advances every source. The result is valid only when every source returns TRUE; the tuple returned with a false flag is not meaningful. Longer sources also advance on an invalid call, including calls made after the first FALSE.
  • When all sources expose size, size returns the minimum; an empty source collection has size 0.

unhead

(source size -- result) Removes a leading prefix from a source accepted as a View or direct Iter.
  • If source is accepted by toView, removes the prefix by slicing, even when source also has next. This view conversion has precedence and includes built-in Text and tuple sources.
  • Otherwise, source must be a direct Iter; it consumes up to size items and returns the remaining iterator. Convert other Iterable objects with toIter first.
  • For an Iter, a negative size reports invalid size; consumption stops when the source returns FALSE. For a View, the size must be within the view and an invalid prefix reports size is out of bounds.

all

(source predicate -- cond) Reports whether every source item satisfies predicate.
  • The source is converted with toIter; the predicate is called through a call boundary and must consume each item and return a Cond.
  • Evaluation stops at the first false predicate; an empty source returns TRUE.

allStatic

(iter predicate -- cond) Recursively tests whether every item from an Iter satisfies predicate.
  • Unlike all, this entry expects an Iter; use source toIter before it.
  • The predicate runs through a call boundary, consumes one item, and returns one Cond. Evaluation stops at the first false result; an exhausted iterator returns TRUE.

Remarks

  • Recursive processing must terminate during compilation. Item values, predicate results, and the final result need not be known.

any

(source predicate -- cond) Reports whether at least one source item satisfies predicate.
  • The source is converted with toIter; the predicate runs through a call boundary, consumes one item, and returns one Cond. Evaluation stops at the first true result.
  • An empty source or a source with no true predicate returns FALSE.

anyStatic

(iter predicate -- cond) Recursively tests whether any item from an Iter satisfies predicate.
  • Unlike any, this entry expects an Iter; use source toIter before it.
  • The predicate runs through a call boundary, consumes one item, and returns one Cond. It stops at the first true result and returns FALSE only after exhaustion without a match.

Remarks

  • Recursive processing must terminate during compilation. Item values, predicate results, and the final result need not be known.

count

(source -- count) Returns the number of items available from a source.
  • Converts source with toIter. If the result has size, returns that method's result without advancing next, preserving its result schema.
  • Otherwise, consumes next until FALSE and returns an Int32 count.

each

(... source body -- ...) Calls body with each source item and consumes the source.
  • The source is converted with toIter; body runs through a call boundary and must consume its item. The body may transform the surrounding stack; run-time traversal requires the same carried stack shape after the item is consumed. Known traversal may change that shape.
  • For non-static In-place tuple fields, the body receives a view whose mutability follows the tuple access path.

eachStatic

(source body --) Processes body inline once for each item from the converted source.
  • Source traversal is resolved during compilation; item values may be known or unknown.
  • The body is processed inline inside eachStatic's call boundary, not in its caller's scope. Its locals do not escape to the caller.
  • For non-static In-place tuple fields, the inline body receives a view whose mutability follows the tuple access path and must leave the iterator recursion's carried stack shape intact.

eachStaticInternal

(iter body --) Processes an already converted iterator with a body inline until exhaustion; this is the low-level form that eachStatic delegates to.
  • Unlike eachStatic, it expects an Iter and does not call toIter; eachStatic converts its source before delegating.
  • Traversal is resolved during compilation; item values may be known or unknown.
  • The body runs once for each valid item, must consume that item, and must preserve the recursion's carried stack shape; exhaustion returns no items.

interleave

(... source consume splice -- ...) Calls consume with each item and calls splice before each item after the first.
  • The source is converted with toIter. An empty source calls neither body.
  • consume runs through a call boundary on each item. splice also runs through a call boundary and must leave its item available to the following consume call.
  • The callbacks may transform the surrounding stack; run-time traversal requires the combined step to preserve its carried stack shape.

meetsAll

(object predicates -- cond) Reports whether every predicate in predicates accepts one object.
  • predicates is converted with toIter; each predicate runs through a call boundary, consumes the supplied object, and returns one Cond.
  • Evaluation stops at the first false predicate. An empty predicate source returns TRUE.

meetsAny

(object predicates -- cond) Reports whether at least one predicate in predicates accepts one object.
  • predicates is converted with toIter; each predicate runs through a call boundary, consumes the supplied object, and returns one Cond.
  • Evaluation stops at the first true predicate. An empty predicate source returns FALSE.

mutate

(source transform --) Replaces every mutable source item with the result of transform.
  • The source is converted with toIter; each successful item is duplicated, passed to transform through a call boundary, and replaced with the transform result through set.
  • transform consumes one item and returns one replacement.
  • A tuple (1 2 3) transformed by [item:; item 1 +] becomes (2 3 4).

View slicing

Unknown bounds are checked at run time only when DEBUG is enabled; disabling DEBUG does not make out-of-bounds access valid.

Each slicer first converts its source with toView. Offsets are zero-based; a size of zero is valid.

slice

(view offset size -- result) Returns a subview beginning at offset with size logical units.
  • offset must be in 0..view.size and size must be in 0..view.size-offset.
  • Invalid arguments report offset is out of bounds or size is out of bounds; the result is produced by the source view's slice method.

range

(view offset0 offset1 -- result) Returns the subview from offset0 through the exclusive endpoint offset1.
  • offset0 must be nonnegative and offset1 must lie in offset0..view.size.
  • The result has offset offset0 and size offset1 - offset0; failures report offset0 is out of bounds or offset1 is out of bounds.

head

(view size -- result) Returns the leading subview of size units.
  • The result is equivalent to 0 size view.slice.
  • size must be in 0..view.size; otherwise the failure is size is out of bounds.

tail

(view size -- result) Returns the trailing subview of size units.
  • The result starts at view.size - size and has size size.
  • size must be in 0..view.size; otherwise the failure is size is out of bounds.

untail

(view size -- result) Returns the view with a trailing suffix of size units removed.
  • The result is equivalent to 0 view.size size - view.slice.
  • size must be in 0..view.size; otherwise the failure is size is out of bounds.

Examples

Counting and searching

"algorithm" use
"control"   use

{} () {} [
  (10 20 30 40) count printStack _:;
  (10 20 30 40) (20 30) contains printStack _:;
  (10 20 30 40) [30 =] findOrdinal printStack _:;
] "main" exportFunction

Expected Output During Compilation

4
TRUE
2

View slicing

"algorithm" use
"control"   use

{} () {} [
  view: "hello" toView;
  view.size printStack _:;
  1 3 @view.slice.size printStack _:;
] "main" exportFunction

Expected Output During Compilation

5
3

Runtime example

"String"    use
"algorithm" use
"control"   use

{} Int32 {} [
  ("count=" (10 20 30 40) count LF
    "contains=" (10 20 30 40) (20 30) contains LF
    "find=" (10 20 30 40) [30 =] findOrdinal LF) printList
  0
] "main" exportFunction

Expected Output

count=4
contains=TRUE
find=2

See also