-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the DeafShark wiki!
Here I will attempt to keep the language documented.
Variables can either be constant or not. Once a constant variable is defined, its value cannot be changed. Variables are declared using the var
and let
keywords, with the let
keyword being used to define constant variables.
Example
var myInt = 42
var myString = "Hello, World"
Types
When declaring a variable, the compiler will automatically try to determine the type if a value is supplied. However, if a value is not supplied, or the programmer wishes to explicitly declare a type, this may be done using the as
keyword.
Example
var helpLabel as String
Functions are blocks of code that may take a number of arguments and be performed any number of times. Functions may be declared in the following way:
func functionName(argument as Type) -> returnType {
body...
}
Example
func add(x as Int, y as Int) -> Int {
return x + y
}
If a return type is not specified in the function definition, the fuction will return nothing.
To call a function, simply use the name of the function followed by parentheses containing any arguments that may be passed.
Example
print("Hello, World")
Arrays are collections of similarly typed elements declared inside square brackets. At this time, arrays are of a constant size.
Example
var myArray = [1, 2, 3, 4]
var names = ["Larry", "Curly", "Moe"]
print(myArray[0])