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
| Code flush with the left side is markdown comments. | |
| /// | |
| block comments are started and ended with a triple slash | |
| Markdown can be used in normal comments too denoted with a triple slash. | |
| * 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 | |
| /// | |
| // double slash for a single comment | |
| function calls don't require parenthesis | |
| alert "blah" | |
| console.log someObj ", " otherValue | |
| Statements are seperated with an end of line or a comma | |
| a = 1, b = 2, c = a + b | |
| 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' | |
| 0 <= i and i < users.length | |
| users[i].update | |
| 'all' is an operator that allows multiple rules to be listed, | |
| this is to avoid long 'this and, that and, something and, rule and' | |
| all | |
| 0 <= i | |
| i < users.lenght | |
| # updating one more inside 'all of', ends it | |
| users[i].update | |
| the 'or' version of 'all' | |
| any | |
| post.owner_id == user.id | |
| user.is_admin | |
| // success! | |
| edit port user | |
| A longer example, converting my .forward rules into this language | |
| any of | |
| # block those fucking mails from Dr Oz | |
| header_from.contains "Dr. Oz" | |
| header_from.contains "Dr.Oz" | |
| header_from.contains "DrOz" | |
| header_from.contains "DoctorOZ" | |
| header_from.contains "OZ Daily News" | |
| header_from.contains "USA SlimSystem" | |
| header_from.contains "LifeHealthPro" | |
| header_from.contains "Viagra" | |
| header_from.contains "viagra" | |
| header_from.contains "Viiagra" | |
| header_from.contains "viiagra" | |
| header_from.contains "Viagrra" | |
| header_from.contains "viagrra" | |
| header_from.contains "Pfizer" | |
| # bullshit mail adverts | |
| header_subject: contains "Instantly boost your website" | |
| header_subject: contains "This Stock is in the news" | |
| # both from and subject start with Chinese ... | |
| any of | |
| header_from.begins "=?utf-8?B?4" | |
| header_from.begins "=?utf-8?B?5" | |
| header_from.begins "=?utf-8?B?6" | |
| header_from.begins "=?utf-8?B?7" | |
| and any of | |
| header_subject.begins "=?utf-8?B?4" | |
| header_subject.begins "=?utf-8?B?5" | |
| header_subject.begins "=?utf-8?B?6" | |
| header_subject.begins "=?utf-8?B?7" | |
| # any mail in chinese (I can't read it even if it's legit) | |
| header_content-type.contains "charset=\"GB2312\"" | |
| # success of if here! | |
| # kill the mail! | |
| fail | |
| for loop using an iterator is denoted using the 'in' keyword | |
| key in array | |
| console.log key array[key] | |
| For loop using normal iteration uses 'to' keyword. | |
| i will be initialized to 0 by default. | |
| i to arguments.length | |
| puts arguments[i] | |
| iterates from 1 to 3 | |
| start = 1 | |
| end = 3 | |
| i = start to end | |
| puts i | |
| alternative which states where the i starts from; from 1 to arguments.length | |
| i = 1 to arguments.length | |
| puts arguments[i] | |
| this is counting down | |
| i = arguments.length - 1 to 0 step -1 | |
| puts arguments[i] | |
| object descriptor | |
| uses end of line to delimit different items | |
| someObj = { | |
| text "click me" | |
| class "button class" | |
| } | |
| closing the brace is optional | |
| denoted through indentation | |
| someObj = { | |
| text "click me" | |
| class "button class" | |
| can also have keys on their own, with no value | |
| names = { | |
| john | |
| brian | |
| al | |
| sam | |
| this is the same as doing ... | |
| names = { | |
| john undefined | |
| brian undefined | |
| al undefined | |
| sam undefined | |
| } | |
| can also use commas | |
| point = { x 3, y 9 } | |
| can also use parenthesis | |
| point = { (x 3) (y 9) } | |
| all of these also work with the 'obj' keyword | |
| point = obj x 3, y 9 | |
| point = obj (x 3) (y 9) | |
| names = obj | |
| john | |
| brian | |
| al | |
| sam | |
| array can be started with the 'array' keyword | |
| ns = array 1 2 3 4 5 | |
| also works with multiple lines | |
| ns = array | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 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