Functions

User-defined functions

For performing repetitive calculations, functions can be defined. A function definition:

  • starts right at the beginning of the line,
  • its name can contain spaces,
  • followed by the parameters listed in parentheses, separated by commas,
  • then a closing parenthesis is followed by a :,
  • the body of the function starts with at least one space from the beginning of the line.

A function can be called by its name, followed by listing the parameters in parentheses, separated by commas.

The function name and its body appear with a gray background.

vacation cost(people count, accomodation per day):
	tax = if people count <= 3 then 0% else 10%
	(people count * accomodation per day) + tax

vacation cost(3, $30)
vacation cost(6, $25)
vacation cost(9, $20)

Builtin Functions

  • pi()
  • e()
  • abs(num)
  • ln(num)
  • lg(num)
  • log(num, num)
  • ceil(num)
  • floor(num)
  • round(num)
  • round_dp(num, decimal places)
  • sin(angle) -> num
  • cos(angle) -> num
  • tan(angle) -> num
  • asin(num) -> angle
  • acos(num) -> angle
  • atan(num) -> angle
  • nth(Matrix, index)
  • transpose(Matrix)
  • sum(Matrix)
sum([1, 2, 3])
transpose([1, 2, 3]) * [1, 2, 3]
pi()
e()
abs(-3)
ln(2)
lg(2)
log(2, 10)
ceil(12.3)
floor(12.3)
round(12.51)
round_dp(12.549, 2)
sin(90degree)
cos(90degree)
nth([1, 2, 3], 2)