Last active
July 17, 2018 13:28
-
-
Save izolate/915ac0167f146917c485 to your computer and use it in GitHub Desktop.
Dream Language
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
# This is a single line comment | |
/* | |
This is a multi-line comment, | |
useful for when you have lots to say. | |
*/ | |
# Arithmetic | |
5 + 5 # 10 | |
5 - 5 # 0 | |
5 * 5 # 25 | |
5 / 5 # 1 | |
5**3 # 125 | |
# Boolean & Special types | |
True | |
False | |
Nil | |
# Logical operators | |
True and False # false | |
True or False # true | |
not True # false | |
# Alternate "not" syntax | |
!True # false | |
!!True # true | |
# Expressions | |
True is True # True | |
True == False # False | |
# Strings | |
'This is a string' | |
print('Some text') # Some text | |
# Variables | |
x = 10 | |
prefer_snake_case = True | |
# Strings | |
animal = 'dog' | |
interpolation = 'the brown fox jumped over the lazy {animal}' | |
# Lists | |
list = [1, 2, 3] | |
is_odd = list.filter(i: i % 2 is not 0) | |
# Maps | |
map = { | |
key: 'value', | |
hyphens-allowed: True, | |
animal, | |
} | |
# Control structures | |
if True { | |
print('nice') | |
} else if False { | |
print('sorry') | |
} else { | |
print('dunno') | |
} | |
for num, i in ['zero', 'one', 'two'] { | |
print('Number "{i}" is pronounced: "{num}"') | |
} | |
# Functions | |
func sum(x, y) { | |
return x + y | |
} | |
sum(3, 6) # 9 | |
# Modules | |
# lib/math.lang | |
give func sum(x, y) { | |
return x + y | |
} | |
# app.lang | |
take sum from 'Math' | |
print('3 + 6 = {sum(3, 6)}') | |
# Example | |
take Fetch from 'fetch' | |
Fetch('http://example.com/api/endpoint', { | |
method: 'get', | |
}).then(+(response) { | |
print('response is {response.data}') | |
}).catch(+(error) { | |
print('error: {err.message}') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment