Copper in 5 minutes


# Comments are between \#'s and multiline but a slash escapes characters. #

# Variables have stack-based lifetimes and only one type: function.
Declaring a name makes a variable. #
a

# Assignment (copies data and members) #
a = 5

# Getting what's stored is done by calling the function in the variable. #
a()

# Pointers (left hand side becomes pointer to right hand side) #
b ~ a

# The included standard library has a print() function. Sorry, no built-in. #
print( b() ) # Prints 5 #

# Lost pointers cause no memory errors or leaks. #
a = 1
print( b() ) # Prints "{fn}". #

# Strings are between double-quotes only. #
c = "hello world"

# Members are auto-created #
a.child = "woot"

# Shortcut parameterless function calls using ":" #
print( a.child: )

# Getting and setting members can be done using their names. #
name = "five" set_member(d name: 5)
print( type_of( member(d name:) ) ) # Prints "number" #

# Creating objects with members... #
e = [ my_member = 0 other_member = 1 ]

# Create functions using {} #
f = {
	x = false
	# if's and loop's require brackets #
	loop {
		# not() takes only 1 parameter,
		but all(), any(), nall(), and none() can take any number of parameters. #
		if ( not(x:) ) {
			x = true
			skip	# Restart the loop #

		# An elif could go here too #
		} else {
			stop	# Escape the loop #
		}
	}
}

# Object-funtions, having members and a body/block of executable code... #
g = [ a b=2 ] {
	# Access members inside a function via "this" pointer #
	ret( [a=a, b=this.b] )
}

# Commas are optional for separating expressions, parameters, or arguments. #
h = g(3), print( h.a:, " ", h.b: ) # Prints "3 2" #

# Parent of the variable whose function is being called can be accessed with "super" #
i = {
	super.kid = 2
}
# ... and it doesn't matter who that parent is... #
j.a = i
j.a:
print(j.kid:) # Prints 2 #

# Combine object member sets with union #
k = union(h j [b=1])
print( k.a:, " ", k.kid:, " ", k.b:) # Prints "3 2 1" #

# Creating and accessing lists... #
l = list(1 2 [p]{ print("p == " p:) })
append(l: 4)
prepend(l: 0)
insert(l: 2 "arf")
m ~ item_at(l: 4)
m("hi")
erase(l: 0)
swap(l: 1 2)
replace(l: 0 "front")

# Function pointers are saved in lists... #
n = { print("hey") }
o = list(n)
p ~ item_at(o: 0)
p: # Prints "hey" #
n = {}
p: # Prints warning of empty function container #

# ... unless copied #
n = { print("hey") }
o = list( copy_of(n) )
p ~ item_at(o: 0)
n = {}
p: # Prints "hey" #

# Sub-lists have to be made from valid indexes that map to the range 0 to list size. #
q = sublist(o: 0 length(o:))

# Sub-lists are linked to the items in the original object. #
r ~ item_at(q: 0)
r: # Prints "hey" #
o = {}
r: # Prints warning of empty function container #

# Strings can be checked for matching value and concatenated #
if ( matches("fn" typename_of(s:)) ) {
	print( concat( "some " "string " ) )
}