[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

operation->procedure



Problem:  I have an  OBJECT-expression  with  38  method-clauses.   Most
of the  38  operations  are  not  defined  for any other type of object.
In order to reduce the  dispatch-time,  I'd  like  to  turn  these  into
procedures, but  they  all  use  variables local to the contour in which
the OBJECT-expression is defined.  Example:

    (DEFINE (MAKE-THING X Y Z)
      (LET ((A ...) (B ...) (C ...))
        ...
        (OBJECT NIL
          ((OP-1 SELF ...) ... A ... B ... C ...)
          ((OP-2 SELF ...) ... A ... B ... C ...)
          ...)))

Hack solution #1: create a locale and "export" it for later use by EVAL:

    (DEFINE (MAKE-THING X Y Z)
      (LOCALE FOO
        (LET ((A ...) (B ...) (C ...))
          ...
          (OBJECT NIL
            ((MY-ENV SELF) FOO)))))

    (DEFINE (OP-1 THING ...)
      (EVAL '(... A ... B ... C ...) (MY-ENV THING)))
    (DEFINE (OP-2 THING ...)
      (EVAL '(... A ... B ... C ...) (MY-ENV THING)))
    ...

Hack solution  #2:   Assuming  normal  syntax for "body," run it through
STANDARD-COMPILER once and call it later.

    (LET ((BODY-1 (STANDARD-COMPILER '(... A ... B ... C ...)
                                     *THE-USER-ENV*))
         ((BODY-2 (STANDARD-COMPILER '(... A ... B ... C ...)
                                     *THE-USER-ENV*))
          ...)
     (DEFINE (OP-1 THING ...)
       (RUN-COMPILED-CODE BODY-1 (MY-ENV THING)))
     (DEFINE (OP-2 THING ...)
       (RUN-COMPILED-CODE BODY-2 (MY-ENV THING)))
     ...)

I don't  like  either of these solutions.  Do you have any better ideas?
[There's also a bug in solution #2:  arguments to OP-1,  besides  THING,
can't be accessed.]
-------