ChaiScript
Public Member Functions | List of all members
ChaiScript_Language::Function Class Reference

Represents a function object in ChaiScript. More...

#include <chaiscript_prelude_docs.hpp>

Public Member Functions

string get_annotation () const
 Returns the annotation description of the function.
 
int get_arity () const
 Returns the arity of the function, -1 if the function takes a variable number of parameters. More...
 
Vector get_contained_functions () const
 Returns a vector of the contained functions. More...
 
Function get_guard () const
 Returns a function guard as function. More...
 
Vector get_param_types () const
 Returns a vector of Type_Info objects that represent the param types for this function. More...
 
bool has_guard () const
 Returns true if the function has a guard to it. Always returns false for a conglomerate function.
 
Object call (Vector t_params) const
 Calls the function with the given set of parameters and returns the value;. More...
 

Detailed Description

Represents a function object in ChaiScript.

A function object may be one function, such as:

var f = fun(x) { return x; }

Or it may represent multiple functions

var f2 = `-`; // represents the unary - as well as the set of binary - operators

Guarded function example

def f3(x) : x > 2 {
return x;
}

Examples in the function definitions below will reference these examples

Member Function Documentation

◆ call()

Object ChaiScript_Language::Function::call ( Vector  t_params) const

Calls the function with the given set of parameters and returns the value;.

Example:

eval> `-`.call([2,1]);
1

◆ get_arity()

int ChaiScript_Language::Function::get_arity ( ) const

Returns the arity of the function, -1 if the function takes a variable number of parameters.

Example:

eval> f.get_arity()
1
eval> f2.get_arity()
-1

◆ get_contained_functions()

Vector ChaiScript_Language::Function::get_contained_functions ( ) const

Returns a vector of the contained functions.

Example:

eval> f.get_contained_functions().size()
0
eval> f2.get_contained_functions().size()
11
eval> var v = f2.get_contained_functions();
v[0].get_arity()
2

◆ get_guard()

Function ChaiScript_Language::Function::get_guard ( ) const

Returns a function guard as function.

Example:

eval> f.get_guard() // Throws exception
Function does not have a guard
eval> f3.get_guard().get_arity()
1

◆ get_param_types()

Vector ChaiScript_Language::Function::get_param_types ( ) const

Returns a vector of Type_Info objects that represent the param types for this function.

The first value in the list is the return type.

If this function is a conglomerate of several functions (get_contained_values().size() > 0) then the function returns as many Type_Info objects as it can. If the functions contained all have the same arity, then it represents the arity. If they have different arities, it returns only one value - the return type.

For each parameter that is the same type, the type is returned. If the types are different then a Type_Info for Object is returned.

Example:

eval> f2.get_param_types().size(); // Returns a Type_Info for Object for the return type
1

The documentation for this class was generated from the following file: