Skip to content

Instantly share code, notes, and snippets.

@JosephLenton
Last active August 29, 2015 13:56
Show Gist options
  • Save JosephLenton/8929980 to your computer and use it in GitHub Desktop.
Save JosephLenton/8929980 to your computer and use it in GitHub Desktop.
Plastique, a programming language idea
Code flush with the left side is markdown comments.
---
block comments are started and ended with a triple hyphen
Markdown can be used in normal comments too denoted with a triple dot.
* 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 hyphen 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
or
doWork = \ a b \ return a + b
The second \ is optional, you can just use end of line.
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]
# Literals
## strings
### Hash-strings
Tokens that start with a # will be seen as a string.
This is for CSS/GUI work.
-- set the button background to off-white
button.style.background = #eee
### Number-strings
Numbers that end with text become strings.
This is for GUI stuff.
div.style.marginLeft = 10px
div.style.height = 100%
### Double Quoted Strings
Double-quote strings are multi-line.
paragraph = "some text
which continues
for multiple
lines"
### Single Quoted Strings
Single-quote strings continue until the end of line, or until a closing quote.
div.style.margin = '0 auto 0 auto'
-- this string hasn't been closed
div.style.padding = '10px 0 20px 0
### Literal Objects
Objects are created in one of three ways ...
The 'obj' keyword
someObj = obj
text "click me"
class "button class"
someObj =
obj
text "click me"
class "button class"
The *
someObj = *
text "click me"
class *button class*
# alternatively
someObj =
*
text "click me"
class *button class*
someObj =
* text "click me"
class *button class*
You can also create objects using braces
someObj = {
text "click me"
class *button class*
}
someObj = { x 1 }
Properties can be delimited using commas
someObj = { x 1, y 2 }
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 }
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"
Objects can have an anonymous 'constructor' for that particular object.
It is defined as a function with no name or arguments.
return {
\
this[ 'blah' ] = 'foobar'
}
This translates into the JavaScript code
return (function() {
this['blah'] = 'foobar';
}).call( { } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment