This chapter showcases Cone's features using code examples and hyperlinks to the appropriate detailed documentation.

Comments

// Line comments start with a '//' and continue to end of line

/*
Block comments start with '/*' and end with '*/'.
They can /* nest */ and span multiple lines.
*/

Literal values: Each comment specifies the type of the values.

null          // Null
true, false   // Bool
123, -3i8     // i32, i8
3.4d, 0.3E-2  // f64. f32
'\n'          // u32 character
"Χαίρετε"     // String

// Text literals enclosed within '"""' may span multiple lines
// Leading indentation is stripped.
    """A line.\n\tIndented line\n
    \t\"Another line\u00BF\""""

Names

# Variables start with letter, _ or $
balance, π, temp2, toReturn
_temp_      // Leading underscore designates 'private'
$, $window  // global environment values

Point       // types are capitalized, by convention

Assignment:

a = 3.4         // a now holds the Integer 3.4
a = b = c       // a and b now have the value found in c
a = (b = c) + 1 // assignments may be embedded in expressions
a,b = b,a       // parallel assignment (this swaps their values)
a += 1          // operator assignment, incrementing value of a

Property or Method Use

child.lastname = parent.lastname    // properties may be retrieved or assigned
# Methods
list.find("banana")
list.sort             // parameters may be omitted
number.`+`(1)         // backticks when method name is not like a variable
frosty.jump(10).yell("Ow!").grow(0.9)  // Method chaining

# Syntactic shortcuts:
a+b*c                 // equivalent to a.`+`(b.`*`(c))
letters[5]            // Index. Equivalent to letters.`[]`(5)
glyphs[4] = "π"       // Uses the setter method for '[]': glyphs.`[]`("π", 4)
+List('a','b')        // Creates a new list. Equivalent to: List.New('a', 'b')
+Regex"abc"           // Equivalent to Regex.New("abc")
1 .. 4                // equivalent to: +Range(1,4)
methodx(a)            // Equivalent to self.methodx(a)

Functions: Blocks can be inferred by indentation or explicitly marked using {}

fn newfunc(a i32, b=2)      // b is 1 if not specified on caller
	imm c = 4               // type inference. 
	a,c = summul(a,b)       // functions may return multiple values
	a*b, c                  // implicitly return two values
	
newfunc(3)                  // returns 10, 6

Conditions and if:

# if block
x = if needs_more     // fails when false or null, succeeds otherwise
	fill_it_up()
elif shape===square   // exact equivalence: same object
	shape = "rectangle"
elif height<5.4       // Uses `<=>` method: -1/less, 0/equal, 1/more
	grow()
elif 5 ~~ 1 .. 7      // match operator. Equivalent to +Range(1,7).'~~'(5)
	"I knew that"
elif a or b and not c // boolean operators ( or use || && ! )
	"Illogical!"
else
	default_action()
	
x = 5 if x<2          // if clause
m = x==4? a : b       // ternary operator

match block:

# match applies '~~' method to each 'with' value
match ship.speed
with 0.0 .. 1.5
	ship.state = 'landing'
with 1.5 .. 4.0
	ship.state = 'crashing'
else
	ship.state = 'flattened'

while:

mut x = 0
while x<=10
	x += 1
	continue if x===3     // 'continue' goes back to start of loop
	Vm.Log("DANGER, DANGER! Will Robinson")
	break if x===5        // 'break' halts loop
	
// while clause
item = get_next() while item!=45

'this' blocks:

npcs[i]                   // establishes value of 'this' for following block
	scene.register(this)
	.jump(10.)            // equivalent to: this.Jump(10.)
	shape = .shape        // equivalent to: shape = this.shape
	.grow(1.1)

// Use 'this' blocks to build multi-layered, typed content
smaug = +Dragon
	name: "Smaug"         // equivalent to: this::name="Smaug"
	color: 'green'
	loot: +List           // 'this' = the new List for following block
		<< 'gem'              // appends 'gem' to the smaug.loot list
		<< 'ring'             // equivalent to: this.'<<'('ring')

Iteration and 'each':

// Calculate 30 using 'each' block
mut sum = 0
each n in 1 .. 10
	if n.isEven
		sum += n

sum += n if n.isEven? each n in 1 .. 10  // equivalent, using 'each' clause

// 'each' iterates over collections
yield item each item in list           // uses list.each to create closure iterator for list
yield key,value each key:value in index

// Use 'each' with 'this' blocks to build procedural content
// This creates a list of fibonacci integers from 1 to 89 (<100)
fiblist = +List
	each n in fibo()      // 'each' works with yielders/closures
		break if n>100
		<< n

_