Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Standard Library: General functions

alt

[alt: a; ...rest]

Prints the first argument that is not nothing.

call

[call: func; args?]

Calls func with an optional list of argument values.

cat

[cat: ...values]

Prints each argument into the current scope.

either

[either: condition; true-value; false-value]

Prints true-value when condition is true, otherwise false-value.

len

[len: value]

Prints the length of a string, list, map, range, or other length-aware value.

type

[type: value]

Prints the runtime type name of value.

seed

[seed]

Prints the currently active RNG seed as an int.

tap

[tap: ...]

Consumes arguments and produces no output. This is useful as a no-op sink in pipe chains.

print

[print: ...values]

Prints values directly into the caller's output scope.

range

[range: a; b?; step?]

Builds a half-open integer range.

require

[require: module-path]

Imports a module through the active module resolver.

See Modules for the default behavior and Module Resolvers for host customization.

irange

[irange: a; b?; step?]

Builds an inclusive integer range.

fork

[fork: seed?]

Pushes a derived RNG onto the RNG stack. Integer and string seeds are both supported.

unfork

[unfork]

Pops the most recent derived RNG and resumes the previous RNG state.

try

[try: context; handler?]

Runs context and optionally dispatches runtime failures to handler.

ds-request

[ds-request: id; ...args]

Calls a registered data source by ID and prints its result.

See Data Sources for host registration, error behavior, and security guidance.

ds-query-sources

[ds-query-sources]

Prints the list of currently registered data-source IDs.

See Data Sources.

proto

[proto: map]

Prints the prototype map of map, or nothing if no prototype is set.

Prototype maps are used only as lookup fallbacks for missing keys. They do not merge physically into the map, and they are not treated as bound objects.

Example

<$obj = (::)>
<$proto = (:: flavor = vanilla)>
[set-proto: <obj>; <proto>]

[proto: <obj>]\n
<obj/flavor>

##
  Output:

  (:: flavor = vanilla)
  vanilla
##

set-proto

[set-proto: map; proto?]

Sets or clears the prototype map for map.

Pass <> to clear the current prototype.

Prototype assignment is validated eagerly. If a call to [set-proto] would create a cycle, Ranty raises a runtime error instead of allowing the assignment.

Examples

# Attach a prototype
<$obj = (::)>
<$proto = (:: flavor = vanilla)>
[set-proto: <obj>; <proto>]
<obj/flavor>
# -> vanilla
# Clear a prototype
<$obj = (::)>
<$proto = (:: flavor = vanilla)>
[set-proto: <obj>; <proto>]
[set-proto: <obj>; <>]
<obj/flavor ? missing>
# -> missing
# Cycles are rejected
<$a = (::)>
<$b = (::)>
[set-proto: <a>; <b>]
[set-proto: <b>; <a>] # runtime error

error

[error: message?]

Raises a USER_ERROR runtime failure with an optional message.