Last active
April 10, 2019 04:44
-
-
Save rummik/9726111 to your computer and use it in GitHub Desktop.
Random Dimond code examples
This file contains 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
#** | |
* For statement definition | |
* | |
* @example | |
* for { $i=0; $i<20; $i++ } { | |
* ... | |
* } | |
*# | |
define { Function, Function } 'for' { | |
{ $expression, $body } = $$~arguments | |
{ $initial, $condition, $each } = $expression | |
$expression~scope = $body~scope = $$~stack[-2]~scope | |
$initial() | |
{ | |
unless $condition() { | |
$body() | |
$each() | |
$self() | |
} | |
} | |
} |
This file contains 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
#** | |
* If statement | |
* | |
* @example | |
* if $condition { | |
* ... | |
* } | |
*# | |
define { ???, Function } 'if' { | |
{ $condition, $body } = $$~arguments | |
$condition && $body() | |
} |
This file contains 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
#** | |
* Unless statement | |
* | |
* @example | |
* unless $condition { | |
* ... | |
* } | |
*# | |
define { ???, Function } 'unless' { | |
{ $condition, $body } = $$~arguments | |
$condition || $body() | |
} |
possible way to define lambda parameters
{ -> ( Integer, String )
...
}
or with named parameters
{ -> ( foo:Integer, bar:(String, null) ;; baz:Boolean )
...
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
some assumed operators (from the examples):
roughly, syntax might be (guessing and making a few things up):
i'm basically guessing, "define" is actually a function, and if a function's last argument is a list, you don't need parens to call it. either that, or only functions bound to a variable need the parens.
the last item in a function is what it returns. don't know how early return looks or if it's a thing
i think things inside { .. } are a list that isn't evaluated right away, and you could delimit with comma or newline. i didn't put it above, but maybe a list inside ( .. ) is one whose contents are evaluated right away
also not sure, although i make a specific syntax for assignment, it could actually be where '=' is just an operator that modifies the scope/state and isn't a higher part of the syntax like this
i don't get what the difference between
;
and,
is here. on thefor
example you have;
but everywhere else with the same pattern is,
probably i use totally different words than you would to describe this. also made a bunch of assumptions. anyway, is it anywhere near correct?