Skip to content

Instantly share code, notes, and snippets.

@clone1018
Created November 6, 2013 16:51
Show Gist options
  • Save clone1018/7339684 to your computer and use it in GitHub Desktop.
Save clone1018/7339684 to your computer and use it in GitHub Desktop.

Dimond

Random programming language ideas. (The name drops the letter 'a', as in a certain other language's name)

Types

"string"
'string' # alternate string syntax
/regex/
%regex%  # alternate regex syntax
<>xml<>
{lambda}
(list)   # automatically detected as an array/hash/object
@(array)
%(hash)
&(object)
$variable
# comment
#* block comment *#

Variable types

$!lambda
$%hash
$@array
$&object
$#integer
$.float
$"string
$/regex
$<xml
${Object}anything

Other reserved type prefixes: '~[^$

Variable Naming

\$(<type>{\w+}|[^\w\s])?(<name>\w+)

Lists, arrays, hashes, and objects

# arrays may only consist of integer keys
@(0; 'hi'; 'two'; 3; 4)

# hashes allow named elements
%(one: 1; item: 'foo')

# objects allow special overrides
&(
        property: value

    extra: {
	    print 'hello'
    }

    get extra: {
	    return 'hi'
    }

    get __property__: {
    }

    get __method__: {
    }
)

Null Object

The null object contains parameters passed to a lambda

$~named    # named argument
$['named'] # also valid
$[0]       # unnamed argument
$$         # object itself

Examples:

define hello {
    print 'Hello ' . $~place
}

# prints 'Hello world'
hello(place: 'world')

define hello2 {
    print 'Hello ' . $[0]
}

# prints 'Hello world'
hello2('world')

Newlines equate to semicolons

Valid:

if $var == 'foo' {
}

Invalid:

if $var == 'foo'
{
}

Translates to:

if $var == 'foo';
{
}

Last variable within a lambda is automatically returned

Returns 'asdf':

{
    'asdf'
}

Routes

$/{ '/hello/:name'~replace(/:(\w+)/, '(<name>\w+)')) }
$route~get('/hello/:name'; {
    # Need the raw variable?  Use the XML $<, everything else is escaped.
    <>
        <!doctype html>
	    <h1>Hello $~name!</h1>
    <>
})

Perl-style unless

unless $var {
    print 'asdf';
}

XML Templates

<>
    <ul>
	    $foo~each({
		    <><li>$~item</li><>
	    })
    </ul>
<>

Language extensions

define name
define operator name
define unary operator name
define binary operator name
define ternary operator name1 name2


if 2 in (1;2;3) {
    # foo
} else {
	# bar
}

each 1..5 {
}

for {$i=0; $i<1; $i++} {
}

while true {
}

each $array {
	print "$~key: $~value"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment