SOAP

From Esolang
Jump to navigation Jump to search
Not to be confused with Sōap.

SOAP (the name standing for Set Oriented Arithmetic Programming) is an esolang by User:BoundedBeans. Many esolangs use stacks, queues, tapes, or accumulators to store data, but not many have done sets.

Storage

SOAP has one single set of natural numbers, excluding zero. Since sets cannot be indexed, it is tricky to actually access the data, but it can be done by checking membership of a specific item, which can be treated as a boolean.

Literals

In order to check for membership, we need a way to represent integers. This is done in base 3 (ternary), just to be a bit annoying. Set literals are the only literal ever used alone, done with {(integer),(integer),…} with integer literals. For example, a set containing 5, 17, 203, and 204 would be {12,122,21112,21120}. Set literals are used for checking things like subsets. The empty set can be written with Ø, though it doesn't have a ton of use. Integers can also be represented with %, which is a variable number that can be used as a kind of pointer to the set.

Instructions

Command Description
*integer Flip the membership of the integer in the main set
"character Print the character to the console
set Store the union of the main set and the specified set in the main set
set Store the intersection of the main set and the specified set in the main set
-set Store the difference of the main set and the specified set in the main set
_set Store the difference of the specified set and the main set in the main set
c Replace the main set by its complement
set[instructions] Execute the instructions as long as the main set is a subset of the specified set
set[instructions] Execute the instructions as long as the main set is a proper subset of the specified set
set[instructions] Execute the instructions as long as the main set is not a subset of the specified set
set[instructions] Execute the instructions as long as the main set is a superset of the specified set
set[instructions] Execute the instructions as long as the main set is a proper superset of the specified set
set[instructions] Execute the instructions as long as the main set is not a superset of the specified set
=set[instructions] Execute the instructions as long as the main set is equal to the specified set
: Increment the variable % by one
; Decrement the variable % by one
~ Accept a character input and store it in the current character
'character/code\ Execute the code once if the last user input character equals the specified character

SOAPI

SOAPI is a variant of SOAP which uses only 1-byte ANSI symbols (and then the symbols not in basic ASCII are only used for printing). This variant, instead of printing out Unicode characters, prints out raw bytes (though non-printable characters must be inserted into the program somehow to test for their input or output them). Along with this restriction, the following table is used for converting SOAP's operators to ANSI:

∪ - U
∩ - I
⊆ - s
⊂ - p
⊄ - n
⊇ - S
⊃ - P
⊅ - N
Ø - E

While this takes away a lot of the fun achieved by copy and pasting weird characters you never need to use otherwise, it also makes it compatible with tools that don't work well with Unicode, such as sed or standard C. It is also the only way to do binary I/O (along with 256 checks on both input and output), since the original SOAP standard says "Print the character to the console" and not "Print the byte to the console".

SOAPI also has two non-standard extensions:

  1. If the first character in the program is an octothorpe (#), it is a comment until the next line. (This is to allow the shebang in Unix.)
  2. Comments are allowed, beginning with $^ and ending with @. SOAPI reserves comments starting with $^! for extensions to the language, so feel free to implement whatever there. SOAPI also reserves comments starting with $^? for further expansion.

SOAPI could be considered a wimpmode to SOAP.

Computational class

BitChanger can be trivially substituted into this language, making it Turing-complete.

} - *%:
< - ;
[ - ⊇{%}[
] - ]

This kind of misses the point of the language, though.

Examples

Hello world

"H"e"l"l"o"," "W"o"r"l"d"!

Truth-machine

*1~'0/"0\'1/⊇{1}["1]\

The same program written in SOAPI:

*1~'0/"0\'1/S{1}["1]\

Cat program

This infinitely repeating cat program processes the printable character in the ASCII code range from inclusive 32 through inclusive 255:

*1⊇{1}[~
' /" \
'!/"!\
'"/""\
'#/"#\
'$/"$\
'%/"%\
'&/"&\
''/"'\
'(/"(\
')/")\
'*/"*\
'+/"+\
',/",\
'-/"-\
'./".\
'//"/\
'0/"0\
'1/"1\
'2/"2\
'3/"3\
'4/"4\
'5/"5\
'6/"6\
'7/"7\
'8/"8\
'9/"9\
':/":\
';/";\
'</"<\
'=/"=\
'>/">\
'?/"?\
'@/"@\
'A/"A\
'B/"B\
'C/"C\
'D/"D\
'E/"E\
'F/"F\
'G/"G\
'H/"H\
'I/"I\
'J/"J\
'K/"K\
'L/"L\
'M/"M\
'N/"N\
'O/"O\
'P/"P\
'Q/"Q\
'R/"R\
'S/"S\
'T/"T\
'U/"U\
'V/"V\
'W/"W\
'X/"X\
'Y/"Y\
'Z/"Z\
'[/"[\
'\/"\\
']/"]\
'^/"^\
'_/"_\
'`/"`\
'a/"a\
'b/"b\
'c/"c\
'd/"d\
'e/"e\
'f/"f\
'g/"g\
'h/"h\
'i/"i\
'j/"j\
'k/"k\
'l/"l\
'm/"m\
'n/"n\
'o/"o\
'p/"p\
'q/"q\
'r/"r\
's/"s\
't/"t\
'u/"u\
'v/"v\
'w/"w\
'x/"x\
'y/"y\
'z/"z\
'{/"{\
'|/"|\
'}/"}\
'~/"~\
' /" \
'¡/"¡\
'¢/"¢\
'£/"£\
'¤/"¤\
'¥/"¥\
'¦/"¦\
'§/"§\
'¨/"¨\
'©/"©\
'ª/"ª\
'«/"«\
'¬/"¬\
'­/"­\
'®/"®\
'¯/"¯\
'°/"°\
'±/"±\
'²/"²\
'³/"³\
'´/"´\
'µ/"µ\
'¶/"¶\
'·/"·\
'¸/"¸\
'¹/"¹\
'º/"º\
'»/"»\
'¼/"¼\
'½/"½\
'¾/"¾\
'¿/"¿\
'À/"À\
'Á/"Á\
'Â/"Â\
'Ã/"Ã\
'Ä/"Ä\
'Å/"Å\
'Æ/"Æ\
'Ç/"Ç\
'È/"È\
'É/"É\
'Ê/"Ê\
'Ë/"Ë\
'Ì/"Ì\
'Í/"Í\
'Î/"Î\
'Ï/"Ï\
'Ð/"Ð\
'Ñ/"Ñ\
'Ò/"Ò\
'Ó/"Ó\
'Ô/"Ô\
'Õ/"Õ\
'Ö/"Ö\
'×/"×\
'Ø/"Ø\
'Ù/"Ù\
'Ú/"Ú\
'Û/"Û\
'Ü/"Ü\
'Ý/"Ý\
'Þ/"Þ\
'ß/"ß\
'à/"à\
'á/"á\
'â/"â\
'ã/"ã\
'ä/"ä\
'å/"å\
'æ/"æ\
'ç/"ç\
'è/"è\
'é/"é\
'ê/"ê\
'ë/"ë\
'ì/"ì\
'í/"í\
'î/"î\
'ï/"ï\
'ð/"ð\
'ñ/"ñ\
'ò/"ò\
'ó/"ó\
'ô/"ô\
'õ/"õ\
'ö/"ö\
'÷/"÷\
'ø/"ø\
'ù/"ù\
'ú/"ú\
'û/"û\
'ü/"ü\
'ý/"ý\
'þ/"þ\
'ÿ/"ÿ\
]

Variable incrementation and iteration

The following program utilizes the sole variable, %, in order to print the message “Ha” three times in immediate succession. To this end % is incremented until it eludes the main set's content {1, 2, 3}.

*1*2*10
⊇{%}["H"a :]

Variable decrementation and iteration

The following program utilizes the sole variable, %, in order to print the message “Ha” three times in immediate succession. To this end % is decremented until it eludes the main set's content {2, 3, 4}.

*2*10*11
:::
⊇{%}["H"a ;]

Deadfish

Deadfish#SOAP

Interpreter

  • Common Lisp implementation of the SOAP programming language. Please note that the concrete character set deployed constitutes a dependency on the Common Lisp implementation; in corollary, Unicode support may or may not be a feature incorporated in the personal environment. The interpreter at hand has been developed and tested with Steel Bank Common Lisp (SBCL) version 1.1.4 as part of the Lisp Cabinet 0.3.5 bundle.
  • Copy of the above Common Lisp implementation with a few changes:
    • Try it online! (Deadfish program is already loaded. Put SOAP program, a blank line, and input to the SOAP program into the input box.)
    • Merged into one file to be run on tio.run
    • Fixed some bugs (the % variable and decrementation now work)
    • SOAP programs now have to make their own prompts
    • Keep in mind that I (User:BoundedBeans) really don't know Common Lisp at all and the style might be bad.
  • detergent, the SOAPI interpreter in Ada, located here

To run both Common Lisp implementations:

  1. Escape quotes and backslashes in your program (Do not escape newlines).
  2. Add (interpret-SOAP "your code") to the end of main.lisp
    • A new addition allows you to use the (load-SOAP-script) at the end of the code. Then you can pass (through STDIN) the SOAP program, followed by a blank line, followed by input to the SOAP program.
  3. If running in the first implementation:
    • You probably want to empty tests.lisp