Jock Documentation
  • Introduction to Jock
  • Getting Started
  • Language Basics
  • Operators and Expressions
  • Functions
  • Control Flow
  • Data Structures
  • Classes and Objects
  • Compiler
  • Hoon Interface
  • Nock Interface
  • Language Reference
    • ASCII
  • Tutorial
Powered by GitBook
On this page
Export as PDF

Functions

A function defines a mapping from an input value to an output value.

// Increment a value using the built-in increment operator +.
func a(b:@) -> @ {
  +(b)
};

a(23)

Syntactically, a function requires the following elements:

  1. func keyword

  2. Function name (all lower case)

  3. In parentheses, one or more arguments

  4. -> mapping operator

  5. Output type

  6. In braces, code block of body

  7. Terminating ;

Methods in class definitions are similar to functions, but must occur inside a class code block and do not have a prefatory func keyword.

PreviousOperators and ExpressionsNextControl Flow

Last updated 28 days ago