Flurry

From Esolang
Jump to navigation Jump to search

Flurry is a strictly evaluated functional programming language created by User:Challenger5 and inspired by Brain-Flak.

Definition

The main difference from Brain-Flak is that there is only one stack, which contains only functions. Functions are allowed to modify the stack, but are otherwise pure.

All nilads and monads return functions. Rather than denoting integer addition, juxtaposition denotes function application.

Nilads take no arguments and return a function. There are four of them:

  • [] evaluates to the height of the stack as a Church numeral.
  • () evaluates to the K combinator.
  • <> evaluates to the S combinator.
  • {} evaluates to a value popped off the stack or to the I combinator if the stack is empty.

Monads enclose one or more operations (nilads or monads) and return a function. There are four of them:

  • [abc] reduces abc by function application and then returns the result. It essentially serves as a grouping operator like parentheses.
  • (abc) reduces abc by function application, and then pushes the result to the stack, returning it.
  • <abc> reduces abc by function composition and then returns the result.
  • {abc} returns a function that:
    • Takes a single argument and pushes that argument to the stack.
    • Reduces abc by function application.
    • Returns the result.

The program is a list of zero or more nilads and monads. The initial stack content is the Church-encoded representation of the input.

Snippets

Numbers

Literal 0:

[<>()]

Literal 1 (also the I combinator):

{{}}

Literal 2 and higher:

2 : {<({}){}>}
3 : {<({})({}){}>}
any n : {< `n-1 copies of ({})` {}>}

Arithmetic

Return the successor function for Church numerals (\a b c. b (a b c)):

<><<>()>

Pop two Church numerals and return their sum (or use {<><<>(){}>} for a function of two arguments):

<><<>(){}>{}

Pop two Church numerals and return their product (or use <<>()> for a function of two arguments):

<{}{}>

Pop two Church numerals n m and return m**n:

{}{}

Miscellaneous

Duplicate the top value on the stack and return it:

(({}))

Return the iota combinator (\x. x S K):

{{}<>()}

Swap the top two stack elements:

<[<><<>()[<>{{}}]()>]()[<>{{}}]()>{}{}{{<>()}}
<><<>()<>[<>{{}}]()>[()()]{}{}{{<>()}} -- by Bubbler

Computational Class

Flurry is Turing-complete (even without the stack) since one can directly convert an SK combinator calculus term into Flurry code using only <> (for S), () (for K), and [...] (for function application).

External Links