Prev: [ANN] Filtered functions
Next: Filtered functions.
From: Pascal Costanza on 5 Dec 2009 16:55 Ron Garret wrote: > In article <7ntfj7F3m9fjiU1(a)mid.individual.net>, > Pascal Costanza <pc(a)p-cos.net> wrote: > >> Filtered functions are an extension of generic functions, extended with >> a filtering step where the arguments received by a generic function are >> mapped to other values based on user-defined mapping functions. Those >> filtered values are then used to perform the actual selection and >> execution of applicable methods. Nevertheless, the methods that are >> eventually executed see the original objects as received by the generic >> function, and not the filtered ones. > > I like this concept, but is there a reason you designed the API the way > you did instead of simply providing a facility for subclassing built-in > classes? In other words, why not simply do: > > (def-subclass positive-integer integer 'plusp) > > (defmethod factorial ((n positive-integer)) ...) > > That would seem to me to provide the same functionality, and would make > code using this feature easier to write and debug. How does the factorial function know which def-subclass definitions to take into account? Should it try all of them? A subset? Based on what criteria? What does it do with the ones where the predicate fails (by signaling an error)? If several of the def-subclass forms apply, which one is selected? Are they all selected? In what order? What is the most specific one, what is the last specific one, and so on? These are the typical issues you have to solve when designing predicate-dispatch-style systems, and they are not trivial to solve (basically because of the halting problem). Filtered functions solve this by defining the acceptable filters along with the filtered function definition, and by defining an order among filters along the way that can be chosen per filtered function. The idea to specify an order between custom filters (specializers) was first described by Jim Newton, and is described in more detail in a paper by Jim Newton and Christophe Rhodes. The difference between their approach and ours is that in their approach, the order is defined at the meta-level (as part of the MOP), whereas here it is defined at the base-level (as part of the define-filtered-function form). I think the latter is more convenient, since the orders tend to be ad hoc anyway, as far as I can tell. Having per-function orders seems to have been adopted by now in Clojure as well. Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Raffael Cavallaro on 5 Dec 2009 17:18 On 2009-12-05 15:18:53 -0500, Pascal Costanza <pc(a)p-cos.net> said: > I'm curious: How do you see them used in combination? First, apologies if the parens or syntax are a bit off - I'm just typing this into a newsreader, not a lisp editor. I'm thinking of a language construct like "whenever" (whenever :any foo (bar :newval-even (evenp newval)) (do-something-in-response ...)) ;; where foo is a class, bar is a slot, and *my-foo* ;; is a particular instance of class foo. ;; the formal parameters newval, oldval, ;; and obj (i.e., self), would be available ;; in the whenever macro (whenever :any foo (bar :newval-greater-than-3 (> newval 3) (do-something-in-response ...)) (whenver *my-foo* (bar :oldval-even (evenp oldval)) (do-something-uniquely-my-foo-in-response)) This would be translated to something like: (define-filtered-function modify-bar-of-foo (obj newval oldval) (:filters (:bar-newval-even (when (evenp newval) t)) (:bar-oldval-even (when (evenp oldval) t)) (:bar-newval-greater-than-3 (when (> 3 newval) t)))) (defmethod modify-bar-of-foo :filter :bar-newval-even (obj newval oldval) (do-something-in-response...)) .... (defmethod modify-bar-of-foo :filter :bar-oldval-even ((obj (eql (*my-foo*))) newval oldval) (do-something-uniquely-my-foo-in-response)) which would be updated with new :filters and defmethods for each such rule added. The function modify-bar-of-foo would be called by a cells-like dataflow framework. Each time round, any slot modification would trigger the corresponding modify-slot-of-class method, and that would be dipatched on filtered values which were determined by the "whenever" rules. By combining the two, (dataflow and predicate-dispatch) you would have a purely declarative lisp dsl where you could program in "rules" expressed as "whenever" clauses. warmest regards, Ralph P.S. I know that something like this could be done in cells alone, and that this is just a matter of surface syntax (i.e., the cells forms would contain big case or cond expressions) but, when all is said and done, in a lanaguage with minimal syntax like lisp, every mode of expression is mostly just a matter of surface syntax... -- Raffael Cavallaro
From: Slobodan Blazeski on 5 Dec 2009 17:41 On Dec 5, 4:28 pm, Pascal Costanza <p...(a)p-cos.net> wrote: > Slobodan Blazeski wrote: > > Any ideas where those would be useful? ContextL was interesting but I > > never figured a natural problem where to use it. > > Did you check the paper? I've read your paper, the interpreter code is very cool still it doesn't answer my question. > > An extensible code walker could be a nice application. (That's like the > interpreter, except that it doesn't interpret. ;) I know a little bit about code walkers such us cl-cont but I'm not in that business. I work on programs that model some processes, they work continuously instead of getting some input and spewing some output. Is there is some interesting problem that this tool solves for me? Think like salesman, you have this nice little widget, price tag is fine you only need to explain to me how it improves the quality of my life. For example if you are selling me objects you could say: Haven't you noticed that some things always come together, like the personal computer that is always consisted of monitor, box, keyboard and mouse. Without objects you would always have to write monitor, box, keyboard and mouse again and again objects allow you to group them and just say personal computer. Before: monitor m, box b, keyboard k, mouse m1 repeated 100 times all over the program. After personal-computer pc; Or if you're in macros trade: Have you noticed all that code that you write again and again macros allows you to write that code for you and your programmers to use their time on solving problems. Before; defclass ... () ; boilerplate some code ; another boilerplate After (defboilerplate-class some-code) ; boilerplate and another boilerplate code are written by the macro So what's your commercial? > > Jim Newton also described a code walker as a motivation for a similar > extension of a CLOS-style object system he described earlier... > > Pascal > > -- > My website:http://p-cos.net > Common Lisp Document Repository:http://cdr.eurolisp.org > Closer to MOP & ContextL:http://common-lisp.net/project/closer/ (*)http://www.htdp.org/2003-09-26/Book/curriculum-Z- H-6.html#node_chap_3
From: Raffael Cavallaro on 5 Dec 2009 17:47 On 2009-12-05 17:18:27 -0500, Raffael Cavallaro <raffaelcavallaro(a)pas.espam.s.il.vous.plait.mac.com> said: > I'm thinking of a language construct like "whenever" > > (whenever :any foo (bar :newval-even (evenp newval)) > (do-something-in-response ...)) You could also add :priority which would be used to order the filter specifications: (whenever :any foo (bar :newval-even (evenp newval) :priority high) (...)) -- Raffael Cavallaro
From: Kenneth Tilton on 5 Dec 2009 17:52
Raffael Cavallaro wrote: > On 2009-12-05 14:32:05 -0500, Kenneth Tilton <kentilton(a)gmail.com> said: > >> Because you established somehow that I wished I had written Filtered >> Functions? Or do you not know the term "sour grapes"? > OK, now let's see your hasty retreat: > > IOW, you don't wish that you had written filtered-functions, but rather > that cells were as well documented and well received as > filtered-functions will be. Oh, good! You don't know what "sour grapes" means! Meanwhile, I provided a thumbs-down analysis on the whole idea of GFs to justify my assessment of an enhancement thereto, to which you responded with irrelevant guesswork as to my motivation. I guess if you have no defense of GFs to offer, that was a smart move. kt -- http://thelaughingstockatpngs.com/ http://www.facebook.com/pages/The-Laughingstock/115923141782?ref=nf |