//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2010, 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available
// under the terms of the MIT License which is available at
// https://opensource.org/licenses/MIT
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////

include::../_part_attributes.asciidoc[]

:leveloffset: -2

[[lang-tut-functions-chapter-intro]]
== Functions

indexterm:[function]
indexterm:[function,standard library]
Functions can be used to compute values from other values.
CIF has many built-in functions, called _standard library functions_.
An example is the `size` function, which takes a <<lang-tut-values-chapter-lists,list>> and returns the number of elements of the list.
Another example is the `abs` function, which takes an <<lang-tut-values-chapter-integers,integer>> or <<lang-tut-values-chapter-reals,real>> number and computes the absolute value of that number.

indexterm:[function,user-defined]
While many built-in functions are available, they may not always suffice.
User-defined functions can be added to CIF models, to allow custom computations needed by the model.
By putting the calculation in a user-defined function, the calculation can be used in several places, allowing for reuse.
Furthermore, functions allow for more complex computations than would otherwise be possible.

indexterm:[function,internal vs external]
CIF features two kinds of user-defined functions: internal ones and external ones.
Internal user-defined functions are fully defined within the CIF model.
External user-defined functions declare only a header which indicates the existence of the function, while the actual implementation is obtained from an external source.
The lessons of this category only explain internal user-defined functions.
The language reference documentation gives more information on external user-defined functions.
