Skip to content

Builtin Functions Overview

HypnoScript offers a comprehensive standard library with over 110 built-in functions in the Rust edition. These functions are available directly in the language and require no additional imports.

Categories

🧠 Core & Hypnotic Functions

Basic I/O, conversion, and hypnotic special functions.

FunctionDescriptionExample
observe(text)Standard output with line breakobserve "Hello World";
whisper(text)Output without line breakwhisper "Part1"; whisper "Part2";
command(text)Imperative output (uppercase)command "Important!";
drift(ms)Pause/Sleep in millisecondsdrift(2000);
DeepTrance(duration)Deep trance inductionDeepTrance(5000);
HypnoticCountdown(from)Hypnotic countdownHypnoticCountdown(10);
TranceInduction(name)Complete trance inductionTranceInduction("Max");
ToInt(value)Convert to integerToInt(3.14)3
ToString(value)Convert to stringToString(42)"42"
ToBoolean(value)Convert to booleanToBoolean("true")true

🔢 Math Functions

Comprehensive mathematical operations and calculations.

CategoryFunctions
TrigonometrySin, Cos, Tan
Roots & PowersSqrt, Pow
LogarithmsLog (ln), Log10
RoundingAbs, Floor, Ceil, Round, Clamp
Min/MaxMin, Max
Number TheoryFactorial, Gcd, Lcm, IsPrime, Fibonacci

Example:

hyp
induce result: number = Sqrt(16);  // 4.0
induce isPrime: boolean = IsPrime(17);  // true
induce fib: number = Fibonacci(10);  // 55

📝 String Functions

Functions for string manipulation and analysis.

CategoryFunctions
BasicsLength, ToUpper, ToLower, Trim, Reverse, Capitalize
SearchIndexOf, Contains, StartsWith, EndsWith
ManipulationReplace, Split, Substring, Repeat
PaddingPadLeft, PadRight
ChecksIsEmpty, IsWhitespace

Example:

hyp
induce text: string = "  Hello World  ";
induce cleaned: string = Trim(text);  // "Hello World"
induce upper: string = ToUpper(cleaned);  // "HELLO WORLD"
induce words: string[] = Split(cleaned, " ");  // ["Hello", "World"]

📦 Array Functions

Functions for working with arrays and lists.

CategoryFunctions
BasicsLength, IsEmpty, Get, IndexOf, Contains
TransformationReverse, Sort, Distinct
AggregationSum, Average, Min, Max
SlicingFirst, Last, Take, Skip, Slice
MoreJoin, Count

Example:

hyp
induce numbers: number[] = [5, 2, 8, 1, 9];
induce sorted: number[] = Sort(numbers);  // [1, 2, 5, 8, 9]
induce sum: number = Sum(numbers);  // 25
induce avg: number = Average(numbers);  // 5.0

→ Detailed Array Functions

📊 Statistics Functions

Functions for statistical calculations and analysis.

CategoryFunctions
Central TendencyCalculateMean, CalculateMedian, CalculateMode
DispersionCalculateVariance, CalculateStandardDeviation, CalculateRange, CalculatePercentile
CorrelationCalculateCorrelation, LinearRegression

Example:

hyp
induce data: number[] = [1, 2, 3, 4, 5];
induce mean: number = CalculateMean(data);  // 3.0
induce stddev: number = CalculateStandardDeviation(data);  // 1.58...

→ Detailed Statistics Functions

🕒 Time & Date

Functions for time and date processing.

CategoryFunctions
Current TimeGetCurrentTime, GetCurrentDate, GetCurrentDateTime
ComponentsGetYear, GetMonth, GetDay, GetHour, GetMinute, GetSecond
CalculationsGetDayOfWeek, GetDayOfYear, IsLeapYear, GetDaysInMonth

Example:

hyp
induce timestamp: number = GetCurrentTime();  // Unix timestamp
induce date: string = GetCurrentDate();  // "2025-01-15"
induce year: number = GetYear();  // 2025

→ Detailed Time/Date Functions

💻 System Functions

Functions for system interaction and information.

CategoryFunctions
System InfoGetOperatingSystem, GetArchitecture, GetCpuCount, GetHostname, GetUsername
DirectoriesGetCurrentDirectory, GetHomeDirectory, GetTempDirectory
EnvironmentGetEnvVar, SetEnvVar, GetArgs
ProcessExit

Example:

hyp
induce os: string = GetOperatingSystem();  // "Windows", "Linux", "macOS"
induce cores: number = GetCpuCount();  // 8
induce home: string = GetHomeDirectory();  // "/home/user" or "C:\\Users\\user"

→ Detailed System Functions

📁 File Functions

Functions for filesystem operations.

CategoryFunctions
Read/WriteReadFile, WriteFile, AppendFile
ManagementDeleteFile, CopyFile, RenameFile
ChecksFileExists, IsFile, IsDirectory
InformationGetFileSize, GetFileExtension, GetFileName, GetParentDirectory
DirectoriesCreateDirectory, ListDirectory

Example:

hyp
if (FileExists("config.txt")) {
    induce content: string = ReadFile("config.txt");
    observe "Config: " + content;
} else {
    WriteFile("config.txt", "default config");
}

→ Detailed File Functions

🧩 CLI & Automation

New builtins help build interactive tools and scripts.

FunctionDescription
CliPromptLocalized text input with default values
CliConfirmYes/No confirmation with Y/n or J/n hint
ParseArgumentsParses CLI arguments into flags and positional parameters
HasFlagChecks if a flag is set
FlagValueReads the value of a flag (--port 80808080)

Example:

hyp
induce args: string[] = GetArgs();
if (HasFlag(args, "help")) {
    observe "Use --port <PORT>";
    Exit(0);
}

induce port = FlagValue(args, "port") ?? "8080";
induce answer = CliPrompt("Service name", "demo", false, "en-US");
induce confirm = CliConfirm("Start deployment?", true, "en-US");

🌐 API & Service Functions

Combines HTTP clients with service health tools.

FunctionDescription
HttpSendGeneral HTTP client (methods, headers, auth, timeout)
HttpGetJsonGET with automatic JSON parsing
HttpPostJsonPOST JSON → JSON (incl. Content-Type)
ServiceHealthCreates health report (uptime, latency, P95, SLO)
RetryScheduleReturns exponential backoff plan with optional jitter
CircuitShouldOpenEvaluates error window for circuit breaker

Example:

hyp
induce response = HttpGetJson("https://api.example.com/status");
if (response.ok != true) {
    observe "API reports error";
}

induce schedule: number[] = RetrySchedule(5, 250, 2.0, 50, 4000);
observe "Retries every " + schedule[0] + "ms";

🧾 Data Formats (JSON & CSV)

FunctionDescription
JsonPrettyFormats JSON for logs
JsonQueryPath query (data.items[0].name)
JsonMergeRecursive merge of two documents
ParseCsvReads CSV (delimiter + header configurable)
CsvSelectColumnsProjects columns by name
CsvToStringBuilds CSV text from table structure

Example:

hyp
induce payload = JsonPretty(ReadFile("response.json"));
induce table = ParseCsv(ReadFile("data.csv"));
induce namesOnly = CsvSelectColumns(table, ["name"]);
WriteFile("names.csv", CsvToString(namesOnly));

✅ Validation

Functions for data validation.

CategoryFunctions
FormatIsValidEmail, IsValidUrl, IsValidPhoneNumber
CharacterIsAlphanumeric, IsAlphabetic, IsNumeric, IsLowercase, IsUppercase
MoreIsInRange, MatchesPattern

Example:

hyp
induce email: string = "user@example.com";
if (IsValidEmail(email)) {
    observe "Valid email!";
}

→ Detailed Validation Functions

🔐 Hashing & String Analysis

Functions for hashing and advanced string operations.

CategoryFunctions
HashingHashString, HashNumber, SimpleRandom
AnalysisAreAnagrams, IsPalindrome, CountOccurrences
TransformationRemoveDuplicates, UniqueCharacters, ReverseWords, TitleCase

Example:

hyp
induce hash: number = HashString("password");
induce isPalin: boolean = IsPalindrome("anna");  // true
induce titleText: string = TitleCase("hello world");  // "Hello World"

→ Detailed Hashing Functions

🧠 DeepMind (Higher-Order Functions)

Advanced functional programming and control flow.

CategoryFunctions
LoopsRepeatAction, RepeatUntil, RepeatWhile
DelayDelayedSuggestion
CompositionCompose, Pipe
Error HandlingTryOrAwaken, EnsureAwakening
MoreIfTranced, SequentialTrance, MeasureTranceDepth, Memoize

Example:

hyp
// Repeat action 5 times
RepeatAction(5, suggestion() {
    observe "Repeated!";
});

// Function composition
suggestion double(x: number): number {
    awaken x * 2;
}

suggestion addTen(x: number): number {
    awaken x + 10;
}

induce composed = Compose(double, addTen);
induce result: number = composed(5);  // double(addTen(5)) = 30

→ Detailed DeepMind Functions

Usage

All Builtin Functions can be used directly in HypnoScript code without imports:

hyp
Focus {
    entrance {
        observe "=== Builtin Functions Demo ===";
    }

    // Array functions
    induce numbers: number[] = [1, 2, 3, 4, 5];
    induce sum: number = Sum(numbers);
    observe "Sum: " + sum;

    // String functions
    induce text: string = "Hello World";
    induce reversed: string = Reverse(text);
    observe "Reversed: " + reversed;

    // Mathematical functions
    induce sqrt: number = Sqrt(16);
    observe "Square root of 16: " + sqrt;

    // System functions
    induce os: string = GetOperatingSystem();
    observe "Operating system: " + os;

    // Validation
    induce isValid: boolean = IsValidEmail("test@example.com");
    observe "Email valid: " + isValid;

    // Statistics
    induce mean: number = CalculateMean([1, 2, 3, 4, 5]);
    observe "Mean: " + mean;

    finale {
        observe "=== Demo completed ===";
    }
} Relax

CLI Command

List all Builtin Functions in the terminal:

bash
hypnoscript builtins

Complete Reference

For a complete alphabetical list of all 110+ functions see:

→ Complete Builtin Reference

Category Index

Next Steps

Released under the MIT License.