Afth/Examples
Jump to navigation
Jump to search
Examples
Hello, World!
A simple Hello World:
:RUN svFsyfSK_j +0a "Hello, World! +0e RUN END
The above without "words":
+0a "Hello, World! +0e !svFsyfSK_j !_q
Add Two Numbers
This adds two base-10 numbers and outputs the result in base-10:
Id Id A+ Od END
The above without "words":
!WS !WS !sLs+S !sY !_q
Which is equivalent to:
!WSWSsLs+SsY_q
Which can be simplified to this by removing 'Ss' sequences:
!WSWLs+Y_q
Cat
A simple Cat program:
:LOOP _^K_j Ic Oc LOOP
Without "Words":
!wS !sy !_^K_j
Above simplified to not have 'Ss' sequences:
!wy_^K_j
Echo
Similar to the Cat program, the Echo program outputs input, but then quits after outputting an LF
:DUP sSS Ic DUP Oc !sF_^<<^<-Lf+K_j END
Above without words:
!wS !sSS !sy !sF_^<<^<-Lf+K_j !_q
Above without 'Ss' sequences:
!wSysF_^<<^<-Lf+K_j !_q
Since the 'y' instruction does not change the value of the line-scope variable 't', the above can be simplified to this:
!wyF_^<<^<-Lf+K_j !_q
Another way of writing the Echo program is:
:DUP sSS :L_NZ sK_j Ic DUP Oc +0a A- L_NZ END
Which, when fully simplified, is:
!wSy +0a !s-Ls+K_j !_q