Skip to content

Builtin Functions Complete Reference

Complete reference of all 110+ builtin functions in HypnoScript (Rust Edition).

Core Builtins (I/O & Conversion)

Output Functions

FunctionSignatureDescription
observe(value: string) -> voidStandard output with newline
whisper(value: string) -> voidOutput without newline
command(value: string) -> voidOutput in uppercase
drift(ms: number) -> voidPause/Sleep (in milliseconds)

Hypnotic Functions

FunctionSignatureDescription
DeepTrance(duration: number) -> voidDeep trance induction with delay
HypnoticCountdown(from: number) -> voidHypnotic countdown
TranceInduction(subjectName: string) -> voidComplete trance induction
HypnoticVisualization(scene: string) -> voidHypnotic visualization

Conversion Functions

FunctionSignatureDescription
ToInt(value: number) -> numberConvert to integer (truncate)
ToDouble(value: string) -> numberParse string to number
ToString(value: any) -> stringConvert to string
ToBoolean(value: string) -> booleanParse string to boolean

Math Builtins

Trigonometric Functions

FunctionSignatureDescription
Sin(x: number) -> numberSine
Cos(x: number) -> numberCosine
Tan(x: number) -> numberTangent

Root & Power

FunctionSignatureDescription
Sqrt(x: number) -> numberSquare root
Pow(base: number, exponent: number) -> numberPower

Logarithms

FunctionSignatureDescription
Log(x: number) -> numberNatural logarithm (ln)
Log10(x: number) -> numberBase-10 logarithm

Rounding

FunctionSignatureDescription
Abs(x: number) -> numberAbsolute value
Floor(x: number) -> numberRound down
Ceil(x: number) -> numberRound up
Round(x: number) -> numberRound to nearest

Min/Max

FunctionSignatureDescription
Min(a: number, b: number) -> numberMinimum
Max(a: number, b: number) -> numberMaximum
Clamp(value: number, min: number, max: number) -> numberClamp value

Number Theory

FunctionSignatureDescription
Factorial(n: number) -> numberFactorial
Gcd(a: number, b: number) -> numberGreatest common divisor
Lcm(a: number, b: number) -> numberLeast common multiple
IsPrime(n: number) -> booleanCheck if prime
Fibonacci(n: number) -> numbern-th Fibonacci number

String Builtins

Basic Operations

FunctionSignatureDescription
Length(s: string) -> numberString length
ToUpper(s: string) -> stringTo uppercase
ToLower(s: string) -> stringTo lowercase
Trim(s: string) -> stringRemove whitespace
Reverse(s: string) -> stringReverse string
Capitalize(s: string) -> stringCapitalize first letter

Search & Replace

FunctionSignatureDescription
IndexOf(s: string, pattern: string) -> numberIndex of substring (-1 if not found)
Replace(s: string, from: string, to: string) -> stringReplace all occurrences
Contains(s: string, pattern: string) -> booleanCheck if contains
StartsWith(s: string, prefix: string) -> booleanCheck prefix
EndsWith(s: string, suffix: string) -> booleanCheck suffix

Manipulation

FunctionSignatureDescription
Split(s: string, delimiter: string) -> string[]Split string
Substring(s: string, start: number, end: number) -> stringExtract substring
Repeat(s: string, times: number) -> stringRepeat string
PadLeft(s: string, width: number, char: string) -> stringPad left
PadRight(s: string, width: number, char: string) -> stringPad right

Checks

FunctionSignatureDescription
IsEmpty(s: string) -> booleanCheck if empty
IsWhitespace(s: string) -> booleanCheck if only whitespace

Array Builtins

:::note Array Prefix All array functions use the Array prefix to distinguish from string functions (e.g., ArrayLength vs. string Length). :::

Basic Operations

FunctionSignatureDescription
ArrayLength(arr: T[]) -> numberArray length
ArrayIsEmpty(arr: T[]) -> booleanCheck if empty
ArrayGet(arr: T[], index: number) -> TElement at index
ArrayIndexOf(arr: T[], element: T) -> numberIndex of element (-1 if not found)
ArrayContains(arr: T[], element: T) -> booleanCheck if contains

Transformation

FunctionSignatureDescription
ArrayReverse(arr: T[]) -> T[]Reverse array
ArraySort(arr: number[]) -> number[]Sort numerically
ArrayDistinct(arr: T[]) -> T[]Remove duplicates

Aggregation

FunctionSignatureDescription
ArraySum(arr: number[]) -> numberSum
ArrayAverage(arr: number[]) -> numberAverage
ArrayMin(arr: number[]) -> numberMinimum
ArrayMax(arr: number[]) -> numberMaximum

Slicing

FunctionSignatureDescription
ArrayFirst(arr: T[]) -> TFirst element
ArrayLast(arr: T[]) -> TLast element
ArrayTake(arr: T[], n: number) -> T[]First n elements
ArraySkip(arr: T[], n: number) -> T[]Skip first n elements
ArraySlice(arr: T[], start: number, end: number) -> T[]Subarray

More

FunctionSignatureDescription
ArrayJoin(arr: T[], separator: string) -> stringArray to string
ArrayCount(arr: T[], element: T) -> numberFrequency of element

Statistics Builtins

Central Tendency

FunctionSignatureDescription
CalculateMean(arr: number[]) -> numberArithmetic mean
CalculateMedian(arr: number[]) -> numberMedian
CalculateMode(arr: number[]) -> numberMode (most frequent)

Dispersion

FunctionSignatureDescription
CalculateVariance(arr: number[]) -> numberVariance
CalculateStandardDeviation(arr: number[]) -> numberStandard deviation
CalculateRange(arr: number[]) -> numberRange (Max - Min)
CalculatePercentile(arr: number[], percentile: number) -> numberCalculate percentile

Correlation & Regression

FunctionSignatureDescription
CalculateCorrelation(x: number[], y: number[]) -> numberCorrelation coefficient
LinearRegression(x: number[], y: number[]) -> (number, number)Linear regression (slope, intercept)

Time Builtins

Current Time

FunctionSignatureDescription
GetCurrentTime() -> numberUnix timestamp (seconds)
GetCurrentDate() -> stringCurrent date (YYYY-MM-DD)
GetCurrentTimeString() -> stringCurrent time (HH:MM:SS)
GetCurrentDateTime() -> stringDate and time
FormatDateTime(format: string) -> stringFormatted time

Date Components

FunctionSignatureDescription
GetYear() -> numberCurrent year
GetMonth() -> numberCurrent month (1-12)
GetDay() -> numberCurrent day (1-31)
GetHour() -> numberCurrent hour (0-23)
GetMinute() -> numberCurrent minute (0-59)
GetSecond() -> numberCurrent second (0-59)
GetDayOfWeek() -> numberDay of week (0=Sunday)
GetDayOfYear() -> numberDay of year (1-366)

Date Calculations

FunctionSignatureDescription
IsLeapYear(year: number) -> booleanCheck leap year
GetDaysInMonth(year: number, month: number) -> numberDays in month

System Builtins

System Information

FunctionSignatureDescription
GetCurrentDirectory() -> stringCurrent directory
GetOperatingSystem() -> stringOperating system
GetArchitecture() -> stringCPU architecture
GetCpuCount() -> numberNumber of CPU cores
GetHostname() -> stringHostname
GetUsername() -> stringUsername
GetHomeDirectory() -> stringHome directory
GetTempDirectory() -> stringTemp directory

Environment Variables

FunctionSignatureDescription
GetEnvVar(name: string) -> stringRead environment variable
SetEnvVar(name: string, value: string) -> voidSet environment variable

Process

FunctionSignatureDescription
GetArgs() -> string[]Command line arguments
Exit(code: number) -> voidExit program

File Builtins

File Operations

FunctionSignatureDescription
ReadFile(path: string) -> stringRead file
WriteFile(path: string, content: string) -> voidWrite file
AppendFile(path: string, content: string) -> voidAppend to file
DeleteFile(path: string) -> voidDelete file
CopyFile(from: string, to: string) -> voidCopy file
RenameFile(from: string, to: string) -> voidRename file

File Information

FunctionSignatureDescription
FileExists(path: string) -> booleanCheck if file exists
IsFile(path: string) -> booleanCheck if path is a file
IsDirectory(path: string) -> booleanCheck if path is a directory
GetFileSize(path: string) -> numberFile size in bytes
GetFileExtension(path: string) -> stringFile extension
GetFileName(path: string) -> stringFile name
GetParentDirectory(path: string) -> stringParent directory

Directory Operations

FunctionSignatureDescription
CreateDirectory(path: string) -> voidCreate directory
ListDirectory(path: string) -> string[]List directory

Validation Builtins

Format Validation

FunctionSignatureDescription
IsValidEmail(email: string) -> booleanEmail validation
IsValidUrl(url: string) -> booleanURL-Validierung
IsValidPhoneNumber(phone: string) -> booleanTelefonnummer-Validierung

Zeichen-Prüfungen

FunctionSignaturDescription
IsAlphanumeric(s: string) -> booleanNur Buchstaben und Zahlen
IsAlphabetic(s: string) -> booleanNur Buchstaben
IsNumeric(s: string) -> booleanNur Zahlen
IsLowercase(s: string) -> booleanNur Kleinbuchstaben
IsUppercase(s: string) -> booleanNur Großbuchstaben

Weitere Validierungen

FunctionSignaturDescription
IsInRange(value: number, min: number, max: number) -> booleanWertebereich prüfen
MatchesPattern(text: string, pattern: string) -> booleanRegex-Match

Hashing Builtins

Hash-Functionen

FunctionSignaturDescription
HashString(s: string) -> numberString hashen
HashNumber(n: number) -> numberNumber hashen
SimpleRandom(seed: number) -> numberPseudo-Zufallszahl

String-Analyse

FunctionSignaturDescription
AreAnagrams(s1: string, s2: string) -> booleanChecks Anagramme
IsPalindrome(s: string) -> booleanChecks Palindrom
CountOccurrences(text: string, pattern: string) -> numberVorkommen zählen
RemoveDuplicates(s: string) -> stringDuplikate entfernen
UniqueCharacters(s: string) -> stringEindeutige Zeichen
ReverseWords(s: string) -> stringWörter umkehren
TitleCase(s: string) -> stringTitle Case Format

DeepMind Builtins (Higher-Order Functions)

Kontrollfluss

FunctionSignaturDescription
RepeatAction(times: number, action: () -> void) -> voidAktion n-mal wiederholen
DelayedSuggestion(action: () -> void, delay: number) -> voidVerzögerte Ausführung
IfTranced(cond: boolean, then: () -> void, else: () -> void) -> voidBedingte Ausführung

Schleifen

FunctionSignaturDescription
RepeatUntil(action: () -> void, condition: () -> boolean) -> voidWiederhole bis Bedingung wahr
RepeatWhile(condition: () -> boolean, action: () -> void) -> voidWiederhole solange wahr

Functionskomposition

FunctionSignaturDescription
Compose(f: B -> C, g: A -> B) -> (A -> C)Functionskomposition f(g(x))
Pipe(f: A -> B, g: B -> C) -> (A -> C)Functions-Pipeline g(f(x))

Fehlerbehandlung

FunctionSignaturDescription
TryOrAwaken(try: () -> void, catch: (error: string) -> void) -> voidTry-Catch
EnsureAwakening(main: () -> void, cleanup: () -> void) -> voidTry-Finally

Weitere

FunctionSignaturDescription
SequentialTrance(actions: (() -> void)[]) -> voidAktionen sequentiell ausführen
MeasureTranceDepth(action: () -> void) -> numberAusführungszeit messen
Memoize(f: A -> R) -> (A -> R)Function mit Caching

Usageshinweise

Namenskonventionen

  • PascalCase für Functionsnamen (z.B. CalculateMean, ToUpper)
  • Case-Insensitive Matching beim Aufruf
  • Typ-Parameters T für generische Functionen

Fehlerbehandlung

  • Functionen die fehlschlagen können werfen Runtime-Errors
  • Use TryOrAwaken für Fehlerbehandlung
  • Validiere Inputn mit Validation-Builtins

Performance

  • Array-Operationen erstellen neue Arrays (immutabel)
  • Use Memoize für teure Berechnungen
  • MeasureTranceDepth für Performance-Profiling

See auch

Released under the MIT License.