Tail
Tail[list]
Returns a new list containing all elements of list except the first. If list is empty, returns an empty list.
- Returns a
List.
Tail[{ 1, 2, 3 }]; (* => {2, 3} *)
Tail[{ }]; (* => {} *)
Take
Take[list, n]
Returns a new list containing the first n elements of list.
If n exceeds the length of list, all elements are returned.
- Returns a
List.
Take[{ 1, 2, 3, 4, 5 }, 3]; (* => {1, 2, 3} *)
Take[{ 1, 2 }, 5]; (* => {1, 2} *)
Tan
Tan[n]
Computes the tangent of an angle n given in radians.
- Returns a
Number.
Tan[0]; (* => 0 *)
Tan[0.785398163397448]; (* => 0.999999999999999 *)
Tanh
Tanh[n]
Computes the hyperbolic tangent of n.
- Returns a
Numberin the range$\left(-1, 1\right)$.
Tanh[0]; (* => 0 *)
Tanh[1]; (* => 0.761594155955765 *)
Tanh[-1]; (* => -0.761594155955765 *)
Thread
Thread[name, captures, body]
Starts a new thread that evaluates body and makes its return value available via Consume[name].
-
nameis aSymbolbound to the thread handle. -
capturesis a list ofSymbols representing variables to clone into the thread. The thread operates on copies; modifications inside the thread do not affect the original variables. -
bodyis the expression to evaluate. -
Returns
Unit[].
Thread[worker, { }, Block[
Sleep[1],
42
]];
Consume[worker]; (* => 42 *)
Timeit
Timeit[expr]
Evaluates expr and returns a list containing the elapsed time (in seconds) and the result.
- Returns a
Listof the form{ time, result }.
Timeit[Sleep[2]]; (* => {2.005052833, ()} *)
Timeit[Add[1, 2]]; (* => {4.958e-06, 3} *)
ToJSON
ToJSON[obj]
Converts a KSL Object into a JSON‑formatted string.
String values are automatically quoted, and numbers are represented as JSON numbers.
- Returns a
String. - Note: In KSL string literals, newline characters are displayed as
\n, but the actual string contains a literal line break.
ToJSON[Object[A, { { #a, 2 } }]];
(* => "{\n \"a\": 2.0\n}" *)
Print[ToJSON[Object[A, { { #a, 2 } }]]];
(*
{
"a": 2.0
}
*)
ToString
ToString[value]
Converts any KSL value into its string representation.
- Returns a
String.
ToString[42]; (* => "42" *)
ToString[{ 1, 2 }]; (* => "{1, 2}" *)
ToString[#t]; (* => "#t" *)
Trim
Trim[s]
Trim[s, mode]
Removes leading and/or trailing whitespace from string s.
modecan be#both(default),#start, or#end.- Returns a
String.
Trim[" hello "]; (* => "hello" *)
Trim[" hello ", #start]; (* => "hello " *)
Trim[" hello ", #end]; (* => " hello" *)
Trunc
Trunc[n]
Truncates the fractional part of n, returning the integer part.
- Returns a
Number.
Trunc[3.7]; (* => 3 *)
Trunc[-3.7]; (* => -3 *)
Try
Try[expr, fallback]
Evaluates expr. If evaluation succeeds, returns its result.
If evaluation raises an error, the error is suppressed and fallback is evaluated instead.
- The error is not propagated; no error message is printed unless
fallbackitself fails. fallbackis evaluated only ifexprfails.
Try[1, Print["failed!"]]; (* => 1 *)
Try[RunShell["noshells", { }], Print["failed!"]];
(* failed! *)