Functional Languages

Functional languages, such as LISP, Scheme and to a large extent TCL, view an entire program as one large function to be evaluated. Expressions, statements and even control structures all return values, which may in turn be used as arguments elsewhere.

Dylan ™ is a functional language, permitting programmers to write functions like the following:

define method shoe-size(person :: <string>)
  if (person = "Larry")
    14;
  else
    11;
  end if;
end method;
      

The function shoe-size has one argument, a string, and an untyped return value. (If this function didn't link against external code, the compiler could easily infer the return type.) If person equals "Larry", then the if statement evaluates to 14, otherwise it returns 11. Since no other statements follow the if , its return value is used as the return value of the entire function.

The same function could also have been written as follows, in a more imperative idiom:

define method shoe-size(person :: <string>)
  let the-size = 11;
  if (person = "Joe")
    the-size := 14;
  end if;
  the-size;
end method;