Re: method-let



nallen05@xxxxxxxxx wrote:
Has anyone ever seen something implimented like a METHOD-LET operator,
that defines a method for a generic function but only within the scope
of it's form, like FLET for methods?

(defclass wheat ())

(defclass bread (wheat) ())

(defclass toast (bread) ())

(defgeneric eat (x))

(defmethod eat ((x wheat))
(print "yuck"))

(defmethod eat ((x toast))
(print "yum"))

(method-let ((foo ((x bread))
(print "will you put this in the toaster?")))
(mapc #'foo (list (make-instance 'wheat)
(make-instance 'bread)
(make-instance 'toast))))
=>
"yuck"
"will you put this in the toaster?"
"yum"
NIL

I thought I remembered such an operator mentioned in an appendix at the
end of Keene's book, but when I went back and checked it was something
like GENERIC-FLET that I miss-remembered...

CLOS had a WITH-ADDED-METHODS constructs at some stage, but this was dropped due to unclear semantics. See http://www.lispworks.com/documentation/HyperSpec/Issues/iss359_w.htm for details.

I think this would be super usefull for say... making PRINT-OBJECT
behave differently in different situations (like printing to XML or in
a GUI) but not losing the semactics of the type-hierarchy and the
method dispatch...

Yes, it would be very useful. ;)

I am actually convinced that it should be a dynamically scoped construct. ContextL supports this and similar features. See http://common-lisp.net/project/closer/contextl.html

and on the subject of fantasy, how about a declaration that proclaims a
generic function to be "sealed" and that no more methods can be defined
and it can be inlined?

"One man's constant is another man's variable." - Alan Perlis

I doubt that function and class sealing would be really useful in practice. From a semantics point of view, it would be weird because it would then be one of the very few constructs (if any) that prohibits doing something in Common Lisp.

From an efficiency point of view, I also doubt that sealing would buy a lot.


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/
.



Relevant Pages

  • Re: method-let
    ... that defines a method for a generic function but only within the scope ... (defclass bread (wheat) ...
    (comp.lang.lisp)
  • Re: Subways Meatball Marinara
    ... It's a WELL-KNOWN fact that Subway bakes there own bread FRESH right there ... 9-GRAIN WHEAT Enriched wheat flour (wheat flour, barley malt, niacin, ... flavor (maltodextrin, natural flavor, silicon dioxide, lactic acid). ...
    (alt.food.barbecue)
  • Re: Sausage and peppers
    ... Daughter can't have wheat either. ... We use pasta made of rice, ... Another issue is the boiling of the pasta and the draining. ... Ener-G brand gluten free bread is more flavorless than sawdust, ...
    (rec.food.cooking)
  • Re: whither the price of bread?
    ... Even bought a much better bread making machine, and even with that, I have been successful at times and not successful at times. ... I made two loaves of part whole wheat and part white bread ... (limits were 90 cents for spring wheat, ... means that the March futures contract will no longer have a limit. ...
    (soc.retirement)
  • Re: Freezing bread
    ... I guess freezing won't change the ... Or should I just eat wheat ... Santa Rosa wheat Tortilla ... Fresh French bread which I eventually put in the fridge ...
    (rec.food.cooking)