Last active
August 29, 2015 13:56
-
-
Save JosephLenton/8929980 to your computer and use it in GitHub Desktop.
Plastique, a programming language idea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # hash used for comments | |
| /# | |
| # Markdown Comments | |
| Slash # denotes the start of markdown comments. | |
| * which can be used anywhere | |
| * looks cool | |
| * doesn't continue until it sees the same again | |
| even "with code" "placed inside" | |
| code instanceof comment | |
| # #/ is ignored in code examples | |
| #/ | |
| /* | |
| * These comments are also supported, | |
| * namely so you can comment out sections of code | |
| */ | |
| # function calls don't require parenthesis | |
| alert "blah" | |
| console.log obj ", " otherValue | |
| # pipes, the >> operator, for piping a value into another | |
| pane >> bb.add button >> bb.toggleClass 'show' | |
| # functions denoted with \ args \ | |
| # indentation used to show when function ends | |
| doWork = \a b\ | |
| a *= 2 | |
| return a + b | |
| # can also use guards | |
| doWork = \ a b \ | |
| | 0 b | <- 1 | |
| | a b | <- a * b | |
| # can add conditions, which are checked at runtime, but can be optimized out with a flag | |
| doWork = \ a b \ | |
| ensure | |
| a > b | |
| isNumber b | |
| isNumber a | |
| return a + b | |
| # guards with conditions | |
| # ensure can be at start or end | |
| # indentation denotes if used for function or guard | |
| doWork = \ a b \ | |
| | 0 b | | |
| ensure isNumber b | |
| return 1 | |
| | a b | | |
| return a + b | |
| ensure | |
| isNumber a | |
| isNumber b | |
| # : used for type notation | |
| doWork = \ a:number b:number \ | |
| <- a + b | |
| # :: used for full conditions, equal to ensures | |
| doWork = \ (a::isNumber a && a > b) (b::isNumber b) \ | |
| <- a + b | |
| # can be used together | |
| doWork = \ (a:number:: a > b) b:number \ | |
| <- a + b | |
| # if statement starts on indentation after an expression | |
| a > 5 | |
| print a | |
| # also means you can do ... | |
| # 'button.classList' only run if 'button =' evaluates to true | |
| button = dom.querySelector '.button.show' | |
| button.classList.remove 'show' | |
| # 'for' statement, if 'i' does not exist, it is defined on the fly and presumed to be 0 | |
| # otherwise initialized to 0 | |
| for i arguments.length | |
| puts i | |
| # alternative which states where the i starts from; from 1 to arguments.length | |
| for i 1 arguments.length | |
| puts arguments[i] | |
| # this is counting down | |
| for i (arguments.length-1) 0 step -1 | |
| puts arguments[i] | |
| # object descriptor | |
| # uses end of line to delimit different items | |
| obj = { | |
| text "click me" | |
| class "button class" | |
| } | |
| # closing the brace is optional | |
| # denoted through indentation | |
| obj = { | |
| text "click me" | |
| class "button class" | |
| # can also use commas | |
| point = { x 3, y 9 } | |
| # can also use parenthesis | |
| point = { (x 3) (y 9) } | |
| # array description | |
| ns = [ 1 2 3 4 5 ] | |
| # closing the array is optional | |
| ns = [ 1 2 3 4 5 | |
| # however indentation will put things in the array ... | |
| ns = [ 1 2 3 4 5 | |
| print "hello world" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment