A Pear Tree

From Esolang
Jump to navigation Jump to search

A Pear Tree is a trivial derivative of Perl created by User:ais523 in 2016, mostly as a joke. It aims to mildly modify the language to make it more suitable for writing polyglots (i.e. programs that run correctly in more than one language), particularly with Python 3.

The semantics are identical to Perl, except that:

  • Various options are set automatically depending on the presence of input on standard input and on the presence of the letter F in the program;
  • Scalar variables can often be used without the leading $ on their names (see the documentation in the reference interpreter for details);
  • When omitting the leading $, scalar variables that hold array references can be dereferenced with suffix [index] notation;
  • print works like Python (adding a trailing newline, and placing spaces between its arguments);
  • A repr function exists, that returns a string representation of its argument.

Additionally, before running the program, the source code is potentially rotated by moving some of the code from the start to the end (or equivalently, vice versa). The point that becomes the new start of the program is determined by checking all substrings of the program to see if they have a CRC-32 of zero (this condition was chosen because it's easy to bring about intentionally – CRC-32 is not secure against preimage attacks – but unlikely to happen by chance). The start of the longest such substring becomes the start of the program. If there are no appropriate substrings, the interpreter prints a partridge and exits, rather than running the program.

External resources

  • An interpreter (in Perl, obviously) is available here (older version, which doesn't handle array indexing).