Cheddar Documentation
  • Introduction
  • Syntax
  • Literals
    • Comment
    • String
    • Number
    • Array
    • Boolean
  • Mathematics
    • Addition
    • Subtraction
    • Multiplication
    • Division
    • Exponentiation
    • Remainder
    • Negation
    • Sign
    • Root
    • Bitwise AND
    • Bitwise OR
    • Bitwise XOR
    • Bitwise NOT
    • Bitwise Left Shift
    • Bitwise Right Shift
  • Variables
  • Functions
    • Defining
      • Lambda
      • Functionized Operators
      • Functionized Properties
    • Operations
      • Functional Bonding
      • Functional Composition
  • Default Operators
    • What Is
    • Instance-of
    • Actually Is
  • Control Flow
    • Conditional
    • Loops
      • For Loops
      • While Loops
  • Standard Library
    • String
      • Bytes
      • Count
      • Length
      • Match
      • Slice
      • Tail
      • Chars
      • Head
      • Lines
      • Ord
      • Split
      • Test
      • Chunk
      • Index
      • Lower
      • Reverse
      • Substitute
      • Upper
  • Developing
    • Structure
    • Primitive Objects
      • Scope
      • Class
      • Variable
      • Namespace
    • Getting Started
    • API
      • Primitives
        • string
        • number
        • array
        • bool
        • func
        • nil
Powered by GitBook
On this page
  • Arguments:
  • Usage:
  • Internal Usage
  • Execution:
  • Arguments:

Was this helpful?

  1. Developing
  2. API
  3. Primitives

func

The function class for Cheddar

Arguments:

name

type

description

arguments

2D array

(described below) this matrix described the arguments for the function. In the form of [ ["arg_name", { <options> }] ]

body

function

(described below) the function body

arguments matrix:

name

type

default

description

Type

cheddar.class

n/a

If provided, the argument is required to be of the given type

Default

cheddar.class{}

n/a

If provided and the argument is not provided, it will be set to this rather than throwing an error.

Splat

bool

false

If provided, this and the following arguments will be combined into a cheddar.array object.

Optional

bool

false

If true, the argument will be nil if not provided

function body:

argument

description

first

This is the function's scope as a cheddar.scope.

second

This is a function which returns a variable's value, given a variable name.

Usage:

-> (a, b = 0) a + b, with api:

new cheddar.func(
  [
    ["a", {}],
    ["b", {
        Default: cheddar.init(
          cheddar.number,
          10, 0, 0
        )
    }]
  ],
  function(scope, input) {
    return cheddar.init(
      cheddar.number,
      10, 0,
      input("a").value + input("b").value
    );
  }
)

Internal Usage

Execution:

func.exec([
    arg1, arg2, ...
], scope)

scope will be set to self variable, if none, set to null.

Arguments:

func.args

the 2D matrix representing the arguments the function is requesting.

PreviousboolNextnil

Last updated 4 years ago

Was this helpful?