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.

Copy

From Esolang
Jump to navigation Jump to search

Copy is an esolang invented by user:cleverxia, inspired by SMITH (loosely), it is unrelated to copying code forward, but rather copying recursively..

Commands

Copy has registers R1 and R2.

Caption text
command meaning
+ & ^ increments R1 or R2 respectively
- & v decrements R1 or R2 respectively, failed decrements skip next command
<m|n> calls the code from instruction m to n, then return control to the original caller.

the - and v command only skips command in this sub-scope: <2|2>.- outputs 0.

However, the m and n are in global scope: <1|1><2|2>. outputs 000 and don't error.

(The words maybe a bit unclear so be sure to refer to the interpreter)

. & $ output R1 or R2 respectively(optional)

Examples

infinite loop

<0|0>

Truth machine

-<2|4>+.<3|4>

Interpreter

in node.js

code="<2|2>.-";//input code here
instructions=[]
for(let i=0;i<code.length;i--)switch(code[i]){
 case'+':instructions.push('+');break
 case'-':instructions.push('-');break
 case'^':instructions.push('^');break
 case'v':instructions.push('v');break
 case'<':
  let b=0,c=0;
  for(i++;code[i]!='|';i++)b=b*10+(+code[i]);
  for(i++;code[i]!='>';i++)c=c*10+(+code[i]);
  instructions.push([b,c]);break
}
let r1=0n,r2=0n;
function interpret(c){
 for(let i=0;i<c.length;i++){
  if(typeof c[i]=='object')interpret(instructions.slice(c[i][0],c[i][1]+1));
  else switch(c[i]){
   case'+':r1++;break
   case'^':r2++;break
   case'-':if(!r1)i++;else r1--;break
   case'v':if(!r2)i++;else r2--;break
}}}
interpret(instructions)