[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: functional languages



Robert.Land@t-online.de (Robert Land) writes:
> On Fri, Dec 13, 2002 at 11:23:43AM -0500, Derrick 'dman' Hudson wrote:
>> "imperative" and "procedural" are the same thing, and C is a prime
>> example.  It is such because the structure of a C program is a
>> collection of procedures which start with "main".  Each procedure is a
>> linear list of statements to be executed in order.
>
> Could you specify a "linear list" more clearly? - the 
> contrary would be a "nonlinear list" which on the first
> view seems to be self-contradictory.

For example, in C:

int fib(int n)
{
  if (n < 2)
    return n;
  return fib(n-2) + fib(n-1);
}

the rules require that fib(n-2) is called before fib(n-1).  In Scheme:

(define (fib n)
  (if (< n 2)
    n
    (+ (fib (- n 2)) (fib (- n 1)))))

the recursive function calls can happen in either order, and I believe
it's even semantically correct for e.g. both function call parameters
to be evaluated before either function is called (again, C and ilk
strictly specify this order).

-- 
David Maze         dmaze@debian.org      http://people.debian.org/~dmaze/
"Theoretical politics is interesting.  Politicking should be illegal."
	-- Abra Mitchell



Reply to: