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

Re: Argument lists: a proposal to shoot at



	
    Date: Thu, 26 Jun 86 12:34 EDT
    From: Guy Steele <gls@Think.COM>
    To: common-lisp@SU-AI.ARPA
    Subject: Argument lists: a proposal to shoot at
    Message-ID: <860626123445.9.GLS@BOETHIUS.THINK.COM>
    
    In the following function descriptions, assume that the argument
    function has Q required parameters and P &optional parameters, and that
    R, K, or A is true iff the function has respectively a &rest, &key, or
    &allow-other-keys lambda-keyword.
    
    
    FUNCTION-MIN-ARGS function					[Function]
    
    Returns Q, the minimum number of arguments that must be supplied when
    the function is called.
    
    
    FUNCTION-MAX-ARGS function					[Function]
    
    Returns (AND (OR (NOT R) K) (+ Q P)), that is, the maximum number of
    arguments, exclusive of arguments for keyword parameters, that may be
    supplied when the function is called.  A return value of NIL indicates
    that there is no such maximum, that is, the function has a &rest
    parameter and no &key parameters.  (Note that if a function has keyword
    parameters, exactly (+ Q P) arguments have to be supplied before the
    arguments that will be interpreted for keyword parameters.)

Your encoding scheme does not let me see the number of
'probably-stack-based' parameters (i.e., P+Q) given a function that
has a &rest param and no &key params.  This makes it impossible to
provide an encapsulation that would use &rest only where necessary (it
would force the use of a &rest parameter for all args beyond the
required parameters).

How about keeping the number of functions down and eliminating the
'encoding' in MAX-ARGS, and using correct terminology with the
following one-function alternative to FUNCTION-MIN-ARGS, -MAX-ARGS,
-HAS-KEYWORD-PARAMETERS, and -KEYWORD-PARAMETERS.  I think
FUNCTION-KEYWORD-PARAMETER-P addresses an idiom common enough to
warrant its own function.

FUNCTION-PARAMETERS function				[Function]

Returns Q, P, R, K, a list of keywords explicitly accepted by the
function (order undefined), and A.  Note that if K is false, the list
is necessarily empty.
    
    FUNCTION-KEYWORD-PARAMETER-P function keyword			[Function]
    
    Returns two values.  If the function directly accepts the keyword as the
    name of a keyword parameter (that is, the keyword parameter appeared in
    the parameter list of the function), then the values T T are returned.
    If the function does not accept the keyword directly, but its parameter
    list contained &allow-other-keywords, then the values T NIL are
    returned.  Otherwise the values NIL NIL are returned.  Note that
    FUNCTION-KEYWORD-PARAMETER-P may be correctly applied to any function,
    even one that was not declared with &key (the values NIL NIL are always
    returned for such a function).
    
    ...
    
    Point of design philosophy: &aux "parameters" aren't anybody's business
    at this level of abstraction.  I don't deny that for the sake of
    debuggers this information, and such other information as the names of
    parameters, may be desired.
Agreed.


    
    --Guy
    
	-- Nick