This example demonstrates recursive function definitions in hyTags. Enter a number and calculate its Fibonacci value.
The example shows how to define functions with parameters and return types, use variables, and handle form submissions.
<form>
<input type="text" name="n" value="20">
<button>Calculate</button>
</form>
<on submit>
<form-get-value name="n">
<number-from-string>
<function-call name="fib"></function-call>
<selection-scope next-sibling=".result">
<number-to-string>
<selection-set-text>
</selection-scope>
</on>
<div class="result"></div>
<function name="fib" params="n: number" return="number">
<number-is-equal other="0">
<if-true>
<function-return value="0">
</if-true>
<number-is-equal other="1">
<if-true>
<function-return value="1">
</if-true>
<var-set name="first">
<number-subtract $self="n" value="1">
<function-call name="fib"></function-call>
</var-set>
<var-set name="second">
<number-subtract $self="n" value="2">
<function-call name="fib"></function-call>
</var-set>
<number-add $self="first" $value="second">
</function>
string onto the stack.string on the stack to a
number.number on the stack to a
string.string on the stack.