Underload

From Esolang

Jump to: navigation, search

Underload is a stack-based esoteric programming language that works along similar lines to Muriel. It was created by User:ais523 in 2006. Although not technically speaking a functional language, its evaluation operator ^ (which is the only form of flow control) makes programming in it functional in practice.

Contents

[edit] Reserved characters

The bracket and angle bracket characters []<> are reserved; if these are to appear anywhere in the program, they must be quoted by placing " before them. This also applies to the " character itself. Other characters must not be quoted with " (in particular, this means that Underload programs cannot output strings containing unmatched parentheses). Parentheses are moderately reserved, in that any Underload program must have matched parentheses to be legal. However, no known interpreter ever, not even the reference interpreter, seems to have implemented any part of this other than the rules about parentheses, and this is therefore arguably not part of the language.

[edit] Commands

  • ~ Swap the top two elements of the stack.
  • : Duplicate the top element of the stack.
  • ! Discard the top element of the stack.
  • * Concatenate the top element of the stack to the end of the second element of the stack.
  • ( Push everything between the ( and the matching ) on top of the stack.
  • ) Closes a ( command.
  • a Encloses the top element of the stack in a pair of parentheses.
  • ^ When the ^ command is called, it includes the top element of the stack into the program rather than the stack, immediately after the ^ command, ready to be run next; this effectively pops the stack.
  • S Output the top element of the stack, popping it.

[edit] Exceptional circumstances

Pretty much anything whose behaviour isn't specifically given here (for instance, running * on an empty stack) is an error.

[edit] Unlambda to Underload

The s, k, and i and v characters in Unlambda can all be translated directly into Underload. Also, the ` character can be translated, but it has to be moved to a postfix rather than prefix position, and .x can be translated for most values of x.

  • s translates to ((:)~*(~)*a(~*(~^)*)*):
    sx`y`z` = xz`yz`` (postfix notation)
    sx`y`   = (:x~y~^)
    sx`     = ((:x~)~*(~^)*)
    s       = ((:)~*(~)*a(~*(~^)*)*)
  • k translates to (a(!)~*)
  • i translates to ()
  • v translates to ((~!a(:^)*):^)
  • ` translates to ~^
  • .x translates to ((x)S)

These translations prove that Underload is Turing-complete, because it can be compiled into from the Turing-complete `sk Unlambda.

[edit] Examples

[edit] 99 bottles of beer

Available here.

[edit] Factorial

(outputs the factorial of however many colons are in the first set of parentheses)

(:::::::):(:((^:()~((:)*~^)a~*^!!()~^))~*()~^^)~(^a(*~^)*a~*()~^!()~^)a~**^!!^S

[edit] Fibonacci sequence

(()(*))(~:^:S*a~^a~!~*~:(/)S^):^

[edit] Hello, world!

(Hello, world!)S

[edit] Infinite loop

(:^):^

[edit] Quine

(:aSS):aSS

[edit] Palindromic quine

(:aS(:^S^:)Sa:):^S^:(:aS(:^S^:)Sa:)

[edit] Self-interpreter

()^

This interpreter doesn't do any error handling. Give the input, a valid Underload program, by placing it inside the parentheses and then run the program. This is the only way to feed input, as the language doesn't have an input feature.

[edit] External resources

The information in the original version of this article was taken from the public-domain Underload specification.

Personal tools