Theoretica

From Esolang
Jump to: navigation, search

Theoretica is a theoretical language. No accurate-to-spec implementation of Theoretica can be produced on a physical machine, as an implementation would require not only infinite memory, but also infinite runtime.

Description

The language is based around operating on sequences, and the language's functions can be split into 3 categories:

  • Generators
  • Operators
  • Flow control

Input is implicit to a dedicated input stack, and the result of generators are stored in a second "infinite" stack.

Generators

Theoretica contains a generator builtin for any conceivable sequence of numbers, however those referenced by the spec are:

   i    Generates an infinite collection of positive integers, starting at 0, in ascending order
   I    Generates an infinite collection of negative integers, starting at 0, in descending order
   !    Generates an infinite collection of positive factorials, starting at 0!, in ascending order
   p    Generates an infinite collection of primes, starting at 2, in ascending order
   ^#   Generates an infinite collection of # exponents, starting at 1^#, in ascending order
   #^   Generates an infinite collection of exponents of #, starting at #^1, in ascending order
   m#   Generates an infinite collection of positive multiples of #, starting at 1#, in ascending order
   f    Generates an infinite Fibonacci sequence, starting at 0, in ascending order
   s"#" Generates an infinitely repeating collection of the ASCII values of #, uses input if # is not given

Operators

All Theoretica operators are designed to operate on an infinite collection generated by a generator.

   +    Sum the collection
   R    Sort the collection into a random order
   ;#   Return the #th item of the collection
   _    Print
   @    Print as ASCII characters
   ?    Print the result of the last conditional, as either "true" or "false"
   :#   Concatenate the collection to the first # items
   l    Get the length of the input
   ~#x  Convert # to base x

Flow Control

Theoretica includes only basic flow control

   c    If any item in the input stack is contained in the generator stack, run the next symbol
   C    If no items in the input stack are contained in the generator stack, run the next symbol
   >    Move to the start of the next line
   <    Move to the start of the previous line

Examples

cat

   _
   <

Infinite loop, keep printing.

Hello, World!

   s"Hello, World!":12@

Generate an infinitely repeating array of the ASCII values of "Hello, World!", concatenate it to the first 12 items, then print the resulting array

Square check

   ^2c>
   ?

Generate an infinite array of squares, check if the input is contained in that infinite array, if it is, run >, skipping to the start of the next line, which then prints the result of the last conditional. Otherwise, skip the >, and hit the end of the line, wrapping down to the start of the next line, which then prints the result of the last conditional.

Prints "true" if the input is a Square, and "false" otherwise.

Prime check

   pc>
   ?

Same as the square check, but with primes

Factorial check

   !c>
   ?

Same as the square check, but with factorials