Iterate/Compilation
For convenience, this page defines a more programmer-friendly version of Iterate that can be compiled into syntactically correct code. The compiled code should optimally be devoid of whitespace, since such isn't necessary to properly parse Iterate, but the example outputs here will use whitespace regardless.
Labels
Labels are able to be defined and referenced using alphanumeric characters (and the underscore). When compiling, each unique label should be turned into a numeric index, with identical labels sharing the same index. The actual index does not matter—order is not important—but labels should not share an index. In the case of the commands n# and ~n#, the label should be placed after a colon.
This program:
(*)1<
*?< (input*)<> >
(is0*)1<
*=input< !is0 >
(print0*)48<
*~n< &print0 >
~@
>
!^
>
*∞< *1< @ > >
>
Becomes:
(*)1<
*?< (1*)<> >
(2*)1<
*=1< !2 >
(3*)48<
*~n< &3 >
~@
>
!^
>
*∞< *1< @ > >
>
Macros
Macros are blocks of code that can be reused multiple times in a single program. When compiling, each macro call will be replaced by the code that is being invoked. Every macro call takes in a prefix that is to be prepended to every label (to avoid clashing), then a variable amount of arguments afterwards. Each argument is simply inserted into the macro's code. Macros can invoke other macros, however are not allowed to cause recursion.
A macro is first defined by a loop with two pairs of parentheses, followed by the name of the label and an asterisk. Outside the parentheses, labels for each argument is provided, separated with spaces. The macro's code is then held within the loop. Mentions of the argument within the code should be prefixed by a question mark. Any labels used within the macro that are not defined outside of the macro will be prefixed.
((print_char*))code<
*1<
(print*)?code<
*~n< &print >
~@
>
>
>
To invoke a macro, use a similar construct as to how you would define it, with a prefix before the second parentheses that will be assigned to each of the labels. Afterwards, every argument used by the macro should be contained within a pair of angle brackets. Note that the prefix is concatenated for each nested call.
(example_(print_char*))<182> (example_(print_char*))<55> (example_(print_char*))<319> (example_(print_char*))<83> (example_(print_char*))<~?>
This program:
((compare*))A B<
$value1 $value2 $equal $less $greater
*?A< (value1*)<> >
*?B< (value2*)<> >
(comparison*)∞<
(check*)1<
*=value1<
*=value2< !check >
(greater*)<> !comparison
>
*=value2<
*=value1< !check >
(less*)<> !comparison
>
(equal*)<> !comparison
>
$value1_dec *=value1< (value1_dec*)<> >
$value2_dec *=value2< (value2_dec*)<> >
$value1 *=value1_dec< *~n< (value1*)<> > ! >
$value2 *=value2_dec< *~n< (value2*)<> > ! >
>
>
((if_else*))condition true false<
(check*)1<
(is0*)1<
*?condition< !is0 >
?false
!check
>
(is1*)?condition<
*~n< !is1 >
?true
!check
>
>
>
((print_char*))char<
*1< (print*)?char< *~n< &print > ~@ ! > >
>
(*)∞<
$input *?< (input*)<> >
(is_n_(compare*))<=input><n^>
(validate_(if_else*))<=is_n_equal><@><
(lose_(print_char*))<89> // Y
(lose_(print_char*))<79> // O
(lose_(print_char*))<85> // U
(lose_(print_char*))<32> //
(lose_(print_char*))<76> // L
(lose_(print_char*))<79> // O
(lose_(print_char*))<83> // S
(lose_(print_char*))<69> // E
!^
>
>
Becomes:
(*)∞<
$1 *?< (1*)<> >
$2 $3 $4 $5 $6
*=1< (2*)<> >
*n^< (3*)<> >
(7*)∞<
(8*)1<
*=2<
*=3< !8 >
(6*)<> !7
>
*=3<
*=2< !8 >
(5*)<> !7
>
(4*)<> !7
>
$9 *=2< (9*)<> >
$10 *=3< (10*)<> >
$2 *=9< *~n< (2*)<> > ! >
$3 *=10< *~n< (3*)<> > ! >
>
(11*)1<
(12*)1<
*=4< !12 >
*1< (13*)89< *~n< &13 > ~@ ! > >
*1< (13*)79< *~n< &13 > ~@ ! > >
*1< (13*)85< *~n< &13 > ~@ ! > >
*1< (13*)32< *~n< &13 > ~@ ! > >
*1< (13*)76< *~n< &13 > ~@ ! > >
*1< (13*)79< *~n< &13 > ~@ ! > >
*1< (13*)83< *~n< &13 > ~@ ! > >
*1< (13*)69< *~n< &13 > ~@ ! > >
!^
!11
>
(14*)=4<
*~n< !14 >
@
!11
>
>
>