[ << Scheme tutorial ] | [Top][Contents][Index] | [ Interfaces for programmers >> ] |
[ < Scheme procedures ] | [ Up : Scheme procedures ] | [ Predicates > ] |
Defining procedures
Procedures are defined in Scheme with define
(define (function-name arg1 arg2 … argn) scheme-expression-that-gives-a-return-value)
For example, we could define a procedure to calculate the average:
guile> (define (average x y) (/ (+ x y) 2)) guile> average #<procedure average (x y)>
Once a procedure is defined, it is called by putting the procedure name and the arguments in a list. For example, we can calculate the average of 3 and 12:
guile> (average 3 12) 15/2