ToC | DocOverview | CGDoc | RelNotes | Index | PermutedIndex
| Allegro CL

| 2 Syntax 2.4 Standard Macro Characters 2.4.4 Semicolon 2.4.4.2 Notes about Style for Semicolon ### 2.4.4.2.5 Examples of Style for Semicolon
    ;;;; Math Utilities

    ;;; FIB computes the the Fibonacci function in the traditional
    ;;; recursive way.

    (defun fib (n)
      (check-type n integer)
      ;; At this point we're sure we have an integer argument.
      ;; Now we can get down to some serious computation.
      (cond ((< n 0)
             ;; Hey, this is just supposed to be a simple example.
             ;; Did you really expect me to handle the general case?
             (error "FIB got ~D as an argument." n))
            ((< n 2) n)             ;fib[0]=0 and fib[1]=1
            ;; The cheap cases didn't work.
            ;; Nothing more to do but recurse.
            (t (+ (fib (- n 1))     ;The traditional formula
                  (fib (- n 2)))))) ; is fib[n-1]+fib[n-2].

© Franz Inc. All Rights Reserved - File last updated 2022-07-25