builtins
本頁內容尚未翻譯。
python.Builtin
Section titled “python.Builtin”def Builtin : TypeWhat a built-in does with its arguments: the heap, the positional arguments, the keyword arguments.
python.Builtins.natural
Section titled “python.Builtins.natural”def Builtins.natural (n : Nat) : ValueAn int of the natural value n.
python.Builtins.floatResult
Section titled “python.Builtins.floatResult”def Builtins.floatResult (h : Heap) (f : Float) : ChangedThe float f produced, on the heap h.
python.Builtins.floatOutcome
Section titled “python.Builtins.floatOutcome”def Builtins.floatOutcome (f : Float) : OutcomeThe float f as an outcome.
python.Builtins.argument
Section titled “python.Builtins.argument”def Builtins.argument (positional : List Value) (k : Nat) : ValueThe value of the argument at position k among positional (None when absent: the check before has made sure it
is there).
python.Builtins.runsCode
Section titled “python.Builtins.runsCode”def Builtins.runsCode (what : String) : RaisedWhat running a user’s method what would need: unsupported here.
python.Builtins.definesAny
Section titled “python.Builtins.definesAny”def Builtins.definesAny (h : Heap) (v : Value) (names : List String) : BoolWhether the value v on the heap h is an instance whose class defines one of the methods names.
python.Builtins.len
Section titled “python.Builtins.len”def Builtins.len (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedlen(x), with the call’s positional and keywords arguments on the heap h.
python.Builtins.abs
Section titled “python.Builtins.abs”def Builtins.abs (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedabs(x), with the call’s positional and keywords arguments on the heap h.
python.Builtins.round
Section titled “python.Builtins.round”def Builtins.round (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedround(number, ndigits=None), with the call’s positional and keywords arguments on the heap h.
python.Builtins.divmod
Section titled “python.Builtins.divmod”def Builtins.divmod (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changeddivmod(a, b): the floor quotient and the remainder. With the call’s positional and keywords arguments on the
heap h.
python.Builtins.digitValue
Section titled “python.Builtins.digitValue”def Builtins.digitValue (c : Nat) : Option NatThe value of the digit c in bases up to 36 (none for anything else).
python.Builtins.digitsIn
Section titled “python.Builtins.digitsIn”def Builtins.digitsIn (base : Nat) (value : Nat) (count : Nat) (afterDigit : Bool) (underscoreFirst : Bool) (cs : Codes) : Option (Nat * Nat)The digits cs in base with single underscores between them (an underscore may come first when
underscoreFirst: a prefix came before), after count digits read so far of value value (afterDigit when the
last was a digit): the value and how many digits; none for anything else.
python.Builtins.digitsAfterUnderscore
Section titled “python.Builtins.digitsAfterUnderscore”def Builtins.digitsAfterUnderscore (base : Nat) (value : Nat) (count : Nat) (cs : Codes) : Option (Nat * Nat)The digits cs in base after an underscore, after count digits read so far of value value: a digit must
come next.
python.Builtins.prefixBase
Section titled “python.Builtins.prefixBase”def Builtins.prefixBase (cs : Codes) : Option NatThe base a prefix gives (0x, 0o, 0b in either case), if the text cs has one.
python.Builtins.powerOfTwo
Section titled “python.Builtins.powerOfTwo”def Builtins.powerOfTwo (base : Nat) : BoolWhether a base is a power of two (its texts have no digit limit).
python.Builtins.allZeros
Section titled “python.Builtins.allZeros”def Builtins.allZeros (cs : Codes) : BoolWhether the decimal digits cs are all zeros (base 0 allows leading zeros only then).
python.Builtins.parseInt
Section titled “python.Builtins.parseInt”def Builtins.parseInt (cs : Codes) (base : Nat) : Either Raised Intint(text, base) of the text cs (CPython’s PyLong_FromString): whitespace and a sign around, then a prefix
that matches the base, then digits.
python.Builtins.toInt
Section titled “python.Builtins.toInt”def Builtins.toInt (h : Heap) (x : Value) : Outcomeint(x) of the value x on the heap h without a base: a number truncated toward zero, a text in base 10.
python.Builtins.int
Section titled “python.Builtins.int”def Builtins.int (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedint(x=0, /, base=10), with the call’s positional and keywords arguments on the heap h.
python.Builtins.float
Section titled “python.Builtins.float”def Builtins.float (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedfloat(x=0.0), with the call’s positional and keywords arguments on the heap h.
python.Builtins.shown
Section titled “python.Builtins.shown”def Builtins.shown (h : Heap) (asRepr : Bool) (x : Value) : Changedstr(x), or repr(x) when asRepr, of the value x on the heap h, checked for ints too long.
python.Builtins.str
Section titled “python.Builtins.str”def Builtins.str (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedstr(object=''), and str(object, encoding, errors) (bytes are not in the subset). With the call’s positional
and keywords arguments on the heap h.
python.Builtins.repr
Section titled “python.Builtins.repr”def Builtins.repr (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedrepr(x), with the call’s positional and keywords arguments on the heap h.
python.Builtins.truth
Section titled “python.Builtins.truth”def Builtins.truth (h : Heap) (v : Value) : Option BoolThe truth of the value v on the heap h; none when it would run a user’s __bool__ or __len__.
python.Builtins.bool
Section titled “python.Builtins.bool”def Builtins.bool (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedbool(x=False), with the call’s positional and keywords arguments on the heap h.
python.Builtins.type
Section titled “python.Builtins.type”def Builtins.type (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedtype(x): its class (making a class with three arguments is not in the subset). With the call’s positional and
keywords arguments on the heap h.
python.Builtins.format
Section titled “python.Builtins.format”def Builtins.format (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedformat(value, format_spec=''), with the call’s positional and keywords arguments on the heap h.
python.Builtins.range
Section titled “python.Builtins.range”def Builtins.range (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedrange(stop), range(start, stop[, step]), with the call’s positional and keywords arguments on the heap
h.
python.Builtins.items
Section titled “python.Builtins.items”def Builtins.items (h : Heap) (v : Value) (work : Heap -> List Value -> Changed) : ChangedThe items of the iterable argument v on the heap h given to work, or the exception.
python.Builtins.collection
Section titled “python.Builtins.collection”def Builtins.collection (h : Heap) (kind : String) (positional : List Value) (keywords : List (Codes * Value)) : Changedlist(iterable=()), tuple(iterable=()), set(iterable=()), by kind, with the call’s positional and
keywords arguments on the heap h.
python.Builtins.dict
Section titled “python.Builtins.dict”def Builtins.dict (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changeddict(**kwargs), dict(mapping, **kwargs), dict(iterable, **kwargs): a new dict updated as dict.update. With
the call’s positional and keywords arguments on the heap h.
python.Builtins.sorted
Section titled “python.Builtins.sorted”def Builtins.sorted (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedsorted(iterable, /, *, key=None, reverse=False): a new list sorted as list.sort. With the call’s positional
and keywords arguments on the heap h.
python.Builtins.floatSum
Section titled “python.Builtins.floatSum”def Builtins.floatSum (total : Float) (compensation : Float) (xs : List Value) : Float * (Float * List Value)Neumaier’s compensated sum of floats (CPython’s builtin_sum_impl from 3.12): the sum so far total, the
compensation, the items left xs; an int that fits a C long is converted to a float first. The rest (the first item
that is not a float or such an int) goes to the generic addition.
python.Builtins.compensated
Section titled “python.Builtins.compensated”def Builtins.compensated (total : Float) (compensation : Float) : FloatThe sum total with the compensation added in when it is finite and not zero.
python.Builtins.sumWithin
Section titled “python.Builtins.sumWithin”def Builtins.sumWithin (fuel : Nat) (h : Heap) (total : Value) (xs : List Value) : ChangedAdding the items xs to the sum total in turn, on the heap h (fuel: the items left): a float sum is
compensated.
python.Builtins.addThen
Section titled “python.Builtins.addThen”def Builtins.addThen (fuel : Nat) (h : Heap) (total : Value) (x : Value) (rest : List Value) : ChangedAdding the item x to the sum total with + on the heap h, then the rest (fuel: the items left).
python.Builtins.sum
Section titled “python.Builtins.sum”def Builtins.sum (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedsum(iterable, /, start=0): a str start is TypeError. With the call’s positional and keywords arguments on the
heap h.
python.Builtins.extreme
Section titled “python.Builtins.extreme”def Builtins.extreme (h : Heap) (isMax : Bool) (best : Value) (xs : List Value) : OutcomeThe first greatest (max, when isMax) or least (min) of best and the values xs after it, on the heap h.
python.Builtins.zipped
Section titled “python.Builtins.zipped”def Builtins.zipped (keys : List Value) (items : List Value) : List (Value * Value)The keys paired with the items, in order (as long as the shorter).
python.Builtins.extremeBy
Section titled “python.Builtins.extremeBy”def Builtins.extremeBy (h : Heap) (isMax : Bool) (best : Value * Value) (xs : List (Value * Value)) : OutcomeThe item of the greatest (max, when isMax) or least key among the key and item pair best so far and the rest
xs, on the heap h: the first such item, as CPython keeps the one it has unless a later key is strictly greater (or
less).
python.Builtins.byKeys
Section titled “python.Builtins.byKeys”def Builtins.byKeys (h : Heap) (name : String) (items : List Value) (keys : List Value) (reversed : Bool) (fallback : Option Value) : Changedsorted, min and max (by name) on the heap h once a key function’s keys are known (the caller called it
on each item, as CPython does before comparing): the items in the order of their keys (reversed as reverse says),
or the item of the least or greatest key (the default fallback, or ValueError, for none); keys whose comparison is a
user’s code are not taken here.
python.Builtins.exceptionInit
Section titled “python.Builtins.exceptionInit”def Builtins.exceptionInit (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : ChangedAn exception’s built-in __init__(self, *args) (a user’s exception class calling super().__init__): its args
set (and a StopIteration’s value), None returned; keyword arguments are a TypeError. With the call’s positional and
keywords arguments on the heap h.
python.Builtins.exceptionStr
Section titled “python.Builtins.exceptionStr”def Builtins.exceptionStr (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : ChangedAn exception’s built-in __str__(self): ‘’ for no arguments, the str of the only one, else the str of the
tuple; an argument whose str is a user’s code is not taken here. With the call’s positional and keywords arguments
on the heap h.
python.Builtins.extremeOf
Section titled “python.Builtins.extremeOf”def Builtins.extremeOf (h : Heap) (name : String) (positional : List Value) (keywords : List (Codes * Value)) : Changedmax(iterable, *, key=None, default), max(a, b, *args, key=None), and min, by name, with the call’s
positional and keywords arguments on the heap h.
python.Builtins.decide
Section titled “python.Builtins.decide”def Builtins.decide (h : Heap) (wanted : Bool) (xs : List Value) : Option BoolThe truths of the values xs on the heap h in order, until one decides (any: a true one, wanted true; all: a
false one); none when a user’s code would run first.
python.Builtins.decideTaking
Section titled “python.Builtins.decideTaking”def Builtins.decideTaking (fuel : Nat) (h : Heap) (wanted : Bool) (it : Value) : Changedany and all (wanted true for any) over the iterator it on the heap h: items taken one at a time, at most
fuel, until one decides (the rest stay in the iterator).
python.Builtins.anyAll
Section titled “python.Builtins.anyAll”def Builtins.anyAll (h : Heap) (name : String) (positional : List Value) (keywords : List (Codes * Value)) : Changedany(iterable), all(iterable), by name, with the call’s positional and keywords arguments on the heap
h.
python.Builtins.ord
Section titled “python.Builtins.ord”def Builtins.ord (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedord(c), with the call’s positional and keywords arguments on the heap h.
python.Builtins.chr
Section titled “python.Builtins.chr”def Builtins.chr (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedchr(i), with the call’s positional and keywords arguments on the heap h.
python.Builtins.classTest
Section titled “python.Builtins.classTest”def Builtins.classTest (h : Heap) (name : String) (positional : List Value) (keywords : List (Codes * Value)) : Changedisinstance(x, classes), issubclass(c, classes), by name, with the call’s positional and keywords arguments
on the heap h.
python.Builtins.wrapped
Section titled “python.Builtins.wrapped”def Builtins.wrapped (h : Heap) (name : String) (positional : List Value) (keywords : List (Codes * Value)) : Changedstaticmethod(f), classmethod(f), by name, with the call’s positional and keywords arguments on the heap
h.
python.Builtins.property
Section titled “python.Builtins.property”def Builtins.property (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedproperty(fget=None, fset=None, fdel=None, doc=None) (deleting through a property is not in the subset). With the
call’s positional and keywords arguments on the heap h.
python.Builtins.propertyWith
Section titled “python.Builtins.propertyWith”def Builtins.propertyWith (which : String) (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedp.getter(f) and p.setter(f): a new property with the function as its getter or setter, the other kept
(p.deleter is not in the subset, as deleting through a property is not). By which, with the call’s positional and
keywords arguments on the heap h.
python.Builtins.iter
Section titled “python.Builtins.iter”def Builtins.iter (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changediter(object) (with a sentinel it needs a callable: the user’s code, unsupported here). With the call’s
positional and keywords arguments on the heap h.
python.Exec.builtinOf
Section titled “python.Exec.builtinOf”def Exec.builtinOf (f : Value) : Option CodesWhether f is a built-in function’s value: its name if it is.
python.Builtins.next
Section titled “python.Builtins.next”def Builtins.next (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changednext(iterator[, default]): StopIteration when it has run out and there is no default. With the call’s positional
and keywords arguments on the heap h.
python.Builtins.enumerate
Section titled “python.Builtins.enumerate”def Builtins.enumerate (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedenumerate(iterable, start=0) (CPython’s own argument parsing: its own messages for keywords). With the call’s
positional and keywords arguments on the heap h.
python.Builtins.iteratorsOf
Section titled “python.Builtins.iteratorsOf”def Builtins.iteratorsOf (h : Heap) (xs : List Value) (so : List Value) : ChangedIterators of the iterables xs in turn on the heap h, after the ones so far, or the first exception.
python.Builtins.zip
Section titled “python.Builtins.zip”def Builtins.zip (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedzip(*iterables, strict=False), with the call’s positional and keywords arguments on the heap h.
python.Builtins.reversed
Section titled “python.Builtins.reversed”def Builtins.reversed (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedreversed(seq): a list walked backward as it is, a tuple’s or a str’s items backward, a range backward (a
dict, a dict’s view or a user’s sequence: unsupported here). With the call’s positional and keywords arguments on
the heap h.
python.Builtins.named
Section titled “python.Builtins.named”def Builtins.named (name : String) (f : Heap -> String -> List Value -> List (Codes * Value) -> Changed) : BuiltinThe built-in f with name as the name it takes first.
python.Builtins.functions
Section titled “python.Builtins.functions”def Builtins.functions : List BuiltinThe built-in functions the model provides.
python.Builtins.real
Section titled “python.Builtins.real”def Builtins.real (h : Heap) (v : Value) : Either Raised FloatThe real number argument v of a math function, on the heap h, as a float: TypeError for anything else,
OverflowError for an int too large.
python.Builtins.sqrt
Section titled “python.Builtins.sqrt”def Builtins.sqrt (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedmath.sqrt(x): ValueError for a negative x. With the call’s positional and keywords arguments on the heap
h.
python.Builtins.fabs
Section titled “python.Builtins.fabs”def Builtins.fabs (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedmath.fabs(x), with the call’s positional and keywords arguments on the heap h.
python.Builtins.rounded
Section titled “python.Builtins.rounded”def Builtins.rounded (h : Heap) (name : String) (positional : List Value) (keywords : List (Codes * Value)) : Changedmath.floor(x), math.ceil(x): an int. By name, with the call’s positional and keywords arguments on the
heap h.
python.Builtins.mathPow
Section titled “python.Builtins.mathPow”def Builtins.mathPow (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedmath.pow(x, y) (CPython’s math_pow_impl): a NaN from finite arguments, or zero to a negative power, is
ValueError; an infinite result from finite arguments is OverflowError. With the call’s positional and keywords
arguments on the heap h.
python.Builtins.truncatedRemainder
Section titled “python.Builtins.truncatedRemainder”def Builtins.truncatedRemainder (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedmath.fmod(x, y) (CPython’s math_fmod_impl): the remainder of the truncating division, with the sign of x. An
infinite y leaves a finite x as it is; a NaN from arguments that are not NaN (y zero, or x infinite) is ValueError.
With the call’s positional and keywords arguments on the heap h.
python.Builtins.gcdWithin
Section titled “python.Builtins.gcdWithin”def Builtins.gcdWithin (fuel : Nat) (a : Nat) (b : Nat) : NatThe greatest common divisor of the naturals a and b, within fuel steps.
python.Builtins.gcdOf
Section titled “python.Builtins.gcdOf”def Builtins.gcdOf (a : Nat) (b : Nat) : NatThe greatest common divisor of the naturals a and b.
python.Builtins.gcd
Section titled “python.Builtins.gcd”def Builtins.gcd (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedmath.gcd(*integers): zero for none. With the call’s positional and keywords arguments on the heap h.
python.Builtins.factorialOf
Section titled “python.Builtins.factorialOf”def Builtins.factorialOf (n : Nat) : Natn!, the factorial of n.
python.Builtins.factorial
Section titled “python.Builtins.factorial”def Builtins.factorial (h : Heap) (positional : List Value) (keywords : List (Codes * Value)) : Changedmath.factorial(n): ValueError for a negative n, OverflowError past a C long. With the call’s positional and
keywords arguments on the heap h.
python.Builtins.inexactMath
Section titled “python.Builtins.inexactMath”def Builtins.inexactMath : List StringThe math functions whose accuracy CPython leaves to the platform’s math library (it calls libm’s pow): the
model gives the correctly rounded result, which the verdict assumes of the library (the same choice the C family names
for pow). sqrt and fmod are exact by IEEE 754 and assume nothing.
python.Builtins.math
Section titled “python.Builtins.math”def Builtins.math : List BuiltinThe math module’s functions the model provides.
python.Builtins.mathConstant
Section titled “python.Builtins.mathConstant”def Builtins.mathConstant (name : String) : Option ValueThe math module’s constant name: the binary64 nearest to each (their shortest decimals read back to them).
python.Builtins.call
Section titled “python.Builtins.call”def Builtins.call (h : Heap) (name : String) (positional : List Value) (keywords : List (Codes * Value)) : ChangedCalling the built-in function or math function name (math.sqrt) with the call’s positional and keywords
arguments on the heap h; a name the model does not provide is unsupported.