Copyright © 1996, 1997 Lucent Technologies Inc. All rights reserved.

4.3 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 : self refopt identifier nil-or-D : self identifier * nil-or-D-list: nil-or-D nil-or-D-list , nil-or-D nil-or-D: identifier nil
That is, 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 may be replaced by nil; in this case it is 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. As another example,
	fn (nil: string)
is the type of a function that takes a string argument and returns no value.

The self keyword has a specialized use within adt declarations. It may be used only for the first argument of a function declared within an adt; its meaning is discussed in §6.3 below.

The star character * may 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 may 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.

05/Jun/97