键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

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 Number in 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].

  • name is a Symbol bound to the thread handle.

  • captures is a list of Symbols representing variables to clone into the thread. The thread operates on copies; modifications inside the thread do not affect the original variables.

  • body is 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 List of 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.

  • mode can 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 fallback itself fails.
  • fallback is evaluated only if expr fails.
Try[1, Print["failed!"]];  (* => 1 *)
Try[RunShell["noshells", { }], Print["failed!"]];
(* failed! *)