[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

DEFMETHOD automagic references considered random

From: Richard Lamson <rsl@MAX-FLEISCHER.SF.Dialnet.ILA.COM>
Subject: DEFMETHOD automagic references considered random
To: Jon L White <jonl@lucid.com>
cc: CommonLoops.PARC, rsl@MAX-FLEISCHER.SF.Dialnet.ILA.COM
In-Reply-To: <9009102310.AA15538@caligula>
Reply-To: rsl@ILA.COM
Received: from FUJI.ILA.COM ([]) by Xerox.COM ; 11 SEP 90
09:13:21 PDT
with SMTP id 55742; 11 Sep 90 12:08:26 EDT
Original-Date: Mon, 10 Sep 90 18:47 PDT
Message-ID: <19900911014743.9.RSL@MAX-FLEISCHER.SF.Dialnet.ILA.COM>
Line-fold: No

    Date: Mon, 10 Sep 90 16:10:06 PDT
    From: Jon L White <jonl@lucid.com>

    re: Can someone please explain to me the reason why specialized
arguments are
	automagically referenced in the bodies of methods?

    Part of the purpose of the specialized variables is to do method
    selection "within the generic function itself";  so there is a sense
    in which the formal parameter variable is being indirectly referenced.
    For example, in the following generic function WHAT-COUNT, no method at
    all explicitly references the variable "x";

	(defmethod what-count ((x foo)) 1)
	(defmethod what-count ((x bar)) 2)
	(defmethod what-count ((x baz)) 3)

    but the discrimination must have referenced it implicitly, just as
    as if it had been written as a non-generic function as follows:

	(defun what-count (x)
	  (etypecase x
	    (foo 1)
	    (bar 2)
	    (baz 3)))

I think this is the same argument as this other related issue:  Suppose I
write a function which takes keywords, and, although I don't care what
value is passed in for a particular keyword, I wish to know whether or not
that keyword was actually passed in:

  (defun random-test (&rest all-the-stuff &key (nonsense nil nonsense-p)
    (if nonsense-p
	(apply nonsensical-random-test all-the-stuff)
	(apply no-nonsense-random-test all-the-stuff)))

Is the compiler correct in warning me that I do not use the value of the
lexical variable NONSENSE?  I claim that I must supply an IGNORE
declaration for NONSENSE if I want to suppress that warning.  I base this
philosophically on the argument that the variable NONSENSE is not
referenced anywhere in the scope of its binding.