键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

Eq

Eq[value1, value2]

Performs a deep equality comparison between any two KSL values.

  • Returns #t if the values are equal, otherwise #f.

Equality rules:

  • Primitive types (Unit, Symbol, Atom, String, Number): equal if their underlying values are identical.
  • Lists: equal if they have the same length and each corresponding element is equal.
  • Objects: equal if they share the same type tag and contain the exact same set of key-value pairs (key order does not matter).
  • Other: returns #f.
Eq[2, 2.0];         (* => #t *)
Eq[#ok, #ok];       (* => #t *)
Eq[#t, #f];         (* => #f *)

Eq[{ 1, { 2, 3 } }, { 1, { 2, 3 } }];  (* => #t *)
Eq[{ 1, 2 }, { 2, 1 }];                (* => #f *)

Let[obj1, Object[T, { { #a, 1 }, { #b, 2 } }]];
Let[obj2, Object[T, { { #b, 2 }, { #a, 1 } }]];
Eq[obj1, obj2];     (* => #t *)

Eq[1, "1"];         (* => #f *)

Evial

Evial[code]

Executes KSL source code provided as a string code within the current evaluation environment. Analogous to eval in other languages.

  • Returns the result of the last expression in code.
  • Side effects (e.g., variable definitions with Let or Update) persist in the current scope.
Has[a];                         (* => #f *)
Evial["Let[a, 10];"];           (* => () *)
Has[a];                         (* => #t *)
Print[a];                       (* => 10 *)

Add[Evial["Add[5, 5]"], 6];     (* => 16 *)

Exit

Exit[code]

Terminates the KSL interpreter immediately and returns the status code code to the operating system. By convention, 0 indicates success; any other value signals an error.

  • This function does not return; the process terminates upon invocation.
Exit[0];

In a terminal, the exit code can be verified using standard shell commands:

> ksl -c 'Exit[69]'
> echo "$?"
69

Exp

Exp[n]

Computes the natural exponential function $\mathrm{\mathbf{e}}^n$.

  • Returns a Number.
  • Following f64 semantics, large inputs may result in inf.
Exp[1];     (* => 2.71828182845905 *)
Exp[0];     (* => 1 *)
Exp[-1];    (* => 0.367879441171442 *)
Exp[1000];  (* => inf *)