23.11.2014 Views

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Another approach is to restrict the compiler to unsafe primitives.<br />

Calls to safe primitives are not open-coded by the compiler, instead,<br />

a procedure call to the safe primitive is issued. The safe primitives<br />

are defined to perform the error checks themselves. Although this<br />

strategy is less efficient than open-coding the safe primitives, the<br />

implementation is much simpler <strong>and</strong> less error-prone.<br />

3.17 Variable-arity Procedures<br />

<strong>Scheme</strong> procedures that accept a variable number <strong>of</strong> arguments are<br />

easy to implement in the architecture we defined so far. Suppose<br />

a procedure is defined to accept two or more arguments as in the<br />

following example:<br />

(let ((f (lambda (a b . c) (vector a b c))))<br />

(f 1 2 3 4))<br />

The call to f passes four arguments in the stack locations<br />

%esp-4, %esp-8, %esp-12, <strong>and</strong> %esp-16 in addition to the number<br />

<strong>of</strong> arguments in %eax. Upon entry <strong>of</strong> f, <strong>and</strong> after performing<br />

the argument check, f enters a loop that constructs a list <strong>of</strong> the<br />

arguments last to front.<br />

Implementing variable-arity procedures allows us to define<br />

many library procedures that accept any number <strong>of</strong> arguments<br />

including +, -, *, =,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!