spec/coroutines.sx: define-library with make-coroutine, coroutine-resume, coroutine-yield, coroutine?, coroutine-alive?. Built on existing perform/ cek-step-loop/cek-resume suspension machinery. spec/tests/test-coroutines.sx: 17 tests — multi-yield, final return, arg passthrough, alive? predicate, nested coroutines, recursive iteration, independent coroutine interleaving. Key: coroutine body must use (define loop (fn…)) not named let — named let transpiles to cek_call→cek_run which rejects IO suspension. All 17/17 pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
802 lines
20 KiB
Plaintext
802 lines
20 KiB
Plaintext
;; ==========================================================================
|
|
;; primitives.sx — Irreducible primitive set
|
|
;;
|
|
;; These are the functions that CANNOT be written in SX because they
|
|
;; require host-native capabilities: native arithmetic, type inspection,
|
|
;; host string library, host math, host I/O, host data structures.
|
|
;;
|
|
;; Everything else lives in spec/stdlib.sx as library functions.
|
|
;;
|
|
;; The primitive set is the out-of-band floor. The fewer primitives,
|
|
;; the tighter the strange loop and the more of the system is auditable,
|
|
;; verifiable, portable SX.
|
|
;;
|
|
;; Format:
|
|
;; (define-primitive "name"
|
|
;; :params (param1 param2 &rest rest)
|
|
;; :returns "type"
|
|
;; :doc "description")
|
|
;;
|
|
;; Typed params use (name :as type) syntax.
|
|
;; Modules: (define-module :name) scopes subsequent entries.
|
|
;;
|
|
;; Functions moved to stdlib.sx (no longer primitives):
|
|
;; Comparison: != <= >= eq? eqv? equal?
|
|
;; Predicates: nil? boolean? number? string? list? dict?
|
|
;; continuation? empty? odd? even? zero? contains?
|
|
;; Arithmetic: inc dec abs ceil round min max clamp
|
|
;; Collections: first last rest nth cons append reverse flatten
|
|
;; range chunk-every zip-pairs vals has-key? merge
|
|
;; assoc dissoc into
|
|
;; Strings: upcase downcase string-length substring
|
|
;; string-contains? starts-with? ends-with?
|
|
;; split join replace
|
|
;; Logic: not
|
|
;; Text: pluralize escape assert parse-datetime
|
|
;; ==========================================================================
|
|
;; --------------------------------------------------------------------------
|
|
;; Core — Arithmetic
|
|
;; --------------------------------------------------------------------------
|
|
(define-module :core.arithmetic)
|
|
|
|
(define-primitive
|
|
"+"
|
|
:params (&rest (args :as number))
|
|
:returns "number"
|
|
:doc "Sum all arguments. Returns integer iff all args are exact integers (float contagion)."
|
|
:body (reduce (fn (a b) (native-add a b)) 0 args))
|
|
|
|
(define-primitive
|
|
"-"
|
|
:params ((a :as number) &rest (b :as number))
|
|
:returns "number"
|
|
:doc "Subtract. Unary: negate. Binary: a - b. Float contagion: returns integer iff all args are integers."
|
|
:body (if (empty? b) (native-neg a) (native-sub a (first b))))
|
|
|
|
(define-primitive
|
|
"*"
|
|
:params (&rest (args :as number))
|
|
:returns "number"
|
|
:doc "Multiply all arguments. Float contagion: integer result iff all args are exact integers."
|
|
:body (reduce (fn (a b) (native-mul a b)) 1 args))
|
|
|
|
(define-primitive
|
|
"/"
|
|
:params ((a :as number) (b :as number))
|
|
:returns "float"
|
|
:doc "Divide a by b. Always returns inexact float."
|
|
:body (native-div a b))
|
|
|
|
(define-primitive
|
|
"mod"
|
|
:params ((a :as number) (b :as number))
|
|
:returns "number"
|
|
:doc "Modulo a % b. Returns integer iff both args are integers."
|
|
:body (native-mod a b))
|
|
|
|
(define-primitive
|
|
"random-int"
|
|
:params ((low :as number) (high :as number))
|
|
:returns "number"
|
|
:doc "Random integer in [low, high] inclusive."
|
|
:body (native-random-int low high))
|
|
|
|
(define-primitive
|
|
"json-encode"
|
|
:params (value)
|
|
:returns "string"
|
|
:doc "Encode value as JSON string with indentation.")
|
|
|
|
(define-primitive
|
|
"sqrt"
|
|
:params ((x :as number))
|
|
:returns "number"
|
|
:doc "Square root.")
|
|
|
|
(define-primitive
|
|
"pow"
|
|
:params ((x :as number) (n :as number))
|
|
:returns "number"
|
|
:doc "x raised to power n.")
|
|
|
|
(define-primitive
|
|
"abs"
|
|
:params ((x :as number))
|
|
:returns "number"
|
|
:doc "Absolute value.")
|
|
|
|
(define-primitive
|
|
"floor"
|
|
:params ((x :as number))
|
|
:returns "integer"
|
|
:doc "Floor toward negative infinity — returns exact integer.")
|
|
|
|
(define-primitive
|
|
"ceil"
|
|
:params ((x :as number))
|
|
:returns "integer"
|
|
:doc "Ceiling toward positive infinity — returns exact integer.")
|
|
|
|
(define-primitive
|
|
"round"
|
|
:params ((x :as number) &rest (ndigits :as number))
|
|
:returns "number"
|
|
:doc "Round to ndigits decimal places (default 0). Returns integer when ndigits is 0.")
|
|
|
|
(define-primitive
|
|
"truncate"
|
|
:params ((x :as number))
|
|
:returns "integer"
|
|
:doc "Truncate toward zero — returns exact integer.")
|
|
|
|
(define-primitive
|
|
"remainder"
|
|
:params (((a :as number) (b :as number)))
|
|
:returns "number"
|
|
:doc "Remainder — sign follows dividend.")
|
|
|
|
(define-primitive
|
|
"modulo"
|
|
:params (((a :as number) (b :as number)))
|
|
:returns "number"
|
|
:doc "Modulo — sign follows divisor.")
|
|
|
|
(define-primitive
|
|
"exact?"
|
|
:params ((x :as number))
|
|
:returns "boolean"
|
|
:doc "True if x is an exact integer (not an inexact float).")
|
|
|
|
(define-primitive
|
|
"inexact?"
|
|
:params ((x :as number))
|
|
:returns "boolean"
|
|
:doc "True if x is an inexact float (not an exact integer).")
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Core — Comparison
|
|
;; --------------------------------------------------------------------------
|
|
(define-primitive
|
|
"exact->inexact"
|
|
:params ((x :as number))
|
|
:returns "float"
|
|
:doc "Convert exact integer to inexact float. Floats pass through unchanged.")
|
|
|
|
(define-primitive
|
|
"inexact->exact"
|
|
:params ((x :as number))
|
|
:returns "integer"
|
|
:doc "Convert inexact float to nearest exact integer (truncates). Integers pass through unchanged.")
|
|
|
|
(define-primitive
|
|
"make-vector"
|
|
:params ((n :as number) (fill :as any :optional true))
|
|
:returns "vector"
|
|
:doc "Create vector of length n, each element initialised to fill (default nil).")
|
|
|
|
(define-primitive
|
|
"vector"
|
|
:params (:rest (elts :as any))
|
|
:returns "vector"
|
|
:doc "Construct a vector from its arguments.")
|
|
|
|
(define-primitive
|
|
"vector?"
|
|
:params ((x :as any))
|
|
:returns "boolean"
|
|
:doc "True if x is a vector.")
|
|
|
|
(define-primitive
|
|
"vector-length"
|
|
:params ((v :as vector))
|
|
:returns "number"
|
|
:doc "Number of elements in vector v.")
|
|
|
|
(define-primitive
|
|
"vector-ref"
|
|
:params ((v :as vector) (i :as number))
|
|
:returns "any"
|
|
:doc "Element at 0-based index i. Error if out of bounds.")
|
|
|
|
(define-primitive
|
|
"vector-set!"
|
|
:params ((v :as vector) (i :as number) (val :as any))
|
|
:returns "nil"
|
|
:doc "Mutate element at index i to val. Error if out of bounds.")
|
|
|
|
(define-primitive
|
|
"vector->list"
|
|
:params ((v :as vector))
|
|
:returns "list"
|
|
:doc "Convert vector to a fresh list.")
|
|
|
|
(define-primitive
|
|
"list->vector"
|
|
:params ((l :as list))
|
|
:returns "vector"
|
|
:doc "Convert list to a fresh vector.")
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Core — Predicates
|
|
;; --------------------------------------------------------------------------
|
|
(define-primitive
|
|
"vector-fill!"
|
|
:params ((v :as vector) (val :as any))
|
|
:returns "nil"
|
|
:doc "Set every element of v to val in place.")
|
|
|
|
(define-primitive
|
|
"vector-copy"
|
|
:params ((v :as vector)
|
|
(start :as number :optional true)
|
|
(end :as number :optional true))
|
|
:returns "vector"
|
|
:doc "Shallow copy of vector, optionally sliced from start (inclusive) to end (exclusive).")
|
|
|
|
(define-primitive
|
|
"min"
|
|
:params (&rest (args :as number))
|
|
:returns "number"
|
|
:doc "Minimum. Single list arg or variadic.")
|
|
|
|
(define-primitive
|
|
"max"
|
|
:params (&rest (args :as number))
|
|
:returns "number"
|
|
:doc "Maximum. Single list arg or variadic.")
|
|
|
|
(define-primitive
|
|
"clamp"
|
|
:params ((x :as number) (lo :as number) (hi :as number))
|
|
:returns "number"
|
|
:doc "Clamp x to range [lo, hi]."
|
|
:body (max lo (min hi x)))
|
|
|
|
(define-primitive
|
|
"inc"
|
|
:params ((n :as number))
|
|
:returns "number"
|
|
:doc "Increment by 1."
|
|
:body (+ n 1))
|
|
|
|
(define-primitive
|
|
"dec"
|
|
:params ((n :as number))
|
|
:returns "number"
|
|
:doc "Decrement by 1."
|
|
:body (- n 1))
|
|
|
|
(define-module :core.comparison)
|
|
|
|
(define-primitive
|
|
"="
|
|
:params (a b)
|
|
:returns "boolean"
|
|
:doc "Deep structural equality. Alias for equal?.")
|
|
|
|
(define-primitive
|
|
"!="
|
|
:params (a b)
|
|
:returns "boolean"
|
|
:doc "Inequality."
|
|
:body (not (= a b)))
|
|
|
|
(define-primitive
|
|
"eq?"
|
|
:params (a b)
|
|
:returns "boolean"
|
|
:doc "Identity equality. True only if a and b are the same object."
|
|
:body (identical? a b))
|
|
|
|
(define-primitive
|
|
"eqv?"
|
|
:params (a b)
|
|
:returns "boolean"
|
|
:doc "Equivalent value for atoms, identity for compound objects.\n Returns true for identical objects (eq?), and also for numbers,\n strings, booleans, and nil with the same value. For lists, dicts,\n lambdas, and components, only true if same identity.")
|
|
|
|
(define-primitive
|
|
"equal?"
|
|
:params (a b)
|
|
:returns "boolean"
|
|
:doc "Deep structural equality. Recursively compares collections."
|
|
:body (= a b))
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Core — Logic
|
|
;; --------------------------------------------------------------------------
|
|
(define-primitive
|
|
"<"
|
|
:params ((a :as number) (b :as number))
|
|
:returns "boolean"
|
|
:doc "Less than.")
|
|
|
|
(define-primitive
|
|
">"
|
|
:params ((a :as number) (b :as number))
|
|
:returns "boolean"
|
|
:doc "Greater than.")
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Core — Strings
|
|
;; --------------------------------------------------------------------------
|
|
(define-primitive
|
|
"<="
|
|
:params ((a :as number) (b :as number))
|
|
:returns "boolean"
|
|
:doc "Less than or equal."
|
|
:body (or (< a b) (= a b)))
|
|
|
|
(define-primitive
|
|
">="
|
|
:params ((a :as number) (b :as number))
|
|
:returns "boolean"
|
|
:doc "Greater than or equal."
|
|
:body (or (> a b) (= a b)))
|
|
|
|
(define-module :core.predicates)
|
|
|
|
(define-primitive
|
|
"odd?"
|
|
:params ((n :as number))
|
|
:returns "boolean"
|
|
:doc "True if n is odd."
|
|
:body (= (mod n 2) 1))
|
|
|
|
(define-primitive
|
|
"even?"
|
|
:params ((n :as number))
|
|
:returns "boolean"
|
|
:doc "True if n is even."
|
|
:body (= (mod n 2) 0))
|
|
|
|
(define-primitive
|
|
"zero?"
|
|
:params ((n :as number))
|
|
:returns "boolean"
|
|
:doc "True if n is zero."
|
|
:body (= n 0))
|
|
|
|
(define-primitive
|
|
"nil?"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "True if x is nil/null/None."
|
|
:body (= (type-of x) "nil"))
|
|
|
|
(define-primitive
|
|
"boolean?"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "True if x is a boolean (true or false)."
|
|
:body (= (type-of x) "boolean"))
|
|
|
|
(define-primitive
|
|
"number?"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "True if x is any number — exact integer or inexact float."
|
|
:body (or (= (type-of x) "number") (integer? x)))
|
|
|
|
(define-primitive
|
|
"integer?"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "True if x is an exact integer, or a float with no fractional part (e.g. 1.0).")
|
|
|
|
(define-primitive
|
|
"float?"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "True if x is an inexact float (Number type). Does not match exact integers.")
|
|
|
|
(define-primitive
|
|
"string?"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "True if x is a string."
|
|
:body (= (type-of x) "string"))
|
|
|
|
(define-primitive
|
|
"list?"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "True if x is a list/array."
|
|
:body (= (type-of x) "list"))
|
|
|
|
(define-primitive
|
|
"dict?"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "True if x is a dict/map."
|
|
:body (= (type-of x) "dict"))
|
|
|
|
(define-primitive
|
|
"continuation?"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "True if x is a captured continuation."
|
|
:body (= (type-of x) "continuation"))
|
|
|
|
(define-primitive
|
|
"empty?"
|
|
:params (coll)
|
|
:returns "boolean"
|
|
:doc "True if coll is nil or has length 0."
|
|
:body (or (nil? coll) (= (len coll) 0)))
|
|
|
|
(define-primitive
|
|
"contains?"
|
|
:params (coll key)
|
|
:returns "boolean"
|
|
:doc "True if coll contains key. Strings: substring check. Dicts: key check. Lists: membership.")
|
|
|
|
(define-module :core.logic)
|
|
|
|
(define-primitive
|
|
"not"
|
|
:params (x)
|
|
:returns "boolean"
|
|
:doc "Logical negation. Note: and/or are special forms, not primitives."
|
|
:body (if x false true))
|
|
|
|
(define-module :core.strings)
|
|
|
|
(define-primitive
|
|
"str"
|
|
:params (&rest args)
|
|
:returns "string"
|
|
:doc "Concatenate all args as strings. nil → empty string, bool → true/false.")
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Core — Collections
|
|
;; --------------------------------------------------------------------------
|
|
(define-primitive
|
|
"concat"
|
|
:params (&rest (colls :as list))
|
|
:returns "list"
|
|
:doc "Concatenate multiple lists into one. Skips nil values.")
|
|
|
|
(define-primitive
|
|
"upper"
|
|
:params ((s :as string))
|
|
:returns "string"
|
|
:doc "Uppercase string.")
|
|
|
|
(define-primitive
|
|
"upcase"
|
|
:params ((s :as string))
|
|
:returns "string"
|
|
:doc "Alias for upper. Uppercase string.")
|
|
|
|
(define-primitive
|
|
"lower"
|
|
:params ((s :as string))
|
|
:returns "string"
|
|
:doc "Lowercase string.")
|
|
|
|
(define-primitive
|
|
"downcase"
|
|
:params ((s :as string))
|
|
:returns "string"
|
|
:doc "Alias for lower. Lowercase string.")
|
|
|
|
(define-primitive
|
|
"string-length"
|
|
:params ((s :as string))
|
|
:returns "number"
|
|
:doc "Length of string in characters.")
|
|
|
|
(define-primitive
|
|
"char-from-code"
|
|
:params ((n :as number))
|
|
:returns "string"
|
|
:doc "Convert Unicode code point to single-character string.")
|
|
|
|
(define-primitive
|
|
"substring"
|
|
:params ((s :as string) (start :as number) (end :as number))
|
|
:returns "string"
|
|
:doc "Extract substring from start (inclusive) to end (exclusive).")
|
|
|
|
(define-primitive
|
|
"string-contains?"
|
|
:params ((s :as string) (needle :as string))
|
|
:returns "boolean"
|
|
:doc "True if string s contains substring needle.")
|
|
|
|
(define-primitive
|
|
"trim"
|
|
:params ((s :as string))
|
|
:returns "string"
|
|
:doc "Strip leading/trailing whitespace.")
|
|
|
|
(define-primitive
|
|
"split"
|
|
:params ((s :as string) &rest (sep :as string))
|
|
:returns "list"
|
|
:doc "Split string by separator (default space).")
|
|
|
|
(define-primitive
|
|
"join"
|
|
:params ((sep :as string) (coll :as list))
|
|
:returns "string"
|
|
:doc "Join collection items with separator string.")
|
|
|
|
(define-primitive
|
|
"replace"
|
|
:params ((s :as string) (old :as string) (new :as string))
|
|
:returns "string"
|
|
:doc "Replace all occurrences of old with new in s.")
|
|
|
|
(define-primitive
|
|
"slice"
|
|
:params (coll (start :as number) &rest (end :as number))
|
|
:returns "any"
|
|
:doc "Slice a string or list from start to end (exclusive). End is optional.")
|
|
|
|
(define-primitive
|
|
"index-of"
|
|
:params ((s :as string) (needle :as string) &rest (from :as number))
|
|
:returns "number"
|
|
:doc "Index of first occurrence of needle in s, or -1 if not found. Optional start index.")
|
|
|
|
(define-primitive
|
|
"starts-with?"
|
|
:params ((s :as string) (prefix :as string))
|
|
:returns "boolean"
|
|
:doc "True if string s starts with prefix.")
|
|
|
|
(define-primitive
|
|
"ends-with?"
|
|
:params ((s :as string) (suffix :as string))
|
|
:returns "boolean"
|
|
:doc "True if string s ends with suffix.")
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Core — Dict operations
|
|
;; --------------------------------------------------------------------------
|
|
(define-module :core.collections)
|
|
|
|
(define-primitive
|
|
"list"
|
|
:params (&rest args)
|
|
:returns "list"
|
|
:doc "Create a list from arguments.")
|
|
|
|
(define-primitive
|
|
"dict"
|
|
:params (&rest pairs)
|
|
:returns "dict"
|
|
:doc "Create a dict from key/value pairs: (dict :a 1 :b 2).")
|
|
|
|
(define-primitive
|
|
"range"
|
|
:params ((start :as number) (end :as number) &rest (step :as number))
|
|
:returns "list"
|
|
:doc "Integer range [start, end) with optional step.")
|
|
|
|
(define-primitive
|
|
"get"
|
|
:params (coll key &rest default)
|
|
:returns "any"
|
|
:doc "Get value from dict by key, or list by index. Optional default.")
|
|
|
|
(define-primitive
|
|
"len"
|
|
:params (coll)
|
|
:returns "number"
|
|
:doc "Length of string, list, or dict.")
|
|
|
|
(define-primitive
|
|
"first"
|
|
:params ((coll :as list))
|
|
:returns "any"
|
|
:doc "First element, or nil if empty.")
|
|
|
|
(define-primitive
|
|
"last"
|
|
:params ((coll :as list))
|
|
:returns "any"
|
|
:doc "Last element, or nil if empty.")
|
|
|
|
(define-primitive
|
|
"rest"
|
|
:params ((coll :as list))
|
|
:returns "list"
|
|
:doc "All elements except the first.")
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Stdlib — Format
|
|
;; --------------------------------------------------------------------------
|
|
(define-primitive
|
|
"nth"
|
|
:params ((coll :as list) (n :as number))
|
|
:returns "any"
|
|
:doc "Element at index n, or nil if out of bounds.")
|
|
|
|
(define-primitive
|
|
"cons"
|
|
:params (x (coll :as list))
|
|
:returns "list"
|
|
:doc "Prepend x to coll.")
|
|
|
|
(define-primitive
|
|
"append"
|
|
:params ((coll :as list) x)
|
|
:returns "list"
|
|
:doc "If x is a list, concatenate. Otherwise append x as single element.")
|
|
|
|
(define-primitive
|
|
"append!"
|
|
:params ((coll :as list) x)
|
|
:returns "list"
|
|
:doc "Mutate coll by appending x in-place. Returns coll.")
|
|
|
|
(define-primitive
|
|
"reverse"
|
|
:params ((coll :as list))
|
|
:returns "list"
|
|
:doc "Return coll in reverse order.")
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Stdlib — Text
|
|
;; --------------------------------------------------------------------------
|
|
(define-primitive
|
|
"flatten"
|
|
:params ((coll :as list))
|
|
:returns "list"
|
|
:doc "Flatten one level of nesting. Nested lists become top-level elements.")
|
|
|
|
(define-primitive
|
|
"chunk-every"
|
|
:params ((coll :as list) (n :as number))
|
|
:returns "list"
|
|
:doc "Split coll into sub-lists of size n.")
|
|
|
|
(define-primitive
|
|
"zip-pairs"
|
|
:params ((coll :as list))
|
|
:returns "list"
|
|
:doc "Consecutive pairs: (1 2 3 4) → ((1 2) (2 3) (3 4)).")
|
|
|
|
(define-module :core.dict)
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Stdlib — Style
|
|
;; --------------------------------------------------------------------------
|
|
;; --------------------------------------------------------------------------
|
|
;; Stdlib — Debug
|
|
;; --------------------------------------------------------------------------
|
|
(define-primitive
|
|
"keys"
|
|
:params ((d :as dict))
|
|
:returns "list"
|
|
:doc "List of dict keys.")
|
|
|
|
(define-primitive
|
|
"vals"
|
|
:params ((d :as dict))
|
|
:returns "list"
|
|
:doc "List of dict values.")
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; Type introspection — platform primitives
|
|
;; --------------------------------------------------------------------------
|
|
(define-primitive
|
|
"merge"
|
|
:params (&rest (dicts :as dict))
|
|
:returns "dict"
|
|
:doc "Merge dicts left to right. Later keys win. Skips nil.")
|
|
|
|
(define-primitive
|
|
"has-key?"
|
|
:params ((d :as dict) key)
|
|
:returns "boolean"
|
|
:doc "True if dict d contains key.")
|
|
|
|
(define-primitive
|
|
"assoc"
|
|
:params ((d :as dict) &rest pairs)
|
|
:returns "dict"
|
|
:doc "Return new dict with key/value pairs added/overwritten.")
|
|
|
|
(define-primitive
|
|
"dissoc"
|
|
:params ((d :as dict) &rest keys)
|
|
:returns "dict"
|
|
:doc "Return new dict with keys removed.")
|
|
|
|
(define-primitive
|
|
"dict-set!"
|
|
:params ((d :as dict) key val)
|
|
:returns "any"
|
|
:doc "Mutate dict d by setting key to val in-place. Returns val.")
|
|
|
|
(define-primitive
|
|
"into"
|
|
:params (target coll)
|
|
:returns "any"
|
|
:doc "Pour coll into target. List target: convert to list. Dict target: convert pairs to dict.")
|
|
|
|
(define-module :stdlib.format)
|
|
|
|
(define-primitive
|
|
"format-date"
|
|
:params ((date-str :as string) (fmt :as string))
|
|
:returns "string"
|
|
:doc "Parse ISO date string and format with strftime-style format.")
|
|
|
|
(define-primitive
|
|
"format-decimal"
|
|
:params ((val :as number) &rest (places :as number))
|
|
:returns "string"
|
|
:doc "Format number with fixed decimal places (default 2).")
|
|
|
|
(define-primitive
|
|
"parse-int"
|
|
:params (val &rest default)
|
|
:returns "number"
|
|
:doc "Parse string to integer with optional default on failure.")
|
|
|
|
(define-primitive
|
|
"parse-datetime"
|
|
:params ((s :as string))
|
|
:returns "string"
|
|
:doc "Parse datetime string — identity passthrough (returns string or nil).")
|
|
|
|
(define-module :stdlib.text)
|
|
|
|
(define-primitive
|
|
"pluralize"
|
|
:params ((count :as number) &rest (forms :as string))
|
|
:returns "string"
|
|
:doc "Pluralize: (pluralize 1) → \"\", (pluralize 2) → \"s\". Or (pluralize n \"item\" \"items\").")
|
|
|
|
(define-primitive
|
|
"escape"
|
|
:params ((s :as string))
|
|
:returns "string"
|
|
:doc "HTML-escape a string (&, <, >, \", ').")
|
|
|
|
(define-primitive
|
|
"strip-tags"
|
|
:params ((s :as string))
|
|
:returns "string"
|
|
:doc "Remove HTML tags from string.")
|
|
|
|
(define-module :stdlib.debug)
|
|
|
|
(define-primitive
|
|
"assert"
|
|
:params (condition &rest message)
|
|
:returns "boolean"
|
|
:doc "Assert condition is truthy; raise error with message if not.")
|
|
|
|
(define-module :stdlib.types)
|
|
|
|
(define-primitive
|
|
"type-of"
|
|
:params (x)
|
|
:returns "string"
|
|
:doc "Return type name: number, string, boolean, nil, symbol, keyword, list, dict, lambda, component, island, macro.")
|
|
|
|
(define-primitive
|
|
"symbol-name"
|
|
:params ((sym :as symbol))
|
|
:returns "string"
|
|
:doc "Return the name string of a symbol.")
|
|
|
|
(define-primitive
|
|
"keyword-name"
|
|
:params ((kw :as keyword))
|
|
:returns "string"
|
|
:doc "Return the name string of a keyword.")
|
|
|
|
(define-primitive
|
|
"sx-parse"
|
|
:params ((source :as string))
|
|
:returns "list"
|
|
:doc "Parse SX source string into a list of AST expressions.")
|
|
|
|
(define-module :stdlib.coroutines)
|