Procedure Operations - MIT/GNU Scheme 7.7.91
Description: MIT/GNU Scheme 7.7.91

Next: Primitive Procedures, Previous: Procedures, Up: Procedures

### 12.1 Procedure Operations

— procedure: apply procedure object object ...

> Calls procedure with the elements of the following list as arguments:

>               (cons* object object ...)

> The initial objects may be any objects, but the last object (there must be at least one object) must be a list.

>               (apply + (list 3 4 5 6))                =>  18
>               (apply + 3 4 '(5 6))                    =>  18

>               (define compose
>                 (lambda (f g)
>                   (lambda args
>                     (f (apply g args)))))
>               ((compose sqrt *) 12 75)                =>  30

— procedure: procedure? object

> Returns `#t` if object is a procedure; otherwise returns `#f`. If `#t` is returned, exactly one of the following predicates is satisfied by object: `compiled-procedure?`, `compound-procedure?`, or `primitive-procedure?`.

— procedure: compiled-procedure? object

> Returns `#t` if object is a compiled procedure; otherwise returns `#f`.

— procedure: compound-procedure? object

> Returns `#t` if object is a compound (i.e. interpreted) procedure; otherwise returns `#f`.

— procedure: primitive-procedure? object

> Returns `#t` if object is a primitive procedure; otherwise returns `#f`.

The following two procedures test the arity of a procedure, that is, the number of arguments that the procedure accepts. The results of the test may be less restrictive than the effect of calling the procedure. In other words, these procedures may indicate that the procedure will accept a given number of arguments, but if you call the procedure it may signal a `condition-type:wrong-number-of-arguments` error. This is because these procedures examine the apparent arity of a procedure. For example, here is a procedure that appears to accept any number of arguments, but when called will signal an error if the number of arguments is not one:

         (lambda arguments (apply car arguments))

— procedure: procedure-arity-valid? procedure k

> Returns `#t` if procedure accepts k arguments; otherwise returns `#f`.

— procedure: procedure-arity procedure

> Returns a description of the number of arguments that procedure accepts. The result is a newly allocated pair whose car field is the minimum number of arguments, and whose cdr field is the maximum number of arguments. The minimum is an exact non-negative integer. The maximum is either an exact non-negative integer, or `#f` meaning that the procedure has no maximum number of arguments.

>               (procedure-arity (lambda () 3))         =>  (0 . 0)
>               (procedure-arity (lambda (x) x))        =>  (1 . 1)
>               (procedure-arity car)                   =>  (1 . 1)
>               (procedure-arity (lambda x x))          =>  (0 . #f)
>               (procedure-arity (lambda (x . y) x))    =>  (1 . #f)
>               (procedure-arity (lambda (x #!optional y) x))
>                                                       =>  (1 . 2)

— procedure: procedure-environment procedure

> Returns the closing environment of procedure. Signals an error if procedure is a primitive procedure, or if procedure is a compiled procedure for which the debugging information is unavailable.