"How-to" request

Pascal Bourguignon pjb at informatimago.com
Fri Mar 19 18:21:58 UTC 2021


Le 19/03/2021 à 18:58, Marco Antoniotti a écrit :
> Hi
> 
> I am trying to create a new ASDF:OPERATION, but I must be missing 
> something and the manual (or Google) does not seem to help much.
> 
> How do you create a new operation, which may be quite simple?  Or 
> better, how do you get PERFORM and/or OPERATE to actually do something 
> for you.
> 
> I know I should RTFM, but in this case it is more of a RTFC, which is 
> far more difficult.
> 
> I tried the following
> 
> (defclass my-op (non-propagating-operation) ())
> 
> (defmethod perform ((o my-op) (s system))
>     (print 42))
> 
> (defmethod operate ((o my-op) (s system) &key &allow-other-keys)
>     (print 666))
> 
> But then, doing
> 
> cl-user 42> (operate 'my-op (find-system "somesys") :bar 1024)
> #<MY-OP >
> #<ASDF/PLAN:SEQUENTIAL-PLAN 2301B97B>
> 
> is all I get.
> 
> Any tutorial or advice?


If you don't override operate, then the inherited operate will call your 
overriden perform:


cl-user> (defclass my-op (non-propagating-operation) ())

(defmethod perform ((o my-op) (s system))
    (print 42))
#<standard-method asdf/action:perform (my-op system) {1007690373}>
cl-user> (operate 'my-op (find-system "cl-naive-store") :bar 1024)

42
#<my-op >
#<sequential-plan {10076CDA23}>
cl-user>


Alternatively, you may also override operate, but you need to call the 
next method (or use a :before or :after method:


cl-user> (defmethod operate ((o my-op) (s system) &rest keys &key 
&allow-other-keys)
            (print (list 666 keys))
            (call-next-method o s))
#<standard-method asdf/operate:operate (my-op system) {10082AB6E3}>

cl-user> (operate 'my-op (find-system "xmls") :bar 1024)
; loading 
#P"/Users/pjb/quicklisp/dists/quicklisp/software/xmls-3.0.2/xmls.asd"

(666 (:bar 1024))
42
#<my-op >
#<sequential-plan {100857BF33}>
cl-user> (operate 'my-op (find-system "xmls") :bar 1024)

(666 (:bar 1024))
#<my-op >
#<sequential-plan {1002AFF8A3}>
cl-user>


Note that default asdf:operate method registers that the perform method 
has been called on the system, so it doesn't call it again.


-- 
__Pascal Bourguignon__



More information about the asdf-devel mailing list