From: ········@gmail.com
Subject: Access to optimization qualities
Date: 
Message-ID: <1132755971.302707.98150@z14g2000cwz.googlegroups.com>
Hello,

is it somehow possible to get at current settings of optimization
qualities, probably at macro-expansion time? The aim is to expand to
different code under different circumstances. Issue writeup
http://www.lisp.org/HyperSpec/Issues/iss101-writeup.html seems to
suggest that it could be *somehow* possible, but I do not see any
portable (or even non-portable, for clisp) way how to do it. I pondered
if it could be part of the environment, but that is implementation
dependent anyway.


Regards,

Tomas Zellerin
From: Pascal Costanza
Subject: Re: Access to optimization qualities
Date: 
Message-ID: <3uje95F10ma3bU1@individual.net>
········@gmail.com wrote:
> Hello,
> 
> is it somehow possible to get at current settings of optimization
> qualities, probably at macro-expansion time? The aim is to expand to
> different code under different circumstances. Issue writeup
> http://www.lisp.org/HyperSpec/Issues/iss101-writeup.html seems to
> suggest that it could be *somehow* possible, but I do not see any
> portable (or even non-portable, for clisp) way how to do it. I pondered
> if it could be part of the environment, but that is implementation
> dependent anyway.

It is implementation dependent. There was an attempt in CLtL2 to define 
access operations for environment objects, but that didn't make it into 
the ANSI Common Lisp standard. It was only recently that Allegro Common 
Lisp has provided a (seemingly) complete solution for doing this.

Either your implementation supports some elements of the CLtL2 approach, 
or you should find ways to implement Allegro's approach.

I have implemented a workaround for ContextL in which I also wanted a 
macro to expand differently according to optimization settings. The 
basic idea is to introduce a symbol macro that describes your own 
optimization setting, for example like this:

(define-symbol-macro optimize-xyz nil)

This allows a user to specify that he/she wants a different setting for 
a particular region of code:

(symbol-macrolet ((optimize-xyz t))
   ...)

Inside a macro you can access that information as follows:

(defmacro bla (... &environment env)
   (let ((optimize-xyz (macroexpand 'optimize-xyz env)))
     (if optimize-xyz
        (do-this ...)
        (do-that ...))))

You can make this look nicer by providing your own macro for the user 
that expands into symbol-macrolet.


Pascal

-- 
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/