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: TheSymbolto check for in the current scope.
Object Key Existence
Has[object, key]
When called with two arguments:
object: TheObjectto inspect.key: AnAtomrepresenting the key to check for.
Return Value
Returns an Atom (#t or #f).
#tif thesymbolis defined or if thekeyexists in theobject.#fif thesymbolis not defined or if thekeydoes not exist in theobject.
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.
Head
Retrieves the first element of a list.
Parameters
Head[list]
The function requires exactly one argument.
list: TheListfrom 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.
*)