hyTags
HomeHome DocumentationDocumentation

Types

Overview

hyTags is dynamically typed. Every value on the stack has a type, and commands expect parameters of particular types. Type errors are caught at runtime and throw exceptions.

Command Naming

Commands that operate on a specific type follow the naming pattern type-function. For example, string-append appends to a string, and number-add adds to a number.

Type-based commands typically have a self parameter that refers to the value being operated on. This parameter is read from the stack by type:

<button>Self parameter</button>
<on click>
  <string-new value="Hello">
  <!-- Stack: ["Hello"] -->
  <string-append string=" World">
  <!-- self = "Hello" (from stack) -->
  <debug-log>
  <!-- Logs: "Hello World" -->
</on>
👆 Try to change something! ⚠️ Preview only available on larger screens

Primitive Types

  • string: Text values. Commands: string-new, string-append, string-split, string-replace, etc.
  • number: Numeric values (integers and decimals). Commands: number-new, number-add, number-multiply, number-round, etc.
  • bool: Boolean values. Commands: bool-true, bool-false, bool-and, bool-or, bool-not.

Collection Types

  • array: An ordered list of values. Arrays are typed: [string] holds strings, [number] holds numbers. Commands: array-new, array-append, array-get, array-loop, etc.
  • object: A key-value dictionary with string keys. Commands: object-new, object-set, object-get, object-get-keys.

DOM Types

  • element: A single DOM element. Commands: element-new, element-clone, selection-get-element.
  • fragment: A collection of DOM nodes. Commands: fragment-new, fragment-replace, selection-append-children.
  • event: An event object passed to handlers. Commands: event-get, event-get-target, event-get-key.

Date and Time Types

  • date: A calendar date (year, month, day). Commands: date-new, date-now, date-add, date-to-string.
  • time: A time of day (hour, minute, second). Commands: time-new, time-now, time-to-string.
  • dateTime: A combined date and time. Commands: date-time-new, date-time-now, date-time-to-string.

Network Types

  • url: A parsed URL with components. Commands: url-new, url-from-string, url-get-path, url-add-query-param.
  • request: An HTTP request being built. Commands: request-new, request-set-object, request-send.
  • response: The result of an HTTP request. Commands: response-is-success, response-get-object, response-get-fragment.
  • error: An error from a failed request. Commands: error-get-code, error-get-message.
  • formData: Form data for HTTP requests. Commands: form-get-data, request-set-form-data.

Other Types

  • rect: A rectangle with position and size. Commands: selection-get-frame-rect, rect-get-left, rect-get-width.
  • closure: A block of commands stored for later execution. Commands: closure-new, closure-execute.

Type and Return Parameters

Some commands work with multiple types. These use a type parameter to specify which type to operate on, or a return parameter to specify the result type.

For example, var-set stores a value of any type. The type parameter tells it what type the value is:

<button>Type parameter</button>
<on click>
  <var-set name="count" value="0" type="number"></var-set>
  <var-set name="label" value="Items" type="string"></var-set>
</on>
👆 Try to change something! ⚠️ Preview only available on larger screens

Commands like selection-scope use a return parameter to specify what type the inner commands will produce:

Hello
<button>Return parameter</button>
<on click>
  <selection-scope next-sibling="div" return="string">
    <selection-get-text>
  </selection-scope>
  <!-- String from scope is now on the stack -->
  <debug-log>
</on>

<div>Hello</div>
👆 Try to change something! ⚠️ Preview only available on larger screens
Test succeeded Test failed