import { Decimal } from 'decimal.js'; import { Type } from '../types/datatype'; import { Environment } from './environment'; interface ICallable { call(environment: Environment, argument: Type[]): Type | number | Decimal; } declare type FcalFunctionFmt = (environment: Environment, argument: Type[]) => Type | number | Decimal; /** * IUseFunction * Interface for UseFunction */ interface IUseFunction { name: string; arity: number; func: FcalFunctionFmt; } /** * FcalFunction represents function in fcal */ declare class FcalFunction implements ICallable { readonly arity: number; readonly name: string; readonly function: FcalFunctionFmt; /** * Create new Fcal function * @param name name of the function * @param arity number of arguments function can expect, -1 for any number of functions * @param func function implementation */ constructor(name: string, arity: number, func: FcalFunctionFmt); /** * call the function * @param {Environment} environment state of fcal * @param {Array} argument arguments of the function * @returns {Type} function result * @throws {FcalError} Error if function return invalid return type */ call(environment: Environment, argument: Type[]): Type; } /** * List of fcal functions */ declare namespace FcalFunction { class List { readonly functions: Map; constructor(); /** * Add new fcal function * @param {FcalFunction} fcalFunction * @throws {FcalError} Error if function name is already exists */ push(ff: FcalFunction): void; /** * Call a function by its name * @param {string} name name of the function * @param {Environment} environment state of fcal * @param {Array} argument arguments for the function * @param {Type} Type result of the function * @throws {FcalError} Error if function is not found */ call(name: string, environment: Environment, argument: Type[]): Type | number | Decimal; /** * Get function implementation by its function name * @param {string} name function name * @returns {FcalFunction | undefined} function */ get(name: string): FcalFunction | undefined; } } export { FcalFunction, IUseFunction, FcalFunctionFmt };