键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

Length

Length[container]

Returns the number of elements in a list or the number of Unicode characters in a string.

  • Returns a Number.
Length[{ 1, 2, 3 }];   (* => 3 *)
Length["👋你好🇺🇸美国"]; (* => 7 *)

Less

Less[x, y]

Compares two numbers and returns #t if x is strictly less than y.

  • Returns #t if $x < y$, otherwise #f.
Less[5, 10];  (* => #t *)
Less[10, 5];  (* => #f *)
Less[5, 5];   (* => #f *)

Let

Let[target, value]

Binds value to target in the current environment. If target is already defined, it is shadowed within the current scope.

  • target may be a single symbol or a list of symbols for destructuring.
  • Returns Unit[].
Let[a, 10];
Print[a];  (* => 10 *)

Let[a, 20];
Print[a];  (* => 20 *)

Let[{ a, b }, { 12, 34 }];

Ln

Ln[n]

Computes the natural logarithm (base $\mathrm{\mathbf{e}}$) of n.

  • Returns a Number.
  • An error is raised if $n \le 0$.
Ln[1];    (* => 0 *)
Ln[2.3];  (* => 0.832909122935104 *)
Ln[0];
(*? Error[ksl::builtin::Ln]: Logarithm of non-positive number. *)

Load

Load[target, module_path]

Loads a KSL module from module_path (without the .ksl extension) and binds it according to target.

  • If target is a single Symbol, the entire module object is bound to that symbol.
  • If target is a List of symbols, only the specified members are imported directly into the current scope.
  • Searches the current working directory and the KSL_PATH directory (default ~/.local/share/ksl).
  • Returns Unit[].
  • An error is raised if the file is not found, contains syntax errors, or a requested symbol does not exist.
Load[ss, "std/string"];
Use[ss, Capitalize]["ksl"];  (* => "Ksl" *)

Load[{ Capitalize, NewLine }, "std/string"];
Capitalize["ksl"];  (* => "Ksl" *)
Print[Concat["Line 1", NewLine, "Line 2"]];

Lowercase

Lowercase[s]

Converts all characters in string s to lowercase.

  • Returns a new String.
Lowercase["Hello World"];  (* => "hello world" *)
Lowercase["KSL"];          (* => "ksl" *)