On Thu, 2 Jun 2022 10:01:15 -0000 (UTC) Zyni Moë wrote:
> Spiros Bousbouras <
spi...@gmail.com> wrote:
>
> > Can you say more like what you were writing ? Because personally I can't think
> > of an occasion where I would find the operator method combinations useful but
> > I wouldn't be able to achieve the same functionality in some other way , likely
> > a more straightforward one.
> >
>
> For instance logging: want all methods on the log object to run, use progn
> and they will now all run. Or checking some object allows some action:
> want all methods on it to return true, use and, this will then happen.
>
> > Do you mean :around methods ? These only take :most-specific-first or
> > :most-specific-last arguments. You actually had a use for those ?
>
> No I mean wrapping methods, which run outside around methods and in most
> specific last order. wrapping method means that class near top of
> inheritance graph can establish dynamic state around all other methods and
> know that it will not be overridden, or can establish default values for
> arguments:
>
> (defvar *blob-cache-default* t)
>
> (defgeneric blob (x &key cache)
> (:method-combination wrapping-standard)
> (:method :wrapping (x &key (cache *blob-cache-default*))
> (call-next-method x :cache cache)))
>
> now no other methods need to worry about the default for the cache
> argument: it is defined in one place, not many.
Where does this wrapping-standard method combination come from ? It's not
part of the CL standard.
> >> Is worth pointing out that is easy to experimentally check that method
> >> combinations such as above have no run-time overhead.
> >
> > I would imagine that depends on the implementation.
> >
>
> Any PCL-derived implementation I think, unless they have gone out of their
> way to break things. Perhaps there are non-PCL-derived implementations.
>
> As other person says, if you find method combinations unuseful is perhaps
> because you have spent too much time with the many primitive languages
> where you have to manually construct them by establishing explicit protocol
> for methods 'this method should do its check and if it succeeds it must
> invoke the next method and return its result otherwise return false' is the
> sort of awful manual errorful pain you must do in Python say to implement
> and method combination.
No , I wasn't thinking in terms of Python at all. But for example one
annoyance for me in CL is that methods cannot be called with FUNCALL [7.6.2
Introduction to Methods] although conceptually they are like functions. If
you could call them using FUNCALL , you could implement operator method
combinations as follows :
PROGN :
(dolist (method (compute-applicable-methods generic-function ...args...))
(funcall method ...args...))
It would be more or less equally easy with any other operator you want.
Instead the standard provides an entirely different interface instead of
reusing other parts of the language. It would be even more convenient if
COMPUTE-APPLICABLE-METHODS returned a vector of methods instead of a list and
, while a method M is executing , you would have a way to get the vector V M
is part of and the position i of M in V [for this particular invocation of
the generic function M is part of] .This way , you wouldn't need
NEXT-METHOD-P but instead examine if i is the greatest position in V .Also
, you wouldn't need CALL-NEXT-METHOD but , instead could simply do
(funcall (aref V (1+ i)) ...args...) .I would also find it more aesthetic if
ADD-METHOD also accepted as a 2nd argument [i.e. the method argument] forms
like (function symbol) or (lambda (...) ...code...) .
Perhaps there are good reasons why the standard forces methods to be treated
very differently from functions but I can't think of such reasons.
One could implement some of the above ideas as an alternative way of doing
generic functions and methods and this is the kind of thing I'm thinking
might be more straightforward to use.
--
The American Mathematical Society's 1979 subject classification contains 61
basic classifications having approximately 3400 subcategories, and it has
been estimated that the number of new theorems published yearly in
mathematics journals is in excess of 100,000.
http://web.mst.edu/~lmhall/0-Introduction.pdf