Pyth

From Esolang
Jump to navigation Jump to search

Pyth is a procedural programming language which is designed to be compiled into Python. It is created by isaacg in 2014. Its primary purpose is conciseness, without sacrificing clarity. It is primarily used for code-golfing.

Language Overview

Every function, variable and statement in Pyth is a single character. In addition, each function and statement has a predefined and immutable arity. The arities currently in use are 0,1,2,3 and extensible. Due to these two elements of the language, parentheses are typically unnecessary, except to end extensible functions and statements. Characters are simply written in prefix notation, and the association of arguments to function is left implicit. In addition, when extensible functions and statements must be terminated, the characters used for that purpose are `)`, which ends a single function or statement, and `\`, which ends all functions or statements. In addition, all functions and statements are implicitly end-of-line terminated. There is no concept of matched parentheses.

The execution of a program is a two step process: First, the Pyth program is compiled in a nearly one-to-one correspondence to a Python program, which is then executed in an environment with various predefined variables and functions.

In contrast to popular code golfing languages GolfScript and CJam, Pyth is a procedural language, not stack based, making it clearer for programmers used to procedural languages.

Examples

Hello, World!

This program prints out the words Hello, World!:

"Hello, World!

Two things to note about this example: Printing is implicit in Pyth, and strings, like all extensible constructs in Pyth, are implicitly ended by the end of line.

Quine

This program prints out its own source code:

jN B"jN B
             print(            Implicit, as before
j              join(           Equivalent to Python's str.join method
 N               N,            A variable initialized to the string '"'
   B             [             This is a preceding function expression.
                               B applies the function " " (enclose in parentheses) to the next parameter and makes a two element list with the original value and that.
    "jN B          "jN B",
                   ("jN B")
                 ]
               )
             )

Documentation

Documentation - kept up to date.

External resources