键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

Has

A polymorphic function that checks for the existence of a symbol in the current environment or a key within an object. The function’s behavior is determined by the number of arguments provided.

Parameters & Behavior

Symbol Existence

Has[symbol]

When called with a single argument:

  • symbol: The Symbol to check for in the current scope.

Object Key Existence

Has[object, key]

When called with two arguments:

  • object: The Object to inspect.
  • key: An Atom representing the key to check for.

Return Value

Returns an Atom (#t or #f).

  • #t if the symbol is defined or if the key exists in the object.
  • #f if the symbol is not defined or if the key does not exist in the object.

No domain-specific errors are thrown by this function.

Examples

Checking Symbol Existence

(* Returns #t because Has is a defined built-in function *)
Has[Has]; (* #t *)

(* Returns #f because the symbol 'a' is not yet defined *)
Has[a]; (* #f *)

Let[a, 0];
(* After binding, the symbol 'a' now exists *)
Has[a]; (* #t *)

Checking Object Key Existence

Let[obj, Object[A, { { #a, 1 } }]];

(* Returns #t because the key #a exists in the object *)
Has[obj, #a]; (* #t *)

(* Returns #f because the key #b does not exist *)
Has[obj, #b]; (* #f *)

Understood. Here is the documentation for the Head function.


Retrieves the first element of a list.

Parameters

Head[list]

The function requires exactly one argument.

  • list: The List from which to retrieve the first element.

Return Value

Returns the first element of the list. The type of the returned value is the type of that element.

Errors

An error will occur if the input list is empty.

Examples

(* Retrieves the first element of a non-empty list *)
Head[{ 1, 2, 3 }]; (* 1 *)

(* The first element can be of any type, including another list *)
Head[{ { #a, #b }, #c }]; (* {#a, #b} *)

(* This will cause an error because the list is empty *)
Head[{ }];
(* ?
Error[ksl::builtin::Head]: Empty list.
*)