--- menuTitle: title: Computation weight: 3 --- This page presents all the ``s that can be performed in Wyrd. ``s do not modify the memory, but they always return a ``. Be careful not to modify the memory through reference when computing values. **Shortcut to each ``:** * [`(add_text_effect {name: String} {parameters: List} {values: list})`](#add_text_effect) * [`(address )`](#address) * [`(cast {from: String} {to: String} )`](#cast) * [`(constant {type: String} {value: String})`](#constant) * [`(get_allocable_address)`](#get_allocable_address) * [`(if_else )`](#if_else) * [`(last_choice_index)`](#last_choice_index) * [`(newline)`](#newline) * [`(operation {operator: String} )`](#unary-operation) * [`(operation {operator: String} )`](#operation) * [`(relative_address )`](#relative_address) * [`(size )`](#target) * [`(text {values: List})`](#text) * [`(value_of )`](#value_of) * [`({extra_computation} {parameters: List})`](#extra_computation) ### add_text_effect `(add_text_effect {name: String} {parameters: List} {values: list})` Add an effect to a list of texts, returning it as a single text. **Parameters:** * `name` is a `{String}` indicating the name of the effect. * `parameters` is a `{List}` of `` that will yield the ``s used as parameters for the effect. * `values` is a `{ List}` that will yield the texts to merge and apply the effect to. These will yield ``s. **Process:** * Compute the `{params: List}` corresponding to `parameters` (keep the order). * Compute the `{texts: List}` corresponding to `values` (keep the order). * Return a new `` `` with `texts` as `content`, `name` as `effect_name`, and `params` as `effect_parameters`. ### address `(address )` Converts to an address. **Parameters:** * `value_or_target` is a `` that will either result in in a `` or a ``. **Process:** * Compute the `` corresponding to `value_or_target`. * If this resulted in a ``, return the value as is. * If this resulted in a ``, interpret the value as `{addr: String}`, return a new `` built from a singleton list with `addr` as its only element. ### cast `(cast {from: String} {to: String} )` Convert from one type to another. **Parameters:** * `from` is a `{String}` naming the type `content` will result to. * `to` is a `{String}` naming the type to convert `content` to. * `content` is a `` that will yield the `` to convert. **Process:** * Compute the `` associate with `content`. * Convert this `` from `from` to `to`. * Return the converted value. **Note:** The following conversions are expected to be available: * A type to the same type, returning the same value. * `` to ``, returning `(StringValue "true")` if `` is `(BoolValue TRUE)` and `(StringValue "false")` otherwise. * `` to ``, same as above, but with text instead of string. * `` to ``. * `` to ``. * `` to ``, using a *floor* function. * `` to ``. * `` to ``. * `` to ``. * `` to ``, with `0` being `(BoolValue FALSE)` and anything else being `(BoolValue TRUE)`. * `` to ``. * `` to ``. * `` to ``, `(BoolValue TRUE)` if the string is `"true"`, `(BoolValue FALSE)` if it is `"false"`. Convert to lowercase prior to checking. * `` to ``, by recursively converting all content to `{String}`, discarding effects and newlines, and appending it all. * `` to ``, by converting it to `` first. * `` to ``, by converting it to `` first. * `` to ``, by converting it to `` first. ### constant `(constant {type: String} {value: String})` Constant value. **Parameters:** * `type` is a `{String}` indicating the type the other parameter should be converted to. * `value` is a `{String}` representation of the value that should be returned. **Process:** * Parse the value of `value` according to `type`. * Return the corresponding ``. **Notes:** The `type` parameter can take the following values: `"string"`, `"float"`, `"int"`, and `"bool"`. ### get_allocable_address `(get_allocable_address)` Get an allocable address. **Process:** * Return an `` corresponding to an unused address. **Notes:** Process when using the suggested `` definition: * If the ``'s `freed_addresses` collection has elements, return a `` corresponding to one of its elements. * Otherwise, create a string `addr` corresponding to `".alloc."` to which the ``'s `allocated_data` integer has been added then return a new `` with a singleton list containing `addr`. As a reminder, `` is not modified by the procedure. ### if_else `(if_else )` **Parameters:** * `condition` is a `` that will indicate which other computation to consider. * `if_true` is a `` that will be considered only if the `condition` is verified. * `if_false` is a `` that will be considered only if the `condition` is not verified. **Process:** * Compute the `` resulting from `condition`. * Interpret this `` as a `{Boolean}`. * If it yielded `TRUE`, compute and return the `` resulting from `if_true`, otherwise, compute and return the `` resulting from `if_false`. ### last_choice_index `(last_choice_index)` Get the index of the user's last chosen option. **Process:** * Return an `` corresponding to the ``'s `last_choice_index`. ### newline `(newline)` Return a newline value. **Process:** * Return a `` corresponding to a newline. ### Unary operation `(operation {operator: String} )` Interpret as `(operation operator x (BoolValue FALSE))`. It is recommended to have the parser do that conversion automatically. ### operation `(operation {operator: String} )` Performs a basic operation. **Parameters:** * `operator` is the name of the operation. * `x` is the first operand. * `y` is the second operand. **Process:** * Compute `` and ``, the `` corresponding to `x` and `y`, respectively. * See the *Notes* below for which operators are expected. * Return the result of the operation. **Notes:** `val_x` and `val_y` always have the same type. If the returned value is a number, it has the same type as `val_x` and `val_y`. Number types are `` and ``. Comparable types are ``, ``, ``, ``, and ``. *Operands are numbers, returns number*: * `divide`, returning the value corresponding to `val_x` divided by `val_y`. This is an integer division if and only if `val_x` is an integer. * `minus`, returning the value corresponding to `val_x` minus `val_y`. * `plus`, returning the value corresponding to `val_x` plus `val_y`. * `power`, returning the value corresponding to `val_x` to the power `val_y`. * `times`, returning the value corresponding to `val_x` times `val_y`. *Operands are ``s, returns ``:* * `modulo`, returning the value corresponding to `val_x` modulo `val_y`. *Operands are ``s, returns ``:* * `and`, returning `(BoolValue TRUE)` if both `val_x` and `val_y` are `(BoolValue TRUE)`, `(BoolValue FALSE)` otherwise. Do not evaluate `val_y` if `val_x` yielded `(BoolBalue FALSE)` (lazy evaluation). * `not`, returning `(BoolValue TRUE)` if `val_x` is `(BoolValue FALSE)`. Otherwise, return `(BoolValue FALSE)`. *Operands are comparable, returns ``:* * `less_than` returning `(BoolValue TRUE)` if `val_x` is less than `val_y` and `(BoolType FALSE)` otherwise. `(BoolType FALSE)` is less than `(BoolType TRUE)`. ``s can be compared by comparing the strings corresponding to having joined all elements in their respective string lists. *Operands can be any type, returns ``:* * `equals` returns `(BoolValue TRUE)` if `val_x` has the same value as `val_y`, `(BoolType FALSE)` otherwise. Be sure to compare values and not identity (value vs reference). ### relative_address `(relative_address )` Appends to an address. **Parameters:** * `target` is a `` that will yield the base address to extend. * `extra` is a `` corresponding to the `` element to add to the address. **Process:** * Compute the `` corresponding to `target`. * Compute the `` corresponding to `extra`. * Return a new `` corresponding to the previous ``, but with its list of strings now having been extended by the addition of the string equivalent to that ``. ### size `(size )` Computes the size of a list. **Parameters:** * `target` is a `` that will yield a `` pointing to a ``. **Process:** * Compute the `` yielded by `target`. * Return a new `` corresponding to the number of elements in the `` pointed to by that ``. ### text `(text {values: List})` Merges a list of text values into a single one. **Parameters:** * `values` is a list of ``s that will yield ``s. **Process:** * Compute the `` corresponding ot each element of `values`. * Return a new `` corresponding to these `` appended one after the next. ### value_of `(value_of )` Retries the value from memory. **Parameters:** * `target` is a `` that will yield the address of the memory element to get the value of. **Process:** * Compute the value of `target`. * Return the `` pointed to by `target` in the ``'s `memory`. ### extra_computation `({extra_computation} {parameters: List})` Performs non-standard computation. **Parameters:** * `extra_computation` is the name of the extra computation. * `parameters` is a list of parameters for this computation call. **Process:** * Undetermined. This is where you choose the process according to the value of `extra_computation` so that you can add non-standard computations.