From costanza at web.de Mon Nov 8 16:59:34 2004 From: costanza at web.de (Pascal Costanza) Date: Mon, 08 Nov 2004 17:59:34 +0100 Subject: [aspectl-devel] Help with a design decision in AspectL Message-ID: <418FA5F6.40807@web.de> Hi, I need some help with a design decision in AspectL. In AspectL, special generic functions currently need to be defined like this: (define-special-function some-function (x y z) (:definer some-function*)) The :definer option names a generic function that must be used to add methods to whereas the "main" name (some-function) is the function that must be used for calling the special function. ("Caller" and "definer" must be separated in order to make the whole concept work at all.) Furthermore, methods need to be defined like this: (defmethod some-function* ((scope t) x y z) ...) or, if you want to define a method in the current dynamic scope: (defmethod* some-function* ((scope dynamic) x y z) ...) The defmethod* operator must be used in the latter case because most CLOS implementations do not provide correct implementations of defmethod as specified in AMOP, and I rely on that. (Actually, I rely on the fact that make-method-lambda is called, but some CLOS implementations don't provide make-method-lambda at all, and those that do don't call it in the defmethod macro.) Furthermore, the first specializer (t or dynamic) is used to make the method dispatch work, so that only methods that are valid for the current dynamic scope are actually executed. This design has "evolved" over a few iterations, and by now I think it's a mess. Here is what I would actually prefer: - Special generic functions should be defined like this: (defgeneric some-function (x y z) (:generic-function-class special-function)) - Methods on special functions should be defined like this: (defmethod some-function (x y z) ...) or (defmethod some-function (x y z) (:scope dynamic) ...) I have experimented with various ways to achieve this, and I am confident by now that this would work. However, I would need to reimplement the defmethod and maybe even the defgeneric macro. There are some pros and cons and here: Pros: p1) It looks better and more in line with how CLOS is "traditionally" used. p2) The new defmethod macro would provide a way to pass method options, a feature that is currently missing in CLOS. For example, it's not currently not possible to name the method class for a method. With the new defmethod macro, this would work as follows: (defmethod do-something (a b c) (:method-class non-standard-method) ...) The idea is that not only strings and declarations are processed specially, but also all forms that are conses and start with a keyword. This is ok AFAICS, because conses that start with a keyword cannot be executed in a meaningful way anyway. p3) The new defmethod and defgeneric macros would conform to the AMOP specification which could be worthwhile for other purposes beyond AspectL as well. (There is already a MOP utilities package provided as part of AspectL that is not strictly related to AspectL and could already be used separately.) Cons: c1) I need to shadow defmethod and maybe defgeneric. This would have an impact on applications and libraries that want to use AspectL. c2) I don't know (yet?) how to ensure the compile-time semantics of those operators as specified in the ANSI spec. The various CLOS implementations do this differently and AMOP doesn't specify anything in this regard. c3) I don't know how to interact with the several development environments that want to record, for example, source locations of method definitions, etc. c1 can possibly be solved by using different names, but I want to avoid that. I don't see any strong reasons to avoid shadowing just because of shadowing. Maybe I can solve c2 in some ways, and I would try to do that, but I don't yet see how. I will probably have no time to solve c3 (but I would accept patches to make this work). I am currently strongly in favor of dropping define-special-function/defmethod* and switching to defgeneric/defmethod as sketched here, but I would appreciate to hear some other opinions, no matter whether strong or not. So what do you think? Pascal -- Pascal Costanza University of Bonn mailto:costanza at web.de Institute of Computer Science III http://www.pascalcostanza.de R?merstr. 164, D-53117 Bonn (Germany) From ml13 at onlinehome.de Sat Nov 27 12:52:46 2004 From: ml13 at onlinehome.de (ml13 at onlinehome.de) Date: Sat, 27 Nov 2004 13:52:46 +0100 Subject: [aspectl-devel] with-special-function-scope Message-ID: <3CBE8DB0-4073-11D9-8CAE-00039345C8B0@onlinehome.de> Hi, I am trying to extend the test example to use a special function that is recursive. As an example, I am defining f(x) to compute the sum of the squares from 0 to x. When I am trying to dynamically redefining the function to simply add 1 to its result, this new definition seems to get called "inside" as well. What do I have to do to get the (assert (eql (f 5) 56))) working?? I am using LispWorks MacOSX by the way. Thanks for any help, Peter. PS: By the way, is there possibly any example existing of the cached fibonacci function using the current version of aspectL? ----------------- (progn (define-special-function f (x) (:definer f*)) (defmethod f* ((scope t) x) (if (zerop x) 0 (+ (* x x) (f (1- x))))) (assert (eql (f 5) 55)) (with-special-function-scope (f*) (defmethod* f* ((scope dynamic) x) (1+ (call-next-method))) (assert (eql (f 5) 56))) (assert (eql (f 6) 91))) From pc at p-cos.net Sat Nov 27 14:34:44 2004 From: pc at p-cos.net (Pascal Costanza) Date: Sat, 27 Nov 2004 15:34:44 +0100 Subject: [aspectl-devel] with-special-function-scope In-Reply-To: <3CBE8DB0-4073-11D9-8CAE-00039345C8B0@onlinehome.de> References: <3CBE8DB0-4073-11D9-8CAE-00039345C8B0@onlinehome.de> Message-ID: <7B2BA978-4081-11D9-8446-000A95DB189E@p-cos.net> Hi Peter, Thanks a lot for the inquiry. Unfortunately, I have no immediate good answer for your question, and I am currently very busy - I have my PhD defense on Thursday, so please bear with me. I will get back to this question afterwards as soon as possible. Pascal On 27 Nov 2004, at 13:52, ml13 at onlinehome.de wrote: > Hi, > > I am trying to extend the test example to use a special function that > is recursive. > As an example, I am defining f(x) to compute the sum of the squares >> from 0 to x. > > When I am trying to dynamically redefining the function to simply add > 1 to its result, this new definition seems to get called "inside" as > well. > > What do I have to do to get the (assert (eql (f 5) 56))) working?? > > I am using LispWorks MacOSX by the way. > > Thanks for any help, > > Peter. > > PS: By the way, is there possibly any example existing of the cached > fibonacci function using the current version of aspectL? > > ----------------- > > (progn > (define-special-function f (x) > (:definer f*)) > (defmethod f* ((scope t) x) > (if (zerop x) > 0 > (+ (* x x) > (f (1- x))))) > (assert (eql (f 5) 55)) > > (with-special-function-scope (f*) > (defmethod* f* ((scope dynamic) x) > (1+ (call-next-method))) > (assert (eql (f 5) 56))) > (assert (eql (f 6) 91))) > > > > _______________________________________________ > aspectl-devel site list > aspectl-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/aspectl-devel > > -- Tyler: "How's that working out for you?" Jack: "Great." Tyler: "Keep it up, then."