Bare Methods

Nameless methods may be declared inline. Such bare methods are typically used as parameters to other methods. For example, the following code fragment squares each element of a list using the built in map function and a bare method:

define method square-list(in :: <list>)
	=> out :: <list>
	map(method(x) x * x end, in);
end;
      

The map function takes each element of the list in and applies the anonymous method. It then builds a new list using the resulting values and returns it. The method square-list might be invoked as follows:Must distinguish return values from code.

square-list( #(1,2,3,4) );
=> #(1,4,9,16)