Lynxer

Documentation

typing

Type inspection, conversion, range, string, number and sequence helpers.

Backend: pure — stdlib/typing.lynx only, over the interpreter's builtins. Import: import("typing") → global.typing.*

The interpreter's strings hold UTF-8, and returnLength, charAt, substring and the charCode/charOf builtins work on code points, so a character is one Unicode scalar value rather than one byte: returnLength("café") is 4 and charCode("é") is 233. charOf accepts any code point up to 0x10FFFF except the surrogate range.

Type Checks

FunctionSignatureReturnsDescription
isNumisNum(any val)booltrue if val is int or float
isIntisInt(any val)booltrue if val is an int
isFloatisFloat(any val)booltrue if val is a float
isStrisStr(any val)booltrue if val is a str
isBoolisBool(any val)booltrue if val is a bool
isListisList(any val)booltrue if val is a list
isTupleisTuple(any val)booltrue if val is a tuple
isCharisChar(any val)booltrue if val is a char
isNoneisNone(any val)booltrue if val is none
isSequenceisSequence(any val)booltrue if val is a list or tuple
isNumericisNumeric(any value)booltrue if value is an int or float
isAlpha / isDigit / isAlphaNum / isSpace(str value)boolEvery character is an ASCII letter / digit / alphanumeric / whitespace; false for ""

isNumeric keeps the Lynxer meaning ("is a number"), not the legacy "the string parses as a number"; use isDigit for digit-only strings.

Integer and Float Ranges

FunctionReturnsDescription
isNumBool / isBitboolint equal to 0 or 1
isInt8 / isInt16 / isInt32 / isInt64boolInteger fits the signed range (int covers the full 64-bit range)
isByte / isUInt8boolInteger in 0..255
isUInt16 / isUInt32 / isUInt64boolInteger in the unsigned range (isUInt64 is int >= 0)
isFloat32 / isFloat64boolNumber within the float32 range / any number

Type Conversions

FunctionSignatureReturnsDescription
typeOftypeOf(any value)strThe value's type name
toStrtoStr(any value)strRenders as text
toStringtoString(any val)strAlias of toStr
toInttoInt(any value)intConverts to an integer
toFloattoFloat(any value)floatConverts to a float
toFloat32 / toFloat64(any value)floatBoth return floatOf(value); Lynxer float is a double, so there is no single-precision narrowing
toBooltoBool(any value)boolvalue != 0
toNumBool(any value)numBoolNormalizes to 0 or 1
toBit(any value)bitNormalizes to 0 or 1
toByte(any value)byteConverts and clamps to 0..255
toChar(any val)charOne-byte string or int code in 0..255; NUL byte on error
toNumber(any val)floatConverts a number to a float; 0.0 otherwise

Char Functions

FunctionSignatureReturnsDescription
charCodeOfcharCodeOf(any val)intCode point of a char, or of the first character of a str; -1 on error
charCodecharCode(str value)intCode point of the first character; -1 for ""
charOfcharOf(int code)charThe char for a code point in 0..0x10FFFF (except surrogates); NUL otherwise
charAtcharAt(str value, int index)char | noneThe character at index, or none when out of range

String Functions

FunctionSignatureReturnsDescription
lenStrlenStr(str value)intLength in code points
trim / stripLeft / stripRight(str value)strStrip leading and trailing / leading / trailing whitespace
upper / lower / titleCase / swapCase(str value)strCase conversion
repeat / repeatStr(str value, int n)strRepeat n times
containscontains(str value, str needle)boolSubstring test (true for an empty needle)
startsWith / endsWith(str value, str affix)boolPrefix / suffix test
replace(str value, str old, str new)strReplace every occurrence
indexOf(str value, str needle)intFirst index, or -1; 0 for an empty needle
countOccurrences(str value, str needle)intNon-overlapping occurrences
substr(str value, int start, int end)strSlice with negative indices and clamping
padLeft / padRight / center(str value, int width, str fill)strPad to width
zfill(str value, int width)strZero-pad, keeping a leading sign
strReverse(str value)strReverse the characters
spacesspaces(int n)strn space characters
wordWrap(str value, int width)strGreedy wrap on spaces
expandTabs(str value, int tabSize)strExpand tabs to tabSize-wide stops
splitFirst(str value, str sep)listTwo-element [before, after]
splitToList(str value, str sep)listSplit into a list of strings
linesOf(str value)listSplit on newlines; [] for ""

Number Functions

FunctionSignatureReturnsDescription
absabs(num value)numAbsolute value
signsign(num value)int1, -1 or 0
maxOf / minOf(num a, num b)numLarger / smaller of two numbers
clampclamp(float value, float low, float high)floatClamp to [low, high]
betweenbetween(num value, num low, num high)boollow <= value <= high
roundToroundTo(float value, int digits)floatRound to digits decimal places

List Functions

These complement the language built-ins (listPush, listGet, sortList, etc.).

FunctionSignatureReturnsDescription
lenList(list lst)intNumber of elements
listFirst / listLast(list lst)elementFirst / last element; runtime error if empty
listHead / listTail(list lst, int n)listFirst / last n elements
listSum / listAvg(list lst)floatSum / mean of numeric elements
listCount(list lst, any val)intOccurrences of val
listRepeat(any val, int n)listn copies of val
listZip(list a, list b)listJSON pair strings {"a":"…","b":"…"}
listChunk(list lst, int n)listJSON-encoded chunks of size n
flatten(list lst)listFlatten one level
unique(list lst)listRemove duplicates, order preserved

Tuple Functions

These compose the language-level tuple built-ins.

FunctionSignatureReturnsDescription
tupleReverse(any t)tupleReversed
tupleSort / tupleSortDesc(any t)tupleSorted ascending / descending
tupleMin / tupleMax(any t)anyMinimum / maximum (or none)
tupleSum / tupleMean(any t)floatSum / arithmetic mean
tupleAny / tupleAll(any t)boolAny / all elements truthy
tupleUnique(any t)tupleDuplicates removed, order preserved
tupleFlatten(any t)tupleFlatten one level
tupleZip(any a, any b)listJSON pair strings
tupleJoin(any t, str sep)strJoin elements with sep

Sequence Conversion

FunctionSignatureReturnsDescription
toList(any val)listTuple → list; lists unchanged; other values → []
toTuple(any val)tupleList → tuple; tuples unchanged; other values → ()
lenSequence(any val)intLength of a list or tuple; 0 otherwise

Example

global setup(){ import("typing"); }

global main(){
    any x = 42;
    if(global.typing.isInt(x)){   print("integer\n"); }

    println(global.typing.abs(-4));            // 4
    println(global.typing.clamp(15.0, 0.0, 10.0)); // 10
    println(global.typing.roundTo(3.14159, 2));    // 3.14
    println(global.typing.charCodeOf("A"));    // 65
    println(global.typing.charAt("hello", 1)); // e
    println(global.typing.zfill("42", 5));     // 00042

    list nums = range(6);
    println(global.typing.listHead(nums, 3));  // [0, 1, 2]
    println(global.typing.listChunk(nums, 2)); // [[0, 1], [2, 3], [4, 5]]

    tuple coords = (int 10, int 20);
    println(global.typing.tupleJoin(coords, "-")); // 10-20
    println(global.typing.toList(coords));     // [10, 20]
}

See also