Skip to content

William8915/stax

 
 

Repository files navigation

Stax

Stax Golfing Language

Run and debug stax online.

Have you ever noticed that software is just too big? Hello world mobile apps are tens of megabytes. Websites are making hundreds of requests for a single page. There's just too much stuff. Stax is the answer! Unfortunately, it's the answer to another question. That question is "is it possible to make another golfing language?". It's not possible to write a mobile app or website in stax, but if it was, they'd probably be extremely small. Don't make the mistake of thinking that means "efficient". If you want a more efficient language, you should probably try any other language. But small, definitely.

Stax is yet another stack-based programming language, optimized for code golf. Stax is influenced by GS2, 05AB1E, and others. Stax is written in printable ASCII characters, although it can be optionally packed into bytes. For more detail check the docs. Or, you know, the code.

Types

Falsy values are numeric zeroes and empty arrays. All other values are truthy.

  • Integer Aribitrary size
  • Float Standard double precision
  • Rational Fractions of integers
  • Block Reference to unexecuted code for map/filter/etc
  • Array Heterogeneous lists of any values

Strings are not a type in stax. Strings are represented as arrays of integer codepoints. There are specific instructions to treat these as strings. For instance P will output an array as if it was a string, followed by a newline.

Features

Stax does lots of stuff, but here are the highlights and most interesting.

Compressed string literals

Stax has a variant of string literals suitable for compressing English-like text with no special characters. It is compressed using Huffman codes. It uses a different set of Huffman codes for every pair of preceding characters. The character weights were derived from a large corpus of English-like text. "Hello, World!" could be written as `jaH1"jS3!`. The language comes with a compression utility.

Rationals

Stax supports fraction arithmetic. You can use u to turn an integer upside down. So 3u yields 1/3. Fractions are always in reduced terms. 3u 6* multiplies 1/3 by 6, but the result will be 2/1.

PackedStax

PackedStax is an alternative representation for Stax code. It is never ambiguous with Stax, since PackedStax always has the leading bit of the first byte set. That means the same interpreter can be used for both representations with no extra information. For ease of clipboard use, PackedStax can be represented using a modified CP437 character encoding. It yields ~18% savings over ASCII.

Annotator

Golfing languages are pretty unreadable by their nature. But Stax comes with an annotation feature to break down a program into individual instructions and explain each one in English.

About

Stax Golfing Language

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 74.1%
  • C# 25.8%
  • Other 0.1%