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.

Record

From Esolang
Jump to navigation Jump to search

Record (Regex concatenate read display) is an esolang invented by User:None1.

Although Record is the name of the esolang, which is a noun, it should be pronounced like the English verb record.

Memory

It uses string variables. Reading a non-existent variable results in an empty string. Storing in a non-existent variable creates it.

String and RegEx

String literals and RegEx style depend on implementation.

Commands

Commands are case sensitive.

  • RE a r s v1 v2 ... tries to match s with RegEx literal r. If it fails then jump to line a (1-indexed, jumping out of bounds halts), otherwise captures to v1 v2 ... (There can be less captured variable than groups but not vice versa).
  • CO v1 s1 concatenates v1 with s1 and stores the result in v1.
  • R v reads a line to variable v.
  • D s prints s with nothing after it.

Examples

The following examples use Python-styled string literals and RegEx.

Hello, World!

D "Hello, World!"

Unary A+B

R a
R b
CO a b
D a

XKCD Random Number

D "4"

Check if input is a number string

R a
RE 5 "(\\d*)" a b
D "Yes"
RE 6 "a" "b"
D "No"

You can see that RegEx is parsed as string literals first and then RegEx.

Cat program

R a
D a

Truth Machine

R a
D a
RE 2 "0" a

Interpreter

In Python by User:None1. (Of course, Python-styled RegEx is used)

This program lacks syntax checks, any Python code may be injected, so be careful with untrusted programs.

import re,sys
def parselit(x):
 s=''
 for i in x:
  s+=i
  try:
   eval(s)
  except:
   pass
  else:
   return (eval(s),x[len(s)+1:])
 return x
def parsesp(x):
 s=''
 for i in x:
  if i==' ':
   return (s,x[len(s)+1:])
  s+=i
 return x
ip=0
vt={}
def mget(x):
 if x in vt:
  return vt[x]
 return ''
def RE(x):
 global ip,llen,vt
 z,x=parselit(x)
 u,x=parselit(x)
 if x[0]!='"':
     w,x=parsesp(x)
     w=mget(w)
 else:
     w,x=parselit(x)
 k=x.split()
 l=re.fullmatch(u,w)
 if l:
  for i,j in enumerate(l.groups()):
   vt[k[i]]=j
 else:
  ip=z-2
  if ip>=llen or ip<0:
   sys.exit()
def CO(x):
    x=x.strip()
    global vt
    a,x=parsesp(x)
    u=(eval(x)if x[0]=='"'else mget(x))
    vt[a]=mget(a)+u
def R(x):
    x=x.strip()
    global vt
    vt[x]=input()
def D(x):
    x=x.strip()
    if x[0]=='"':
        print(eval(x),end='')
    else:
        print(mget(x),end='')
x=sys.stdin.read().split('\n')
llen=len(x)
while 1:
    if ip>=llen:
        break
    i=x[ip]
    i=i.strip()
    i+=' '
    w,i=parsesp(i)
    if w in ('RE','CO','R','D'):
        eval(w)(i)
    ip+=1

Computational class

Record is Turing complete because it can be translated from the 2-register Minsky machine.

We can use unary, CO allows us to increment a number, while the RegEx "0(0*)" allows us to decrement a number, and if it fails, it means it is already zero and in which case jumps to another location.