munificent / magpie

The Magpie programming language.

Clone this repository (size: 897.6 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/munificent/magpie/

Unlike many languages, Magpie does not have a built in set of operators. Instead, an operator is simply another kind of user-defined function. An operator takes two arguments and the operator itself appears between them.

Magpie includes many built-in operators, but users may also define their own operators. Examples:

1 + 2 / 3
a | b
"foo" ++ "bar"
apple --/-> banana

Under the hood, operators are regular functions, so the above are essentially syntactic sugar for the following:

+ (1, / (2, 3))
| (a, b)
++ ("foo", "bar")
--/-> (apple, banana)

Magpie does not have prefix or postfix unary operators. Prefix arithmetic operators in Magpie use regular function calls, and postfix operators are not used:

a = -b;     // C
a = Neg b   // magpie

a = !b;     // C
a = Not b   // magpie

Associativity

Operators associate to the left, and all have the same precedence. Like Smalltalk, Magpie does not have built-in arithmetic operator precendence like you learned in school. 1 + 2 * 3 evaluates to 9 in Magpie, not 7 as it would in textbook arithmetic or in C. Since users are free to define their own arbitrary operators, it would be impossible for Magpie to have the "right" operator precedence built in for all use cases. Instead, parentheses must be used.


This revision is from 2009-11-17 05:22