[Openmcl-devel] Quick HW question...

Ron Garret ron at flownet.com
Wed Nov 17 10:35:45 PST 2010


On Nov 17, 2010, at 10:14 AM, Spires, Shannon V wrote:

> 
> On Nov 17, 2010, at 10:47 AM, Gary Byers <gb at clozure.com> wrote:
> 
>> Suppose that there were semi-magic macros (I -think- that they could be macros)
>> called something like EXPECTED-TRUE and EXPECTED-FALSE that each took a single
>> form and just caused that form to return whatever it returned, but the contract
>> was that the compiler could treat them as advice about whether the primary
>> return value was likely to be NIL or not.  So you could say:
>> 
>> (if (expected-false (some-test))
>>  (exceptional-case)
>>  (common-case))
> 
> How about 
> (if (some-test)
> 	(exceptional-case)
> 	(locally (declare expected-branch)
> 		(common case)))
> 
> or, more portably but less semantically meaningful:
> 
> (if (some-test)
> 	(exceptional-case)
> 	(locally (declare (optimize (speed 3)))
> 		(common case)))
> 
> or -- easiest of all -- when speed=3, the compiler automatically codes the first clause in an if or a cond or a case to be the expected one.

The second case should be the expected one because of the overwhelmingly common idiom:

(cond ((null l) nil)
           (t ...))

And there's no reason not to apply this optimization all the time, not just when speed=3.

rg




More information about the Openmcl-devel mailing list