We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Do while true

From Esolang
Jump to navigation Jump to search

Do while true is an esolang made by User:cleverxia, where every line is an expression.

Syntax

There is a stack.

Every line is an expression in postfix notation (1$2$- equals -1) and evaluated from left to right ($72$o$105$o-No prints Hi! and equals -33).

The intepreter first does that line and get the evaluated value, and then runs it until the evaluated value is 0.

Every negative or 0 value is treated as 0, else they're treates as 1.

Notes:

  • the syntax sugar $abc$ means the number abc.
  • #x means argument x.
  • EOF returns -1, and the integers are unbounded.
Caption text
Command Descriprion
i gets input, evaluates to input.
N change the sign of #1
o output #1 and returns it
1 returns a 1
> returns 1 if #1>#2 else 0
~ returns 1, discards #1
: duplicate and return top of stack
< push #1 onto the stack and returns #1
- returns #1 - #2
! returns and discards top of the stack
r returns a random bit
v rotate stack down. returns 0
@ anything beyond that is a comment
S swaps top two stack elements, returns 0
^ rotate the stack up, returns a 0
= pop a list of numbers ending with 0 off-stack. convert them to strings. defines function number #1 to be the converted string as DWT code. returns #1
Z run function #1. returns #1.
h halt. "returns" 0.

Examples

Hello, World!

$72$o$101$o$108$o$108$o$111$o$44$o$32$o$87$o$111$o$114$o$108$o$100$o$33$o------------~1-

Truth-machine

i<~1-
:o$48$-

Cat program

io

Self intepreter

i<:-^-|1-~
1=1Z-h-     @it's ok without the last "-"

Prime checker

requires integer input.

TBD

Interpreter in node.js

code=`input code here`
input=`input input here`

gi=(i=>{let c=0;return _=>(c>=i.length?-1:i.codePointAt(c++))})(input);stk=[];funcs=[]
function il(code,b,r){
let tst=[];for(i of code)switch(i){
case'h':process.exit();case'o':process.stdout.write(String.fromCodePoint(tst.pop()%1114111));break
case'1':tst.push(1);break;case'-':b=tst.pop();r=tst.pop();tst.push(b-r||0);break
case'>':b=tst.pop();r=tst.pop();tst.push(b>r);break;case'!':tst.push(stk.pop()||0);break
case'~':tst.pop();tst.push(1);break;case'<':stk.push(tst[tst.length-1]||0);break
case':':stk.push(stk[stk.length-1]||0);break;case'N':b=tst.pop();tst.push(-b||0);break
case'i':tst.push(gi``);break;case'S':b=stk.pop();r=stk.pop();stk.push(b||0);stk.push(r||0);tst.push(0);break
case'^':stk.push(stk[0]||0);stk=stk.slice(1);tst.push(0);break;case'r':tst.push(Math.random()<.5?1:0);break
case'v':stk=[stk[stk.length-1]||0].concat(stk);stk.pop();tst.push(0);break
case'=':b=[];while(stk.length&&(r=stk.pop())>0)b.push(r);funcs[r=tst.pop()||0]=String.fromCodePoint(...b);tst.push(r);break
case'Z':interpret(funcs[b=tst.pop()||0]);tst.push(b);break;default:tst.push(i.codePointAt())
}return tst.top()}function interpret(code){let codes=code.split`
`,T=0;for(let i of codes)do{T=il(i.split`@`[0])}while(T)}interpret(code)