[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Function Types

A function type characterizes the arguments and return value of a function. The syntax is:

function-type:
	fn function-arg-ret

function-arg-ret:
	(formal-arg-listopt)
	(formal-arg-listopt) : data-type

formal-arg-list:
	formal-arg
	formal-arg-list, formal-arg

formal-arg:
	nil-or-D-list : type
	nil-or-D-list : self refopt identifier
	*

nil-or-D-list:
	nil-or-D
	nil-or-D, nil-or-D

nil-or-D:
	identifier
	nil
The denotation of a function type has the keyword fn followed by a comma-separated list of its arguments enclosed in parentheses, and perhaps followed by the type the function returns. Absence of a return value means that the function returns no value; it is a procedure. The names and types of arguments are specified. However, the name of an argument can be replaced by nil, making it nameless. For example:

fn (nil : int, nil : int) : int
fn (radius : int, angle : int) : int
fn (radius, angle : int) : int

all denote exactly the same type, namely a function of two integers that returns an integer.

The following is an example of a function that takes a string argument and returns no value:

fn (nil : string)

The self keyword has a specialized use within adt declarations. It can be used only for the first argument of a function declared within an adt; its meaning is discussed in the ADT Declarations section.

The star character * can be given as the last argument in a function type. It declares that the function is variadic; during a call, actual arguments at its position and following are passed in a manner unspecified by the language. For example, the type of the print function of the Sys module is:

fn (s : string, *) : int

This means that the first argument of print is a string and that other arguments can be given when the function is called. The Limbo language itself has no way of accessing these arguments; the notation is an artifice for describing facilities built into the runtime system, such as the Sys module.



[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Copyright © 1998, Lucent Technologies, Inc. All rights reserved.