-
Notifications
You must be signed in to change notification settings - Fork 1
Syntax
Lloyd Dilley edited this page Jun 17, 2020
·
10 revisions
# Single line comment
##
Multi-line
Comments
##
Functions execute a block of code when called. The last value in the function body becomes its return value.
func add(num1, num2) {
num1 + num2
}
sum = add(5, 3) # sum equals 8
Parentheses are optional in most cases, so the following would work as well:
sum = add 5, 3
Concoct provides the standard set of statements
myVar = true
if myVar
executeFunc()
while myVar
executeFunc()
do
executeFunc()
while myVar
num = 2
switch num {
if 1:
executeFunc1()
# break statements are implicit
if 2:
executeFunc2()
else:
executeFunc3()
}
myArray = [5, "string", 'a', false]
# Either this syntax or possibly a "contains" method for checking array members
if("string" in myArray)
print "Array contains string"
for element in array
print element
for num in range(5)
print num
Classes are for object-oriented designs, and they can optionally be grouped in namespaces.
namespace RPG {
class Entity {
func new(name) {
self.name = name
self.health = 100
}
}
class Player : Entity {
func new() : super("Player Name") {
}
func take_damage(amount) {
self.health -= amount
}
}
}
player = new RPG.Player()
player.take_damage(13)