What's new? | Help | Directory | Sign in
Google
cat-language
The Cat Programming Language Project
  
  
  
  
    
Search
for
Updated May 18, 2007 by cdiggins
Labels: Glossary
Function  
Definition of a function.

Function

A function is a named expression that consumes zero or more values from the stack, and produces zero or more values on to the stack. A function may also have side-effects.

A function can be pushed on to a stack by quoting it.

Some example of function definitions are:

>> define f { 40 2 + }
stack: _empty_
>> define g { 42 eq ["correct answer"] ["wrong answer"] if writeln }
stack: _empty_
>> 12 g
wrong answer
stack: _empty_
>> f g
that is the answer
stack: _empty_
>> [f]
stack: [f]

Sign in to add a comment