containers
本頁內容尚未翻譯。
python.Ordering
Section titled “python.Ordering”data OrderingHow values compare without the heap: an order (-1, 0 or 1), unordered (a NaN takes part: every comparison is
false), or incomparable (< raises TypeError).
python.Value.equal
Section titled “python.Value.equal”def Value.equal (a : Value) (b : Value) : BoolWhether the values a and b are equal without looking at the heap: numbers by value, str by code points, tuples
item by item, objects on the heap by address.
python.Value.equalOther
Section titled “python.Value.equalOther”def Value.equalOther (a : Value) (b : Value) : BoolWhether a, a value that is not a number, equals b.
python.Value.equalAll
Section titled “python.Value.equalAll”def Value.equalAll (xs : List Value) (ys : List Value) : BoolWhether the lists of values xs and ys are equal item by item.
python.Value.compareCodes
Section titled “python.Value.compareCodes”def Value.compareCodes (xs : Codes) (ys : Codes) : IntComparing the code points xs with ys: -1, 0 or 1.
python.Value.order
Section titled “python.Value.order”def Value.order (a : Value) (b : Value) : OrderingHow the values a and b compare without the heap.
python.Value.orderOther
Section titled “python.Value.orderOther”def Value.orderOther (a : Value) (b : Value) : OrderingHow a, a value that is not a number, compares with b: str by code points, tuples by their first unequal
items.
python.Value.orderAll
Section titled “python.Value.orderAll”def Value.orderAll (xs : List Value) (ys : List Value) : OrderingHow the lists xs and ys compare: by the first items that are not equal, else by length.
python.Changed
Section titled “python.Changed”data ChangedWhat changing the heap gives: the new heap and the outcome.
python.Changed.same
Section titled “python.Changed.same”def Changed.same (h : Heap) (o : Outcome) : ChangedThe heap h unchanged, with the outcome o.
python.Changed.value
Section titled “python.Changed.value”def Changed.value (h : Heap) (v : Value) : ChangedThe heap h with the value v produced.
python.Heap.allocate
Section titled “python.Heap.allocate”def Heap.allocate (h : Heap) (o : Object) : ChangedThe new object o on the heap h: the heap with it, and a reference to it.
python.Heap.store
Section titled “python.Heap.store”def Heap.store (h : Heap) (a : Nat) (o : Object) : HeapThe heap h with the object at the address a replaced by o.
python.Heap.list
Section titled “python.Heap.list”def Heap.list (h : Heap) (xs : List Value) : ChangedA new list of the values xs on the heap h.
python.Attributes.find
Section titled “python.Attributes.find”def Attributes.find (attributes : List (Codes * Value)) (name : Codes) : Option ValueThe attribute of a name among attributes in order.
python.Class.order
Section titled “python.Class.order”def Class.order (h : Heap) (c : Value) : List ValueThe class value c’s method resolution order (itself first) on the heap h: empty for a built-in class.
python.Class.attributes
Section titled “python.Class.attributes”def Class.attributes (h : Heap) (c : Value) : List (Codes * Value)The class value c’s own attributes on the heap h.
python.Class.hashable
Section titled “python.Class.hashable”def Class.hashable (h : Heap) (order : List Value) : BoolWhether instances of the classes in the method resolution order on the heap h are hashable: the first class
defining __hash__ or __eq__ decides (only __eq__ makes them unhashable).
python.Value.hashable
Section titled “python.Value.hashable”def Value.hashable (h : Heap) (v : Value) : BoolWhether the value v on the heap h can be a dict key or a set item.
python.Value.hashableAll
Section titled “python.Value.hashableAll”def Value.hashableAll (h : Heap) (vs : List Value) : BoolWhether every value of vs on the heap h can be a dict key.
python.Containers.unhashableKey
Section titled “python.Containers.unhashableKey”def Containers.unhashableKey (h : Heap) (v : Value) : OutcomeTypeError for v as an unhashable dict key, its type name read from the heap h (CPython 3.14’s words).
python.Containers.unhashableItem
Section titled “python.Containers.unhashableItem”def Containers.unhashableItem (h : Heap) (v : Value) : OutcomeTypeError for v as an unhashable set item, its type name read from the heap h (CPython 3.14’s words).
python.Dict.get
Section titled “python.Dict.get”def Dict.get (pairs : List (Value * Value)) (k : Value) : Option ValueThe value for the key k in the dict’s pairs.
python.Dict.set
Section titled “python.Dict.set”def Dict.set (pairs : List (Value * Value)) (k : Value) (v : Value) : List (Value * Value)The dict’s pairs with the key k set to v: an existing key keeps its key and place, a new one goes last.
python.Dict.remove
Section titled “python.Dict.remove”def Dict.remove (pairs : List (Value * Value)) (k : Value) : List (Value * Value)The dict’s pairs without the key k.
python.Dict.ofPairs
Section titled “python.Dict.ofPairs”def Dict.ofPairs (pairs : List (Value * Value)) : List (Value * Value)A dict from pairs in order (a later pair’s value wins).
python.Dict.keys
Section titled “python.Dict.keys”def Dict.keys (pairs : List (Value * Value)) : List ValueThe keys of the dict’s pairs.
python.Dict.values
Section titled “python.Dict.values”def Dict.values (pairs : List (Value * Value)) : List ValueThe values of the dict’s pairs.
python.Dict.items
Section titled “python.Dict.items”def Dict.items (pairs : List (Value * Value)) : List ValueThe dict’s pairs as tuples.
python.Set.has
Section titled “python.Set.has”def Set.has (x : Value) (xs : List Value) : BoolWhether the value x is among the values xs (by ==, without the heap).
python.Set.remove
Section titled “python.Set.remove”def Set.remove (x : Value) (xs : List Value) : List ValueThe set’s items xs without the item x.
python.Heap.dict
Section titled “python.Heap.dict”def Heap.dict (h : Heap) (pairs : List (Value * Value)) : ChangedA new dict from pairs on the heap h.
python.Index.within
Section titled “python.Index.within”def Index.within (i : Int) (size : Nat) : Option NatThe index i, counted from the end when negative, if it is within the length size.
python.Index.wrongType
Section titled “python.Index.wrongType”def Index.wrongType (h : Heap) (what : String) (i : Value) : OutcomeTypeError for the index i that is not an int, into the sequence named what (its type name read from the heap
h).
python.Index.notSubscriptable
Section titled “python.Index.notSubscriptable”def Index.notSubscriptable (h : Heap) (c : Value) : OutcomeTypeError for the value c that cannot be indexed, its type name read from the heap h.
python.Index.item
Section titled “python.Index.item”def Index.item (h : Heap) (what : String) (items : List Value) (i : Value) : OutcomeThe item of items at the index i on the heap h, or IndexError (what: the sequence’s name in the
message).
python.Containers.listValues
Section titled “python.Containers.listValues”def Containers.listValues (xs : Array Value) : List ValueThe list’s items xs (every place in a list holds a value).
python.Index.objectItem
Section titled “python.Index.objectItem”def Index.objectItem (h : Heap) (c : Value) (o : Object) (i : Value) : Outcomec[i] of the object o that c refers to on the heap h.
python.Index.get
Section titled “python.Index.get”def Index.get (h : Heap) (c : Value) (i : Value) : Outcomec[i] on the heap h.
python.Index.notAssignable
Section titled “python.Index.notAssignable”def Index.notAssignable (h : Heap) (c : Value) : OutcomeTypeError for the value c whose items cannot be assigned, its type name read from the heap h.
python.Index.setObject
Section titled “python.Index.setObject”def Index.setObject (h : Heap) (c : Value) (a : Nat) (o : Object) (i : Value) (v : Value) : Changedc[i] = v on the object o that c refers to at the address a on the heap h.
python.Index.set
Section titled “python.Index.set”def Index.set (h : Heap) (c : Value) (i : Value) (v : Value) : Changedc[i] = v on the heap h.
python.Index.notDeletable
Section titled “python.Index.notDeletable”def Index.notDeletable (h : Heap) (c : Value) : OutcomeTypeError for the value c whose items cannot be deleted, its type name read from the heap h (a tuple’s and a
str’s message says “doesn’t”, as CPython’s do).
python.Index.deleteObject
Section titled “python.Index.deleteObject”def Index.deleteObject (h : Heap) (c : Value) (a : Nat) (o : Object) (i : Value) : Changeddel c[i] on the object o that c refers to at the address a on the heap h: a list’s item at an index
(counted from the end when negative), a dict’s key (KeyError when it is not there).
python.Index.delete
Section titled “python.Index.delete”def Index.delete (h : Heap) (c : Value) (i : Value) : Changeddel c[i] on the heap h.
python.Slice.bound
Section titled “python.Slice.bound”def Slice.bound (size : Nat) (up : Bool) (v : Value) (absent : Int) : IntThe slice bound v clamped to a sequence of size items as CPython’s PySlice_AdjustIndices does (counted from
the end when negative; up is whether the step is positive); None is the bound’s default absent.
python.Slice.indexesWithin
Section titled “python.Slice.indexesWithin”def Slice.indexesWithin (fuel : Nat) (i : Int) (stop : Int) (step : Int) (up : Bool) : List NatThe indexes from i toward stop by step (going up when up), within fuel indexes.
python.Slice.indexes
Section titled “python.Slice.indexes”def Slice.indexes (size : Nat) (start : Value) (stop : Value) (step : Int) : List NatThe indexes the slice from start to stop by step takes from a sequence of size items.
python.Slice.pick
Section titled “python.Slice.pick”def Slice.pick {A : Type} (xs : List A) (indexes : List Nat) : List AThe items of xs at the indexes.
python.Slice.get
Section titled “python.Slice.get”def Slice.get (h : Heap) (c : Value) (start : Value) (stop : Value) (step : Value) : Changedc[start:stop:step] on the heap h (None bounds and step take their defaults).
python.Containers.noLength
Section titled “python.Containers.noLength”def Containers.noLength (h : Heap) (v : Value) : OutcomeTypeError for the value v without a length, its type name read from the heap h.
python.Object.size
Section titled “python.Object.size”def Object.size (h : Heap) (o : Object) : Option NatThe number of items in the object o on the heap h, if it has a length.
python.Containers.size
Section titled “python.Containers.size”def Containers.size (h : Heap) (v : Value) : Outcomelen(v) on the heap h.
python.Items
Section titled “python.Items”data ItemsWhat iterating gives: the values in order, or an exception.
python.Range.values
Section titled “python.Range.values”def Range.values (start : Int) (step : Int) (count : Nat) : List ValueThe count values of a range from start by step.
python.Heap.listItems
Section titled “python.Heap.listItems”def Heap.listItems (h : Heap) (v : Value) : Option (List Value)The values the list v holds now on the heap h (none if it is not a list).
python.Object.items
Section titled “python.Object.items”def Object.items (h : Heap) (o : Object) : Option (List Value)The values iterating over the object o on the heap h gives, if it can be iterated.
python.Containers.runsCode
Section titled “python.Containers.runsCode”def Containers.runsCode (h : Heap) (v : Value) (o : Object) : BoolWhether iterating over the object o that v refers to on the heap h runs a user’s code or changes its state:
a generator, an iterator (taking its items uses it up: python.iterators’s Iterator.drain), or an instance whose
class defines __iter__ or __getitem__.
python.Containers.runs
Section titled “python.Containers.runs”def Containers.runs (h : Heap) (v : Value) : BoolWhether iterating over the value v on the heap h runs a user’s code or uses up an iterator
(Containers.runsCode).
python.Containers.iterate
Section titled “python.Containers.iterate”def Containers.iterate (h : Heap) (v : Value) : ItemsIterating over the value v on the heap h; iterating that runs a user’s code or uses up an iterator is the
caller’s, unsupported here.
python.Text.findWithin
Section titled “python.Text.findWithin”def Text.findWithin (fuel : Nat) (k : Nat) (part : Codes) (cs : Codes) : Option NatWhere part (not empty) first occurs in cs, within fuel steps (k: the position so far).
python.Containers.concatenate
Section titled “python.Containers.concatenate”def Containers.concatenate (h : Heap) (a : Value) (b : Value) : Option Changeda + b for two lists on the heap h (none when a is not a list: another operator’s case).
python.Containers.repeat
Section titled “python.Containers.repeat”def Containers.repeat (n : Int) (xs : List Value) : List ValueThe items xs repeated n times (none when n is not positive).
python.Containers.repeatError
Section titled “python.Containers.repeatError”def Containers.repeatError (h : Heap) (v : Value) : OutcomeTypeError for repeating a sequence by the value v that is not an int, its type name read from the heap h.
python.Containers.repeatList
Section titled “python.Containers.repeatList”def Containers.repeatList (h : Heap) (a : Value) (b : Value) : Option Changeda * b for a list a or b and a count, on the heap h (none when neither side is a list).
python.Outcome.truth
Section titled “python.Outcome.truth”def Outcome.truth (b : Bool) : OutcomeThe bool b produced.
python.Set.same
Section titled “python.Set.same”def Set.same (xs : List Value) (ys : List Value) : BoolWhether the sets with the items xs and ys have the same items.
python.Contents.fuel
Section titled “python.Contents.fuel”def Contents.fuel : NatHow deep comparing contents may go.
python.Contents.unsupported
Section titled “python.Contents.unsupported”def Contents.unsupported : OutcomeThe comparison the model cannot make: a user’s comparison method inside a container.
python.Class.lookup
Section titled “python.Class.lookup”def Class.lookup (h : Heap) (order : List Value) (name : String) : Option ValueThe attribute name along the method resolution order on the heap h, if a class in it defines it.
python.Value.isInstance
Section titled “python.Value.isInstance”def Value.isInstance (h : Heap) (v : Value) : BoolWhether the value v is an instance of a user’s class on the heap h.
python.Value.defines
Section titled “python.Value.defines”def Value.defines (h : Heap) (v : Value) (name : String) : BoolWhether the value v is an instance on the heap h whose class defines a method name.
python.Value.definesComparison
Section titled “python.Value.definesComparison”def Value.definesComparison (h : Heap) (v : Value) : BoolWhether the class of the value v on the heap h defines a comparison method.
python.Contents.equalOther
Section titled “python.Contents.equalOther”def Contents.equalOther (h : Heap) (a : Value) (b : Value) : Option BoolEquality of the values a and b of different kinds (or a user’s objects) on the heap h: not equal, unless one
defines __eq__ (unsupported here: none).
python.Object.isView
Section titled “python.Object.isView”def Object.isView (o : Object) : BoolWhether the object o is a dict’s view.
python.Object.setLike
Section titled “python.Object.setLike”def Object.setLike (h : Heap) (o : Object) : Option (List Value)The items of the object o on the heap h if it compares as a set: a set, or a dict’s keys or items view.
python.Contents.equalViews
Section titled “python.Contents.equalViews”def Contents.equalViews (h : Heap) (a : Value) (b : Value) (x : Object) (y : Object) : Option BoolEquality of the objects x and y that a and b refer to on the heap h, where a view takes part: as sets
when both compare as sets, else as other objects do.
python.Contents.equal
Section titled “python.Contents.equal”def Contents.equal (h : Heap) (a : Value) (b : Value) : Outcomea == b on the heap h as the built-in types decide it (a user’s object, whose methods were tried and declined,
is equal only to itself).
python.Contents.has
Section titled “python.Contents.has”def Contents.has (h : Heap) (x : Value) (xs : List Value) : Outcomex in xs for a sequence’s items xs on the heap h: x is y or x == y for some item.
python.Position
Section titled “python.Position”data PositionWhere an item first equals x: its position, none, or the comparison the model cannot make.
python.Contents.position
Section titled “python.Contents.position”def Contents.position (h : Heap) (k : Nat) (x : Value) (xs : List Value) : PositionThe first position from k where an item of xs equals x on the heap h.
python.Contents.count
Section titled “python.Contents.count”def Contents.count (h : Heap) (x : Value) (xs : List Value) (so : Nat) : OutcomeHow many items of xs equal x on the heap h (counted so far: so).
python.Contents.contains
Section titled “python.Contents.contains”def Contents.contains (h : Heap) (c : Value) (x : Value) : Outcomex in c on the heap h: a substring for a str, a key for a dict (hashable), an item for anything that can be
iterated.
python.Contents.sequence
Section titled “python.Contents.sequence”def Contents.sequence (h : Heap) (v : Value) : Option (Nat * List Value)A sequence’s kind (0 a list, 1 a tuple) and items, if the value v on the heap h is one.
python.Heap.setItems
Section titled “python.Heap.setItems”def Heap.setItems (h : Heap) (v : Value) : Option (List Value)A set’s items, if the value v on the heap h is one.
python.Contents.notOrdered
Section titled “python.Contents.notOrdered”def Contents.notOrdered (h : Heap) (symbol : String) (a : Value) (b : Value) : OutcomeTypeError for the comparison symbol between a and b, whose types have no order (their type names read from
the heap h).
python.Contents.setOrder
Section titled “python.Contents.setOrder”def Contents.setOrder (symbol : String) (xs : List Value) (ys : List Value) : BoolThe set order symbol between the sets with the items xs and ys: <= is a subset, < a proper subset, >=
a superset, > a proper superset.
python.Contents.compareValues
Section titled “python.Contents.compareValues”def Contents.compareValues (h : Heap) (symbol : String) (wanted : Int -> Bool) (a : Value) (b : Value) : OutcomeThe comparison symbol of a and b, values that are neither sequences nor sets: by their order without the
heap (wanted: whether a -1, 0 or 1 makes it true; h only names the types in TypeError).
python.Contents.less
Section titled “python.Contents.less”def Contents.less (h : Heap) (a : Value) (b : Value) : Outcomea < b by contents on the heap h.
python.Contents.greater
Section titled “python.Contents.greater”def Contents.greater (h : Heap) (a : Value) (b : Value) : Outcomea > b by contents on the heap h.
python.Sorted
Section titled “python.Sorted”data SortedWhat sorting gives: the values in order, or the exception a comparison raised.
python.SortedBy
Section titled “python.SortedBy”data SortedBy (A : Type)What sorting items by keys gives: the items in order, or the exception a comparison raised.
python.SortedBy.prepend
Section titled “python.SortedBy.prepend”def SortedBy.prepend {A : Type} (x : A) (r : SortedBy A) : SortedBy AThe item x put before the sorted result r.
python.Contents.before
Section titled “python.Contents.before”def Contents.before (h : Heap) (b : Value) (a : Value) : Option Raised * BoolWhether b sorts before a on the heap h: b < a (none with the exception when the comparison raises).
python.Contents.mergeBy
Section titled “python.Contents.mergeBy”def Contents.mergeBy {A : Type} (h : Heap) (key : A -> Value) (fuel : Nat) (xs : List A) (ys : List A) : SortedBy AMerging the lists xs and ys, sorted by their items’ key, on the heap h within fuel steps (an item of
ys goes first only when its key is less: stable).
python.Contents.mergeSortBy
Section titled “python.Contents.mergeSortBy”def Contents.mergeSortBy {A : Type} (h : Heap) (key : A -> Value) (fuel : Nat) (xs : List A) : SortedBy AA merge sort of xs by the items’ key on the heap h, within fuel halvings.
python.Contents.flip
Section titled “python.Contents.flip”def Contents.flip {A : Type} (i : Nat) (j : Nat) (xs : List A) : List AThe list xs with its items from position i up to j reversed.
python.Contents.moved
Section titled “python.Contents.moved”def Contents.moved {A : Type} (at : Nat) (ok : Nat) (moving : A) (xs : List A) : List AThe list xs with the item moving at position ok moved to position at (the ones between moved up one).
python.Contents.lessBy
Section titled “python.Contents.lessBy”def Contents.lessBy {A : Type} (h : Heap) (key : A -> Value) (x : A) (y : A) : Either Raised BoolWhether the key of x is less than the key of y by the built-in order on the heap h, or the exception
comparing them raised.
python.Contents.lessAt
Section titled “python.Contents.lessAt”def Contents.lessAt {A : Type} (h : Heap) (key : A -> Value) (xs : List A) (i : Nat) (j : Nat) : Either (Raised * List A) BoolWhether the item of xs at i is less than the one at j by their key on the heap h (false past the end); a
failure keeps the items as they are.
python.Contents.ascendFrom
Section titled “python.Contents.ascendFrom”def Contents.ascendFrom {A : Type} (h : Heap) (key : A -> Value) (fuel : Nat) (xs : List A) (n : Nat) (count : Nat) : Either (Raised * List A) Natcount_run‘s ascending stretch of xs from n, by the items’ key on the heap h within fuel steps: the
first n whose item is less than the one before (or the count of items).
python.Contents.lastEqual
Section titled “python.Contents.lastEqual”def Contents.lastEqual {A : Type} (xs : List A) (n : Nat) (neq : Nat) : List AREVERSE_LAST_NEQ: xs with the last stretch of equal items before n (neq after the first) reversed.
python.Contents.descendFrom
Section titled “python.Contents.descendFrom”def Contents.descendFrom {A : Type} (h : Heap) (key : A -> Value) (fuel : Nat) (xs : List A) (n : Nat) (neq : Nat) (count : Nat) : Either (Raised * List A) (List A * (Nat * Nat))count_run‘s descending stretch of xs from n (neq equal items so far), by the items’ key on the heap h
within fuel steps, among count items: the items with each finished stretch of equal ones reversed, where it ends,
and the equal ones still open.
python.Contents.descending
Section titled “python.Contents.descending”def Contents.descending {A : Type} (h : Heap) (key : A -> Value) (xs : List A) (n : Nat) (count : Nat) : Either (Raised * List A) (List A * Nat)count_run on the count items xs from a descending start at n, by their key on the heap h: the
stretch, its last equal items reversed, the whole run reversed, then extended by an ascending stretch.
python.Contents.countRun
Section titled “python.Contents.countRun”def Contents.countRun {A : Type} (h : Heap) (key : A -> Value) (xs : List A) (count : Nat) : Either (Raised * List A) (List A * Nat)count_run (CPython’s listsort) on the count items xs by their key on the heap h: the items with the
run at the start ascending, and its length.
python.Contents.searchFrom
Section titled “python.Contents.searchFrom”def Contents.searchFrom {A : Type} (h : Heap) (key : A -> Value) (fuel : Nat) (xs : List A) (pivot : A) (low : Nat) (high : Nat) : Either (Raised * List A) Natbinarysort‘s search in xs by the items’ key on the heap h, within fuel halvings: where the pivot
belongs between low and high (pivot < a[M] halving).
python.Contents.insertFrom
Section titled “python.Contents.insertFrom”def Contents.insertFrom {A : Type} (h : Heap) (key : A -> Value) (fuel : Nat) (xs : List A) (ok : Nat) (count : Nat) : Either (Raised * List A) (List A)binarysort of the count items xs from ok (the items before it sorted), by their key on the heap h
within fuel steps: each next item moved where it belongs among those before it.
python.Contents.shortSort
Section titled “python.Contents.shortSort”def Contents.shortSort {A : Type} (h : Heap) (key : A -> Value) (xs : List A) : Option Raised * List AThe items xs (fewer than 64) sorted by their key on the heap h as CPython’s listsort does (one run:
count_run then binarysort), so a comparison that raises is the one CPython makes first: the items sorted, or as
far as the sorting got, with the exception.
python.Contents.sortPartly
Section titled “python.Contents.sortPartly”def Contents.sortPartly {A : Type} (h : Heap) (key : A -> Value) (reversed : Bool) (xs : List A) : Option Raised * List AThe items xs sorted by their key on the heap h, with the exception a comparison raised (the items then as
far as the sorting got, as CPython’s list.sort leaves them): fewer than 64 as CPython compares them
(Contents.shortSort); more by a stable merge sort, which gives the same order, but a comparison that raises there
is not taken (CPython may compare another pair first). When reversed, CPython reverses, sorts and reverses again
(after a failure too), so items with equal keys keep their order.
python.Contents.sortBy
Section titled “python.Contents.sortBy”def Contents.sortBy {A : Type} (h : Heap) (key : A -> Value) (reversed : Bool) (xs : List A) : SortedBy AThe items xs sorted by their key on the heap h (descending when reversed), or the exception a comparison
raised (Contents.sortPartly).
python.Contents.itself
Section titled “python.Contents.itself”def Contents.itself (v : Value) : ValueThe value v as its own key.
python.Contents.sort
Section titled “python.Contents.sort”def Contents.sort (h : Heap) (reversed : Bool) (xs : List Value) : Sortedsorted(xs) on the heap h: the values sorted by themselves (descending when reversed).