User:Gilbert189/A way to golf Baba is You esolangs
This assumes that standard Baba is You syntax and blocks are used. I'm using cp437 as the character inventory.
Step 1: Replace keywords to characters
Let's start simple first. Objects are represented as letters, including ones with diacritics, and line characters. Additional ones are:
" TEXT · EMPTY ⌂ ALL ♣ GROUP, could use ♥, ♦, or ♠ as other GROUPs @ LEVEL _ CURSOR █ IMAGE
Operators are represented by symbols. Here's the list of them.
= IS . HAS + MAKE & AND ! NOT ± ON π NEAR | FACING ¿ LONELY Γ FEAR * EAT ≡ MIMIC ° IDLE ‼ POWERED ¿ WITHOUT ↑ ABOVE ↓ BELOW ↔ BESIDE (← and → can also be used) § FEELING ♫ PLAY ` OFTEN , SELDOM
Properties are also represented by symbols. Here's the list of them.
▲ UP ▼ DOWN ◄ LEFT ► RIGHT / BROKEN ? CHILL ^ BACK ↨ FALL (can be prefixed with UP, DOWN, LEFT, and RIGHT) ∙ NUDGE (can be prefixed with UP, DOWN, LEFT, and RIGHT) ♂ TURN (can be prefixed with LEFT (ccw), and RIGHT (cw)) ⌠ FLOAT $ PHANTOM ' HIDE ▄ HOT ▀ MELT % MORE ÷ MOVE ↕ REVERSE • OPEN ◘ SHUT ¡ POWER < PULL > PUSH ε SAFE ∟ SHIFT τ SINK φ STILL δ LOCKED (can be prefixed with UP, DOWN, LEFT, and RIGHT) ■ STOP [ SWAP ] TELE ⌡ WEAK ♪ WIN ¶ WORD ☺ YOU ☻ YOU2 £ BONUS » END « DONE ½ REVERT ¼ SELECT √ DEFEAT
If you plug in a hello world program written in Babalang (which fits the criteria of using only BIY syntax and keywords) to this golfer, we get:
A=☺&÷ B=A&A C=B&B D=C&C E=D&D F=E&E G=F&F Æ=♣ H=G&D e=G&F&C&A l=G&F&D&C o=G&F&E&!A ç=F&D&C ñ=F w=G&F&E&D&!A r=G&F&E&B d=G&F&C é=F&A Ñ=D&B Æ.H&e&l&l&o&ç&ñ&w&o&r&l&d&é&Ñ Æ="
We can optimize this code a little bit:
A=☺&÷B=A&AC=B&BD=C&CE=D&DF=E&EG=F&F Æ=♣ H=G&Dÿ=G&Fe=ÿ&C&Al=ÿ&D&Cƒ=ÿ&Eo=ƒ&!Aç=l&!Gñ=Fw=ƒ&D&!Ar=ƒ&Bd=ÿ&Cé=F&AÑ=D&B Æ.H&e&l&l&o&ç&ñ&w&o&r&l&d&é&Ñ Æ="
Step 2: Make ANDs unnecessary
Looking at the right side, we can see that most of the characters on the right side of the rule, especially the last one, are ANDs. We can make this unneccesary, however we have to delimit the rules by a space to disambiguate rules.
A=☺÷ B=AA C=BB D=CC E=DD F=EE G=FF Æ=♣ H=GD ÿ=GF e=ÿCA l=ÿDC ƒ=ÿE o=ƒ!A ç=l!G ñ=F w=ƒD!A r=ƒB d=ÿC é=FA Ñ=DB Æ.HelloçñworldéÑ Æ="
ANDs are still used to handle ambiguity with singleton rule that needs 2 characters (like ♂
) and other things.
It can also combine 2 lines of code that has the same objects. For example, you can combine b±f=s
and b±fΓi
to b±f=s&Γi
.
Step 3: Rule collisions
Baba is You has this, so why not implement them here?
Say you have the lines B=K
and K=☺
. You can combine them like this:
B=K=☺
If translated, this code is a valid Baba is You code, parsed as BABA IS KEKE
and KEKE IS YOU
.
Although not a feature in BIY, I'm going to add property collision as well. This allows B=☺
and K=☺
to be compressed like this:
B=☺=K
If translated to Baba is You, this rule will not make sense there (BABA IS YOU IS KEKE
)
Colliding property/object clusters are also possible. For example, B=☺•ε=K
will be parsed as B=☺•ε
and K=☺•ε
, and B=☺=KM
will be parsed as B=☺
and KM=☺
.
Rule collision can also extend/append rules. For example, B=☺
and K=☺ε
can be collided to this:
B=☺=Kε
Since ε
is a property, it will always be put in the right side of the rule (otherwise the rule doesn't make sense), therefore no ambiguity is created.
Things go weird if you add an object to the mix, though. Say you want to collide B=☺
and KM=☺
. Normally, objects will always be put in the left side of the rule, so these rules can be collided as expected:
B=☺=KM
However, if you want to collide B=☺
and K=☺M
, you have to somehow force M
to the right side of the rule. To do this, you can use the humble AND:
B=☺=K&M
Note that you don't have to do this if you have another operator in the right side of the rule. For example, B=☺
and K=☺.M
can be collided to:
B=☺=K.M
Objects in the right side can also become part of a normal, separate rule. For example,
B=☺=K=ε
is parsed as the rules B=☺
K=☺
K=ε
.
From this, we can reduce the program to this:
A=☺÷ B=AA C=BB D=CC E=DD F=EE G=FF Æ=♣ H=GD ÿ=GF d=ÿC=e&A l=ÿDC ƒ=ÿE o=ƒ!A=w&D ç=l!G ñ=F=é&A r=ƒB Ñ=DB Æ.HelloçñworldéÑ Æ="