Monthly Archives: October 2011

Bracket: A bracket-only programming language.

I just came up with a lambda-calculus-based language with my roommate. (Warning!: assumes familiarity with lambda calc.)

EDIT: Curly and square brackets are unnecessary and confusing. Future versions of Bracket will be nice and round:
(XY) –> (()XY)
{XY} –> (XY)
[X] –> (X)

This leads to a single elegant function (), which can take 0-3 arguments:
() is the lambda metaprocedure
(X) is an identifier
(XY) is the procedure X applied to argument Y
(MXY) is the metaprocedure M applied to arguments X and Y

This simplifies the language, and should therefore make code much more readable. It also helps me achieve my goal of creating the purest form of LISP: one in which there are no data types and no keywords — only parentheses. (Everything (must (be parentheses))).

ENDEDIT.

Here’s the syntax for Bracket:
(XY): the lambda expression λX.Y, where X is an identifier and Y is an expression.
[X]: an identifier (variable) unique to X (that is, [], [[]], [potato] are all unique identifiers.)
{XY}: the expression X applied to Y. Equivalently, {} is just used for grouping, but all lambda expressions must be explicitly grouped with anything they are applied to.

For example, ([][]) is the identity function, [x] is an identifier, and {([][])[x]} = [x].

A program is just an expression that evaluates to a list* of numbers**, which can be translated into a string of characters with
{{P([]([[]]{{C{{[]I}O}}[[]]}))}N}
(the Bracket syntax for Pλx.λy.C(xIO)yN)
Where:
P is the program
C is a function that prepends an ASCII character to a string
I is a function that increments an ASCII character once
O is the ASCII null character 0x00 or \0
N is the empty string “”

*lists are represented in Church encoding, “Higher-order function” style.
**numbers are Church numerals (see the same article)

Now that that’s out of the way, here’s a “Hello World” program: (actually prints “HW” for the sake of brevity)

{{([]([[]]([[[]]]([[[[]]]]{{[[[]]][]}{[[]]{[[[]]][[[[]]]]}}}))))([]([[]]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[][[]]}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}))}{{([]([[]]([[[]]]([[[[]]]]{{[[[]]][]}{[[]]{[[[]]][[[[]]]]}}}))))([]([[]]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[]{[][[]]}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}))}([[[]]]([[[[]]]][[[[]]]]))}}

And here it is in the new, 300% rounder version of Bracket:

(((()(())(()((()))(()(((())))(()((((()))))(((((())))(()))(((()))((((())))((((())))))))))))(()(())(()((()))((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(((()(())(()((()))(()(((())))(()((((()))))(((((())))(()))(((()))((((())))((((())))))))))))(()(())(()((()))((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((())((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(()(((())))(()((((()))))((((()))))))))

Advertisements