Range
Range[start, step, end]
Generates a list of numbers from start to end (inclusive), incrementing by step.
- Returns a
ListofNumbers.
Range[1, 2, 9]; (* => {1, 3, 5, 7, 9} *)
Range[10, -2, 4]; (* => {10, 8, 6, 4} *)
Read
Read[path]
Read[path, count]
Reads the contents of a file.
- With a single argument, reads the entire file as a UTF‑8
String. - With a
countargument, readscountbytes from the file and returns aListofNumbers.
Read["hello.txt"]; (* => "world" *)
Read["/dev/urandom", 4]; (* => {1509190865, 2408416647, 3954905998, 328341581} *)
Read["/dev/urandom"];
(*? Error[ksl::builtin::Read]: Unable to read contents of file at `/dev/urandom` with `operation interrupted`. *)
ReCapture
ReCapture[pattern, s, captures]
Captures values from named groups in the first match of the regular expression pattern within string s.
capturesis a list ofAtoms specifying which named groups to extract.- Returns a
Listof the same length ascaptures. Each position contains the captured substring if the corresponding named group participated in the match; otherwiseUnit[]. - If the regular expression is invalid or no match is found anywhere in
s, an error is raised.
ReCapture[
"^hello, (?<name>(.+))! Today is (?<state>(.+))\.$",
"hello, Kevin! Today is good.",
{ #name, #state }
];
(* => {"Kevin", "good"} *)
(* Requesting only a subset of groups *)
ReCapture[
"^hello, (?<name>(.+))! Today is (?<state>(.+))\.$",
"hello, Kevin! Today is good.",
{ #name }
];
(* => {"Kevin"} *)
(* Requesting a non‑existent group name *)
ReCapture[
"^hello, (?<name>(.+))! Today is (?<state>(.+))\.$",
"hello, Kevin! Today is good.",
{ #oops }
];
(* => {()} *)
ReceiveValue
ReceiveValue[rx]
Receives a value from the channel receiver rx.
Blocks until a value is available.
- Returns the value sent via
SendValue.
OpenChannel[rx, tx];
SendValue[tx, "hello"];
ReceiveValue[rx]; (* => "hello" *)
Reduce
Reduce[list, fun, initial]
Reduces (folds) list from left to right using the binary function fun, starting with initial.
funmust accept two arguments: the accumulator and the current element.- Returns the final accumulated value.
Reduce[{ "a", "b", "c" }, Concat, "!"]; (* => "!abc" *)
Reduce[{ 1, 2, 3 }, Add, 0]; (* => 6 *)
Rem
Rem[m, n]
Computes the remainder of m divided by n, truncating toward zero.
- Returns a
Number.
Rem[7, 3]; (* => 1 *)
Rem[-7, 3]; (* => -1 *)
Rem[7, -3]; (* => 1 *)
ReMatch
ReMatch[pattern, s]
Tests whether the regular expression pattern matches any part of string s.
- Returns
#tif a match is found anywhere ins, otherwise#f.
ReMatch["^[1-9]+$", "1231"]; (* => #t *)
ReMatch["^[1-9]+$", "12301"]; (* => #f *)
ReMatch["[1-9]+", "12301"]; (* => #t *)
Remove
Remove[list, index]
Returns a new list with the element at the 1‑based index removed.
The original list is unchanged.
- Returns a
List. - An error is raised if
indexis out of bounds.
Remove[{ 1, 2, 3 }, 2]; (* => { 1, 3 } *)
Remove[{ }, 2];
(*? Error[ksl::builtin::Remove]: Index `2` is out of boundary. *)
Reverse
Reverse[list]
Returns a new list with the elements of list in reverse order.
The original list is unchanged.
- Returns a
List.
Reverse[{ "a", "b", "c" }]; (* => { "c", "b", "a" } *)
Rm
Rm[path]
Removes the file or directory at path recursively (equivalent to rm -r).
This operation is irreversible.
- Returns
Unit[]. - An error is raised if
pathdoes not exist or permissions are insufficient.
Rm["/tmp/notable"];
(*? Error[ksl::builtin::Rm]: Failed to get the metadata of `/tmp/notable` with: `No such file or directory (os error 2)` *)
Round
Round[n]
Rounds n to the nearest integer, with halfway cases rounding away from zero.
- Returns a
Number.
Round[3.2]; (* => 3 *)
Round[3.8]; (* => 4 *)
Round[-3.5]; (* => -4 *)
RunShell
RunShell[cmd, args]
Executes a system command with the given arguments. Stdout and stderr are inherited from the KSL process and are not captured.
cmdis aStringnaming the command to run.argsis aListof arguments.Stringarguments are passed verbatim.Atomarguments (e.g.,#h) are automatically converted to a flag (-h).
- Returns
#okif the command exits successfully, or#errif it fails. - An error is raised if the command cannot be executed (e.g., command not found).
RunShell["ls", { "-la", #h }]; (* => #ok *)
Mkdir["a"];
RunShell["rm", { "a" }];
(* rm: a: is a directory
=> #err *)
RunShell["nocmd", { }];
(*? Error[ksl::builtin::RunShell]: Execution failed: No such file or directory (os error 2). *)