Skip to content

Instantly share code, notes, and snippets.

@Villane
Forked from anonymous/MatrixDemo.slang
Last active December 15, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Villane/3fb491d0147da7d564fc to your computer and use it in GitHub Desktop.
Save Villane/3fb491d0147da7d564fc to your computer and use it in GitHub Desktop.
// juxtaposition is a magic name, topLevel=false means juxtaposition cannot be parsed by itself
// it has to appear in a hole of another operator (that other operator must have a precedence relation to it)
group juxtaposition(topLevel = false)
// … denotes operator holes
// ⁕ means that the previous name part is a separator, and the operator is variadic
group matrixBrackets = "⟦…,⁕…⟧"
// usually, any expression can appear in internal holes of operators, however juxtaposition cannot because topLevel=false
// => means juxtaposition is allowed in the internal holes of matrixBrackets
// (-> would mean is allowed in non-internal i.e. left or right holes, however matrixBrackets doesn't have any)
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
// juxtaposition is only allowed to appear in internal holes of matrixBrackets
// the holes are separated by commas
def createAMatrix() = ⟦1 2,
3 4⟧
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment