Next: Typing and Constants, Previous: Statement-lifting, Up: Principles of Compilation [Contents][Index]
All procedures taking a list argument are converted into ordinary non-list taking procedures and they are called with the list-making calls inserted. For example,
(define foo (lambda (x . y) (cons x (reverse y)) ))
is converted to
(define foo (lambda (x y) (cons x (reverse y)) ))
and any call to foo will make a list for a variable y. For example,
(foo 1 2 3)
is converted to
(foo 1 (cons 2 (cons 3 '()))).
All higher-order procedure calls where an argument-term contains unbound variables will generate a new instance (provided it has not been created already) of this higher-order procedure, carrying the right amount of free variables inside to right places.
For example, if there is a following definition:
(define (member-if fn lst) (if (fn (car lst)) lst (member-if fn (cdr lst)) ))
and a call
(member-if (lambda (x) (eq? x y)) lst),
a new instance of member-if is created (if an analogous one has not been created before):
(define (member-if_inst1 tmp fn lst) (if (fn tmp (car lst)) lst (member-if_inst1 tmp fn (cdr lst)) ))
and the call is converted to
(member-if_inst1 y foo lst)
and a top-level define
(define (foo y x) (eq? x y))
In addition, if the higher-order procedure is to be exported, an additional instance is created, which uses apply to call all argument-procedures, assuming they are defined via interpreter. The exportable higher-order procedure will have a name fun_exporthof, where fun is the name of the original procedure.
Next: Typing and Constants, Previous: Statement-lifting, Up: Principles of Compilation [Contents][Index]