Afth/Examples

From Esolang
Jump to navigation Jump to search

Dictionary Code

This is the dictionary as used in all examples:

:A+ sLs+S
:A- s-Ls+S
:A* sLs*S
:A/ sLs/S
:A% sLs%S
:Ic wS
:Oc sy
:Id WS
:Od sY
:Ih mS
:Oh sM
:END _q
:ABS s|S
:NEG s|-S
:DUP sSS
:L_NZ sK_j
:JNZ_r sFsKfj
:JUMPr sF_1Kfj
:JUMP sF_1KfJ
:DROP s_
:PUSH S
:JSiGr sF.Zfj
:Si .S
:CR _1101S
:LF _1010S

Examples

Hello, World!

A simple Hello World:

LF
"Hello, World!
+02 JSiGr
+02 JUMPr
Oc +02 NEG JUMPr
END

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 can be simplified to this by removing 'Ss' sequences:

!WSWLs+Y_q

Echo

Similar to the Cat program, the Echo program outputs input, but then quits after outputting an LF

Ic DUP Oc LF A- L_NZ
END

Which, when fully simplified, is:

!wSy_1010-Ls+K_j
!_q

RPN Calculator

This is v2 of a single-line five-function RPN Calculator.

The chars for the five functions are: + - * / %

At end of line, the characters " 0 ." must be present to view result and auto-quit.

LF
"RPN CALC
+02 JSiGr
+02 JUMPr
Oc +02 NEG JUMPr
Id Id Ic Ic DROP +02 JUMPr
Id Ic Ic DROP
DUP '. A- +02 JNZ_r
DROP DROP Od END
DUP '+ A- +02 JNZ_r
DROP A+ +04 NEG JUMPr
DUP '- A- +02 JNZ_r
DROP A- +06 NEG JUMPr
DUP '* A- +02 JNZ_r
DROP A* +08 NEG JUMPr
DUP '/ A- +02 JNZ_r
DROP A/ +0a NEG JUMPr
DUP '% A- +02 JNZ_r
DROP A% +0c NEG JUMPr
DROP LF
"ERROR...
+02 JSiGr
+02 JUMPr
Oc +02 NEG JUMPr
END

External Links

Up-to-date source of this page.