键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

Has

Has[symbol]

Has[object, key]

A polymorphic function that checks for existence in the current environment or within an object.

  • Single argument: Returns #t if symbol is defined in the current scope, otherwise #f.
  • Two arguments: Returns #t if key exists in object, otherwise #f.
(* Symbol existence *)
Has[Has];  (* => #t *)
Has[a];    (* => #f *)

Let[a, 0];
Has[a];    (* => #t *)

(* Object key existence *)
Let[obj, Object[A, { { #a, 1 } }]];
Has[obj, #a];  (* => #t *)
Has[obj, #b];  (* => #f *)

Head[list]

Retrieves the first element of list.

  • Returns the first element of the list.
  • An error is raised if list is empty.
Head[{ 1, 2, 3 }];        (* => 1 *)
Head[{ { #a, #b }, #c }]; (* => {#a, #b} *)

Head[{ }];
(*? Error[ksl::builtin::Head]: Empty list. *)