Computations

This page presents all the computations that can be performed in Wyrd. Computations may access the current memory, but, with one exception, do not change it. The one exception is (new t). All computations return values. The terms ‘value’ and ‘computation’ are interchangeable.

CONSTANT

(const [BASE TYPE] {string})
Returns the [BASE TYPE] represented by {string}.

CAST

(cast [COMPUTATION] [BASE TYPE])
Converts [COMPUTATION] to [BASE TYPE], returns the result.

Note:

  • Converting from FLOAT to INT returns floor(v).
  • Converting from BOOL to STRING yields either True or False.

The following must be supported:

  • [FLOAT] to [FLOAT], [INT], and [STRING].
  • [INT] to [FLOAT], [INT], and [STRING].
  • [BOOL] to [BOOL] and [STRING].
  • [STRING] to [BOOL] (true and false), [FLOAT], [INT], and[STRING].

IF-ELSE

(if_else [BOOL] [C0 = COMPUTATION] [C1 = COMPUTATION])
Returns C0 if [BOOL] holds true, C1 otherwise. C0 and C1 both have the same type.

EQUALS

(equals [C0 = COMPUTATION] [C1 = COMPUTATION])
Returns a BOOL, true if C0 and C1 hold the same value. C0 and C1 are both of the same type.

MATHEMATICAL OPERATORS

(divide [C0 = NUMBER] [C1 = NUMBER])
(minus [C0 = NUMBER] [C1 = NUMBER])
(plus [C0 = NUMBER] [C1 = NUMBER])
(power [C0 = NUMBER] [C1 = NUMBER])

(times [C0 = NUMBER] [C1 = NUMBER])
The operation returns a value of the same type as C0 and C1 (both C0 and C1 are also of the same type). Thus, (divide C0 C1) is an integer division (the remainder is discarded) if C0 and C1 are of type INT, and a standard division if they are of type FLOAT.

(rand [C0 = INT] [C1 = INT])
Returns a random value between C0 and C1, inclusive. Raises a runtime error if C0 > C1.

MATHEMATICAL COMPARISON

(less_than [C0 = COMPARABLE] [C1 = COMPARABLE])
Returns a [BOOL] indicating if C0 is strictly less than C1. C0 and C1 are both of the same type.

LOGICAL OPERATORS

(and [C0 = BOOL] [C1 = BOOL])
(not [C0 = BOOL])

SIZE

(size [COLLECTION ADDRESS])
Returns the number of elements held by the collection at [COLLECTION ADDRESS].

REFERENCES

(address [COMPUTATION])
Returns an ADDRESS to the memory element at address [COMPUTATION]. Raises a runtime error if [COMPUTATION] is not a memory element.

(relative_address [R0 = (COLLECTION|STRUCTURE) ADDRESS] [STRING])
Returns a REFERENCE to member [STRING] of R0.

(value_of [ADDRESS])
Returns the value held at the memory location [ADDRESS].

(new [TYPE])
Returns an [TYPE] ADDRESS to a newly allocated memory element of type [TYPE].

TEXT

(newline)
Returns a TEXT value corresponding to a newline.

(text [S0 = STRING] ... [SN = STRING])
Returns a single value [TEXT] representing the elements S0S1.

(add_text_effect ({string} [V0 = COMPUTATION] ... [VN = COMPUTATION]) [TEXT])
Returns a [TEXT] value of [TEXT] with the given effect enabled.

LAST USER CHOICE

(get_last_user_choice)
Returns the number corresponding to the option last chosen by the user in a (resolve_choices), or -1 if there is no such value.