Skip to content

Instantly share code, notes, and snippets.

Created April 2, 2013 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/034395b59ecec2a5a96e to your computer and use it in GitHub Desktop.
Save anonymous/034395b59ecec2a5a96e to your computer and use it in GitHub Desktop.
Matrix constructor example with Slang's mixfix operators
group juxtaposition
// … denotes operator holes
// ⁕ denotes that the previous name part is a separator, and the operator is variadic
group matrixBrackets = "⟦…,⁕…⟧"
// at the moment the following rule isn't really needed, because any expression can appear in a closed hole
// (a closed hole is one that has operator name parts on both left and right)
// but if we imagine that an operator group such as juxtaposition could be "disabled by default"
// then we would here say that juxtaposition is allowed to appear in the closed holes of matrixBrackets
matrixBrackets -> juxtaposition
type Row = (a: Int, b: Int)
extending Int {
def juxtaposition(that: Int): Row = (this, that)
}
// at the moment ⟦…,⁕…⟧ is not a valid identifier unless wrapped in `...`
def `⟦…,⁕…⟧`(row1: Row, row2: Row) = // create matrix
// since juxtaposition is defined to bind more tightly than matrixBrackets, it can appear in these holes
// separated by commas
def main() = ⟦1 2,
3 4⟧
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment