From: Ethan Benatan
Subject: How to ensure that a method is compiled?
Date: 
Message-ID: <ethan+-2305951205500001@peaceful.cs.pitt.edu>
I am trying to ensure that a method is compiled.  With a function it 
would be fairly straightforward, but I am having difficulty applying 
#'compile to a method.  That is, I have worked out a way to do it but
it seems terribly inelegant at best, dangerous a worst. (This is a patch
to a large system, and making sure that the compilation happens
at definition time is not an easy option).

Here's an example.  I have defined a method and now I want to compile it.
(I'm working in Allegro v4.1 and MCL. The example is from Allegro.)

    Allegro CL 4.1 [DEC MIPS; R1] (12/15/92 21:09)
    Copyright (C) 1985-1992, Franz Inc., Berkeley, CA, USA.  All Rights
    Reserved.
    ;; Optimization settings: safety 1, space 1, speed 1, debug 2
    ;; For a complete description of all compiler switches given the
    current
    ;; optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS).
    USER(1): (defclass foo () ((a)))
    #<STANDARD-CLASS FOO @ #x10440dc2>
    USER(2): (defmethod grok ((foo foo))
    (setf (slot-value foo 'a) 'grokked))
    #<STANDARD-METHOD GROK (FOO) @ #x1044294a>
    USER(3): (setf grok-method 
                  (find-method #'grok '() (list (find-class 'foo))))
    #<STANDARD-METHOD GROK (FOO) @ #x1044294a>
    USER(4): (compiled-function-p (clos:method-function grok-method))
    NIL

Okay, now I want to compile the method.  Compile wants a name, and
appears to want to compile (symbol-function name).  But the name
(symbol) that I have is that which has the generic function bound to
it, not the method...

    [1i] USER(14): (symbol-function 'grok)
    #<STANDARD-GENERIC-FUNCTION GROK @ #x10442652>
    [1i] USER(15): (compiled-function-p (symbol-function 'grok))
    T
    [2] USER(17): (compile 'grok)
    ; While compiling GROK:
    Error: Function GROK is already compiled
    [3] USER(18): (compiled-function-p (clos:method-function grok-method))
    NIL

So we have to have a symbol to work with.  A little experimentation
yields:

    USER(64): (setf temp (gensym))
    #:G79
    USER(65): (setf (symbol-function temp) (clos:method-function grok-method))
    #<Interpreted Function (METHOD GROK (FOO)) @ #x1051836a>
    USER(68): (compile temp)
    #:G79
    NIL
    NIL
    USER(79): (setf (slot-value grok-method 'function) (symbol-function temp))
    #<Function G79 @ #x10577202>
    USER(81): (compiled-function-p (clos:method-function grok-method))
    T

And all seems to work, but my goodness it is ugly.  And I don't like
messing directly with the internal structure of the method which I 
don't understand...

All suggestions gratefully accepted! Thanks,

Ethan

Ethan Benatan
······@pitt.edu
http://www.pitt.edu/~ethan

From: Ken Anderson
Subject: Re: How to ensure that a method is compiled?
Date: 
Message-ID: <KANDERSO.95May24085301@bitburg.bbn.com>
In article <·······················@peaceful.cs.pitt.edu> ······@pitt.edu (Ethan Benatan) writes:

   I am trying to ensure that a method is compiled.  With a function it 
   would be fairly straightforward, but I am having difficulty applying 
   #'compile to a method.  That is, I have worked out a way to do it but
   it seems terribly inelegant at best, dangerous a worst. (This is a patch
   to a large system, and making sure that the compilation happens
   at definition time is not an easy option).

   Here's an example.  I have defined a method and now I want to compile it.
   (I'm working in Allegro v4.1 and MCL. The example is from Allegro.)

Write your patch into a file, compile the file and load the file into the
world you are trying to patch.
--
Ken Anderson 
Internet: ·········@bbn.com
BBN ST               Work Phone: 617-873-3160
10 Moulton St.       Home Phone: 617-643-0157
Mail Stop 6/4a              FAX: 617-873-2794
Cambridge MA 02138
USA
From: William J. (Bud) Frawley
Subject: Re: How to ensure that a method is compiled?
Date: 
Message-ID: <3pvksl$2rd@ceylon.gte.com>
Ethan,

I'm using Allegro Common Lisp For Windows, v. 2.0.

First, ACL-Win has no CLOS package; Method-Function is
in the Common-Lisp package.

Secondly, discovered by testing your example and
verified by reading the on-line documentation, ACL
"compiles everything on definition".

Nevertheless, your approach works, and doesn't seem
"dangerous". What is questionable is its portability.
What I do when I define unusual constructs is put
copious notes with documented test cases in the
installation file, telling just what to do to insure
that each construct meets its purpose in any given
environment. These tests are conducted as part of the
installation; if any fail, we stop right there. (This
can be embarrassing in the short term, but patching
bizarre hacks on the fly is even worse.)

Bud Frawley
From: 55437-olivier clarisse(haim)463
Subject: Re: How to ensure that a method is compiled?
Date: 
Message-ID: <D954J4.71r@ssbunews.ih.att.com>
Using your example, the following is a bit cleaner as it does
not require you to bind the method to a generated symbol. Also
the method is compiled upon definition, not artificially after
an interpreted definition was first created:

1> (funcall (compile nil `(lambda () (defmethod grok ((foo foo))
					(setf (slot-value foo 'a) 'grokked)))))
#<STANDARD-METHOD GROK (FOO)>

2> (setf grok-method 
         (find-method #'grok '() (list (find-class 'foo))))
#<STANDARD-METHOD GROK (FOO)>

3> (clos:method-function grok-method)
#<Function (METHOD GROK (FOO)) @ #x2684db2>  ;Compiled definition

Note that both ACLPC and MCL have replaced the interpreter
by a compiler so this is done by default on PC and MAC platforms:
any method your code dynamically generates (i.e. to patch itself)
is always compiled by default.

Can you list several advantages of having methods generated by some code
compiled within the application itself (as above) and not after you
first save the generated code to file, compile the file and
then load it (the traditional way it seems)?

Could it be that (CLOS) methods are first class entities
and can therefore not only describe themselves but also compile
themselves without requiring external tools to butcher them?

Might it be possible to cleanly build self improving and adaptive
autonomous software machines based on this property? Could this
be a good ground for research on computational reflection?
-- 
----------------
Olivier Clarisse
Member of Technicall Staff
AT&T Bell Laboratories