Skip to content

Instantly share code, notes, and snippets.

@rummik
Last active April 10, 2019 04:44
Show Gist options
  • Save rummik/9726111 to your computer and use it in GitHub Desktop.
Save rummik/9726111 to your computer and use it in GitHub Desktop.
Random Dimond code examples
#**
* 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()
}
}
}
#**
* If statement
*
* @example
* if $condition {
* ...
* }
*#
define { ???, Function } 'if' {
{ $condition, $body } = $$~arguments
$condition && $body()
}
#**
* Unless statement
*
* @example
* unless $condition {
* ...
* }
*#
define { ???, Function } 'unless' {
{ $condition, $body } = $$~arguments
$condition || $body()
}
@anoxic
Copy link

anoxic commented Apr 10, 2019

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