BracketOnly
BracketOnly is an esolang invented by User:None1, it is no longer a work in progress. It uses only two characters: Brackets! (()
). Thus the name.
Syntax
BracketOnly uses nested brackets, brackets must be matched, there must be even groups of brackets, and each group must be valid too.
For example:
(
is invalid because it is unmatched.
(())()(()())
is invalid because there are 3 groups, which is an odd number.
(())()
is invalid because the first group has one group, which is an odd number.
Groups are divided two by two: (F)(p1p2p3...)
, F is the ID of the function, and p1, p2, p3, ... are arguments. That calls the function with the ID F and arguments p1, p2, p3, ...
Memory model
BracketOnly uses an unbounded array of signed bignums.
Functions
BracketOnly uses built-in functions, they are as follows:
ID | Name (not used in actual programming) | arguments | Description |
---|---|---|---|
0 | one | () | Returns 1 |
1 | add | (a,b,c,d,...) | Returns the sum of all arguments |
2 | mul | (a,b,c,d,...) | Returns the product of all arguments |
3 | sub | (a,b) | Returns a-b |
4 | div | (a,b) | Returns the quotient of a/b |
5 | mod | (a,b) | Returns the remainder of a/b |
6 | inp | () | Returns the input integer |
7 | inpc | () | Returns the value of the input Unicode character |
8 | out | (x) | Output x as number and return x |
9 | outc | (x) | Output the Unicode character with value x and return x |
10 | rnd | (x,y) | Returns random integer from x to y |
11 | if | (a,b,c) | If a is not zero, evaluate b, otherwise evaluate c |
12 | while | (a,b) | While a is not zero, evaluate b, return the sum of all evaluations |
13 | read | (i) | Return the i-th element (starting from 0) of the array |
14 | write | (i,j) | Set the i-th element (starting from 0) of the array to j |
15 | and | (x,y) | return x bitwise AND y |
16 | or | (x,y) | return x bitwise OR y |
17 | xor | (x) | return x bitwise XOR y |
18 | not | (x) | return 1 if x is 0, otherwise 0 |
19 | lt | (x,y) | return 1 if x < y, otherwise 0 |
20 | gt | (x,y) | return 1 if x > y, otherwise 0 |
21 | eq | (x,y) | return 1 if x = y, otherwise 0 |
22 | ne | (x,y) | return 1 if x != y, otherwise 0 |
23 | le | (x,y) | return 1 if x <= y, otherwise 0 |
24 | ge | (x,y) | return 1 if x >= y, otherwise 0 |
Note that if the function ID consists of multiple values, they are summed to get the ID, for example:
(()()()())(()())
Will return 1 by calling (one()+one())(one(),one())
(mul(one(),one())
).
Examples
Constants
The following Python program generates constants:
memo={0:'',1:'()()'} def generate(x): if x in memo: return memo[x] l=[] for i in range(1,x): l.append(generate(i)+generate(x-i)) for i in range(2,x): if x%i==0: l.append('(()()()())((()())('+generate(i)+')'+'(()())('+generate(x//i)+'))') res=l[0] for i in l[1:]: if len(i)<len(res): res=i memo[x]=res return res for i in range(100): print(f'{i} - '+generate(i))
Which are:
0 - 1 - ()() 2 - ()()()() 3 - ()()()()()() 4 - ()()()()()()()() 5 - ()()()()()()()()()() 6 - ()()()()()()()()()()()() 7 - ()()()()()()()()()()()()()() 8 - ()()()()()()()()()()()()()()()() 9 - ()()()()()()()()()()()()()()()()()() 10 - ()()()()()()()()()()()()()()()()()()()() 11 - ()()()()()()()()()()()()()()()()()()()()()() 12 - ()()()()()()()()()()()()()()()()()()()()()()()() 13 - ()()()()()()()()()()()()()()()()()()()()()()()()()() 14 - ()()()()()()()()()()()()()()()()()()()()()()()()()()()() 15 - ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()() 16 - (()()()())((()())(()()()()()()()())(()())(()()()()()()()())) 17 - ()()(()()()())((()())(()()()()()()()())(()())(()()()()()()()())) 18 - (()()()())((()())(()()()()()())(()())(()()()()()()()()()()()())) 19 - ()()(()()()())((()())(()()()()()())(()())(()()()()()()()()()()()())) 20 - (()()()())((()())(()()()()()()()())(()())(()()()()()()()()()())) 21 - ()()(()()()())((()())(()()()()()()()())(()())(()()()()()()()()()())) 22 - ()()()()(()()()())((()())(()()()()()()()())(()())(()()()()()()()()()())) 23 - ()()()()()()(()()()())((()())(()()()()()()()())(()())(()()()()()()()()()())) 24 - (()()()())((()())(()()()()()()()())(()())(()()()()()()()()()()()())) 25 - (()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()())) 26 - ()()(()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()())) 27 - ()()()()(()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()())) 28 - (()()()())((()())(()()()()()()()())(()())(()()()()()()()()()()()()()())) 29 - ()()(()()()())((()())(()()()()()()()())(()())(()()()()()()()()()()()()()())) 30 - (()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()()()())) 31 - ()()(()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()()()())) 32 - (()()()())((()())(()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 33 - ()()(()()()())((()())(()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 34 - ()()()()(()()()())((()())(()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 35 - (()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()()()()()())) 36 - (()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()())) 37 - ()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()())) 38 - ()()()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()())) 39 - ()()()()()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()())) 40 - (()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 41 - ()()(()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 42 - (()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()())) 43 - ()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()())) 44 - ()()()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()())) 45 - (()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 46 - ()()(()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 47 - ()()()()(()()()())((()())(()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 48 - (()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 49 - (()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()())) 50 - ()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()())) 51 - ()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()())) 52 - ()()()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()())) 53 - ()()()()()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()())) 54 - (()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 55 - ()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 56 - (()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 57 - ()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 58 - ()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 59 - ()()()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 60 - (()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 61 - ()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 62 - ()()()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 63 - (()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 64 - (()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 65 - ()()(()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()())) 66 - (()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()())) 67 - ()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()())) 68 - ()()()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()())) 69 - ()()()()()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()())) 70 - (()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 71 - ()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 72 - (()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 73 - ()()(()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 74 - ()()()()(()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 75 - ()()()()()()(()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 76 - ()()()()()()()()(()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 77 - (()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()())) 78 - ()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()())) 79 - ()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()())) 80 - (()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 81 - (()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 82 - ()()(()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 83 - ()()()()(()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())) 84 - (()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()())) 85 - ()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()())) 86 - ()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()())) 87 - ()()()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()())) 88 - (()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()())) 89 - ()()(()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()())) 90 - (()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 91 - ()()(()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 92 - ()()()()(()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 93 - ()()()()()()(()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 94 - ()()()()()()()()(()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())) 95 - (()()()())((()())(()()()()()()()()()())(()())(()()(()()()())((()())(()()()()()())(()())(()()()()()()()()()()()())))) 96 - (()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()())) 97 - ()()(()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()())) 98 - (()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()()()()()())) 99 - (()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()))
Cat program
(()()()()()()()()()()()()()()()()()()()()()()()())((()()()()()()()()()()()()()()()()()())((()()()()()()()()()()()()()())()))
A+B Problem
(()()()()()()()()()()()()()()()())((()())((()()()()()()()()()()()())()(()()()()()()()()()()()())()))
XKCD Random Number
(()()()()()()()()()()()()()()()()()())((()())(()()()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()))))
Alternative:
(()()()()()()()()()()()()()()()())((()())(()()()()()()()()))
Hello World
(()()()()()()()()()()()()()()()()()())((()()()())((()())(()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()())))(()()()()()()()()()()()()()()()()()())((()())(()()(()()()())((()())(()()()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()))))(()()()()()()()()()()()()()()()()()())((()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()())))(()()()()()()()()()()()()()()()()()())((()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()())))(()()()()()()()()()()()()()()()()()())((()())(()()(()()()())((()())(()()()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()))))(()()()()()()()()()()()()()()()()()())((()())(()()()()(()()()())((()())(()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()))))(()()()()()()()()()()()()()()()()()())((()()()())((()())(()()()()()()()())(()())(()()()()()()()()()()()()()()()())))(()()()()()()()()()()()()()()()()()())((()())(()()()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()()))))(()()()()()()()()()()()()()()()()()())((()())(()()(()()()())((()())(()()()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()))))(()()()()()()()()()()()()()()()()()())((()()()())((()())(()()()()()()()()()()()())(()())(()()(()()()())((()())(()()()()()())(()())(()()()()()()()()()()()())))))(()()()()()()()()()()()()()()()()()())((()()()())((()())(()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()()()()()())))(()()()()()()()()()()()()()()()()()())((()()()())((()())(()()()()()()()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()()()()()()()())))(()()()()()()()()()()()()()()()()()())((()())(()()(()()()())((()())(()()()()()()()())(()())(()()()()()()()()()()()()()()()()))))
Truth Machine
(()()()()()()()()()()()()()()()()()()()()()()()()()()()())((()())()(()()()()()()()()()()()())())(()()()()()()()()()()()()()()()())((()()()()()()()()()()()()()()()()()()()()()()()()()())((()())()))(()()()()()()()()()()()()()()()()()()()()()()()())((()()()()()()()()()()()()()()()()()()()()()()()()()())((()())())(()()()()()()()()()()()()()()()())(()()))
Generated with:
print(Write(0,Inp())+Out(Read(0))+While(Read(0),Out(1)))
Fibonacci
(()()()()()()()()()()()()()()()()()()()()()()()()()()()())(()()()())(()()()()()()()()()()()()()()()()()()()()()()()())(()()(()())((()()()()()()()()()()()()()()()())((()()()()()()()()()()()()()()()()()()()()()()()()()())((()())()))(()()()()()()()()()()()()()()()()()()()()()()()()()()()())((()())(()()()())(()())((()()()()()()()()()()()()()()()()()()()()()()()()()())((()())())(()()()()()()()()()()()()()()()()()()()()()()()()()())(()())))(()()()()()()()()()()()()()()()()()()()()()()()()()()()())((()())()(()()()()()()()()()()()()()()()()()()()()()()()()()())(()()))(()()()()()()()()()()()()()()()()()()()()()()()()()()()())(()()(()()()()()()()()()()()()()()()()()()()()()()()()()())((()())(()()()())))))
Generated with:
print(Write(1,1)+While(1,Add(Out(Read(0)),Write(2,Add(Read(0),Read(1))),Write(0,Read(1)),Write(1,Read(2)))))
Never Gonna Give You Up
BracketOnly/Rickroll, an unoptimized implementation, it is LZMA compressed and encoded with Base64 since the original program is 264108 bytes long!
Bogen
Bogen, a generator in Python, allows users to generate BracketOnly code easily, its source code is like this:
memo={0:'',1:'()()'} def generate(x): if x in memo: return memo[x] l=[] for i in range(1,x): l.append(generate(i)+generate(x-i)) for i in range(2,x): if x%i==0: l.append('(()()()())((()())('+generate(i)+')'+'(()())('+generate(x//i)+'))') res=l[0] for i in l[1:]: if len(i)<len(res): res=i memo[x]=res return res def isonebracket(x): num,cnt=0,0 for i in x: if i=='(': num+=1 else: num-=1 if not num: cnt+=1 return cnt==2 def merge(x): if not isonebracket(x): return '(()())('+x+')' return x def build(x): if isinstance(x,str): return x return merge(generate(x)) def One(*args): return "(" + generate(0) + ")(" + "".join(map(build, args)) + ")" def Add(*args): return "(" + generate(1) + ")(" + "".join(map(build, args)) + ")" def Mul(*args): return "(" + generate(2) + ")(" + "".join(map(build, args)) + ")" def Sub(*args): return "(" + generate(3) + ")(" + "".join(map(build, args)) + ")" def Div(*args): return "(" + generate(4) + ")(" + "".join(map(build, args)) + ")" def Mod(*args): return "(" + generate(5) + ")(" + "".join(map(build, args)) + ")" def Inp(*args): return "(" + generate(6) + ")(" + "".join(map(build, args)) + ")" def Inpc(*args): return "(" + generate(7) + ")(" + "".join(map(build, args)) + ")" def Out(*args): return "(" + generate(8) + ")(" + "".join(map(build, args)) + ")" def Outc(*args): return "(" + generate(9) + ")(" + "".join(map(build, args)) + ")" def Rnd(*args): return "(" + generate(10) + ")(" + "".join(map(build, args)) + ")" def If(*args): return "(" + generate(11) + ")(" + "".join(map(build, args)) + ")" def While(*args): return "(" + generate(12) + ")(" + "".join(map(build, args)) + ")" def Read(*args): return "(" + generate(13) + ")(" + "".join(map(build, args)) + ")" def Write(*args): return "(" + generate(14) + ")(" + "".join(map(build, args)) + ")" def And(*args): return "(" + generate(15) + ")(" + "".join(map(build, args)) + ")" def Or(*args): return "(" + generate(16) + ")(" + "".join(map(build, args)) + ")" def Xor(*args): return "(" + generate(17) + ")(" + "".join(map(build, args)) + ")" def Not(*args): return "(" + generate(18) + ")(" + "".join(map(build, args)) + ")" def Lt(*args): return "(" + generate(19) + ")(" + "".join(map(build, args)) + ")" def Gt(*args): return "(" + generate(20) + ")(" + "".join(map(build, args)) + ")" def Eq(*args): return "(" + generate(21) + ")(" + "".join(map(build, args)) + ")" def Ne(*args): return "(" + generate(22) + ")(" + "".join(map(build, args)) + ")" def Le(*args): return "(" + generate(23) + ")(" + "".join(map(build, args)) + ")" def Ge(*args): return "(" + generate(24) + ")(" + "".join(map(build, args)) + ")"
You can use it like this, type in:
from bogen import * print(Out(Add(Inp(),Inp())))
to get:
(()()()()()()()()()()()()()()()())((()())((()()()()()()()()()()()())()(()()()()()()()()()()()())()))
Or type in:
from bogen import * print(Outc(52))
to get:
(()()()()()()()()()()()()()()()()()())(()()()()()()(()()()())((()())(()()()()()()()()()()()()()())(()())(()()()()()()()()()()()()()())))
Most of the example programs you see here are actually generated with bogen.
File extensions
Currently, recommended file extensions for this esolang are .()
, .bo
and .bracketonly
.