In general, lisp, how can I override / change the evaluation behavior for a particular type of object?

In common-lisp, I want to implement a reference system like this:

Suppose I have:

(defclass reference () ((host) (port) (file)))

as well as me:

(defun fetch-remote-value (reference) ...)which retrieves and deserializes the lisp object.

How can I intervene in the evaluation process, since whenever a reference object is evaluated, the remote value is received and re-evaluated to obtain the final result?

EDIT:

A more detailed description of what I want to accomplish:

Using cl-store, I serialize lisp objects and send them to a remote file (or db or something else) to save. After successful storage, I save the host, port and file in the reference object. I would like, whenever eval is called in a reference object, it first extracts the object, and then calls eval on the received value. Since the link can also be serial numbers in other (parent) objects or aggregate types, I can get free recursive remote link resolution on the modifying Eval, so I don’t have to go through and solve the loaded child of the link itself.

EDIT: Since objects always evaluate themselves, my question is a bit erroneously posed. Essentially, I would like to do the following:

, , REFERENCE, , , (---)?

+3
4

: , , eval Lisp. Lisp.

, , .

(defclass foo () (reference :accessor ref))
(ref some-foo)

ref - ; .

, , :

(defmacro defresolver (name class slot)
    `(defmethod ,name ((inst ,class))
        (fetch-remote-reference (slot-value inst ',slot))))

(defresolver foo-reference foo reference)

() Common Lisp :

(defmacro let-with-resolution (bindings &body body) 
    `(symbol-macrolet ,(mapcar #'(lambda (form) (list (car form) `(fetch-aux ,(cadr form)))) bindings) ,@body))

(defmethod fetch-aux ((any t)) any)
(defmethod fetch-aux ((any reference)) (fetch-remote-reference any))

; , , . , , , . , , - setf fetch-aux, .

+2

, Common Lisp . .

MOP , . Common Lisp, , . (+ p 5) p .

+2

. - . .

CLOS :

:

  • , :

    (defmethod move (( ))  ( ( )))

    (defmethod move (( ))  ...))

.

CLOS , . , . CHANGE-CLASS .

, - , - . - .

, , -.

+1
source

I would add a layer on top of your deserialization engine, which sends based on the type of incoming data.

0
source

All Articles