What are first class procedures?

In Scheme, procedures are regular first-class values, just like any other values such as strings or integers.

In a language like PHP, you define a procedure as

function foo ($bar)
    $baz = do_something($bar);

However, PHP does not permit using procedures as ordinary values.

$foo = function ($bar) // This is invalid!
    $baz = do_something_else($bar);

foo and do_something are defined quite different from $bar and $baz. We cannot manipulate the procedure foo like a regular value. We cannot pass foo around in our procedures; nor can we re-define it.

In Scheme, however, procedures are just regular values. Scheme's syntax (define (name . arguments) body) is simply syntactic sugar for (define name (lambda arguments body)). This means that the following code is valid:

 (define (foo bar baz) 
   (+ bar baz)) 
 (foo 2 8) => 10 
 (set! foo (lambda (x y) (* x y))) 
 (foo 2 8) => 16 

Passing procedures as arguments

Since procedures are regular values just like anything else, such as lists, they may be passed as arguments to other procedures. For example, the standard (map procedure list) procedure applies procedure to every element of list and collects a list of its respective results. E.g., the following double-list procedure doubles every element of its input list:

 (define (double-list list) 
   (map (lambda (x) (* x 2)) list)) 
 (double-list '(0 1 2 3)) 
   ; => (0 2 4 6)