键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

PadLeft

PadLeft[list, elem, n]

Pads list on the left by inserting n copies of elem.

  • Returns a new list with n copies of elem prepended to the left side of list.
  • If n is zero or negative, list is returned unchanged.
PadLeft[{ 1, 2, 3 }, #elem, 3];  (* => {#elem, #elem, #elem, 1, 2, 3} *)
PadLeft[{ 1, 2, 3 }, #elem, 0];  (* => {1, 2, 3} *)

PadRight

PadRight[list, elem, n]

Pads list on the right by inserting n copies of elem.

  • Returns a new list with n copies of elem appended to the right side of list.
  • If n is zero or negative, list is returned unchanged.
PadRight[{1, 2, 3}, #elem, 3];  (* => {1, 2, 3, #elem, #elem, #elem} *)
PadRight[{1, 2, 3}, #elem, 0];  (* => {1, 2, 3} *)

ParseNumber

ParseNumber[s]

Parses a string s into a number.

  • Returns a Number if the string represents a valid numeric literal (including "nan" and "inf").
  • An error is raised if the string cannot be parsed as a number.
ParseNumber["12.2e-3"];  (* => 0.0122 *)
ParseNumber["nan"];      (* => nan *)

ParseNumber["another"];
(*? Error[ksl::builtin::ParseNumber]: `another` is not a valid number string. *)

ParseNumber

ParseNumber[s]

Parses a string s into a number.

  • Returns a Number if the string represents a valid numeric literal (including "nan" and "inf").
  • An error is raised if the string cannot be parsed as a number.
ParseNumber["12.2e-3"];  (* => 0.0122 *)
ParseNumber["nan"];      (* => nan *)

ParseNumber["another"];
(*? Error[ksl::builtin::ParseNumber]: `another` is not a valid number string. *)

Plugin

Plugin[name, "lib/export"]

Declares a foreign function interface (FFI) binding to an external native library.

  • name is the Symbol that will be bound to the imported function in the current environment.
  • The second argument is a String specifying the library path and exported symbol name, separated by a forward slash.
  • Returns Unit[].
Plugin[RaylibGetTime, "ksl_cplugin/cplugin_raylib_get_time"];
(* RaylibGetTime can now be called as a regular KSL function *)

Power

Power[b, e]

Computes b raised to the power of e ($b^e$).

  • Returns a Number.
Power[3, 4];   (* => 81 *)
Power[2, -1];  (* => 0.5 *)
Power[9, 0.5]; (* => 3 *)

Prepend

Prepend[list, element]

Returns a new list with element inserted at the beginning of list. The original list is unchanged.

  • Returns a new List.
Prepend[{ 1, 2, 3 }, #elem];  (* => { #elem, 1, 2, 3 } *)
Let[v, { 1, 2 }];
Prepend[v, 0];  (* => { 0, 1, 2 } *)
Print[v];       (* => { 1, 2 } *)

Print

Print[val] Print[val, end]

Prints the string representation of val to standard output, followed by a newline (or a custom end string).

  • If end is provided, it replaces the default newline.
  • Returns Unit[].
Print["Hello, World!"];          (* Prints with a trailing newline *)
Print["Progress: ", ""];         (* Prints without a trailing newline *)
Print["100%"];                   (* Continues on the same line *)

Pwd

Pwd[]

Returns the current working directory as an absolute path.

  • Returns a String.
Pwd[];  (* => "/home/user" *)