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

Re: DEFUN&



I like the DEFUN& stuff I saw on your direectory - would you like to make
it available to the MACLISP community by installing it on LIBLSP and
LIBDOC?  I have three suggestions that you might want to consider
seriously first, however.

1.) Use a gensymmed symbol for the LEXPR lambda variable;  it won't make 
    any difference when compiling, since this variable should be purely 
    local, but you will avoid two pitfalls:
      1a) Inadvertent capturing of a binding by a free variable in
	  interpretive code - interpretive bindings in MACLISP do not shield
	  the local variables from other, non-lexically-apparent functions.
      1b) Inadvertent SPECIALization of the lambda variable during
	  compilation.

2.) The meaning of a DECLARE, in a DEFUN immediately following the dummy 
    argument list, cannot be retained correctly unless it is placed either 
    before the internal lambda-bindings for the optional variables, or 
    immediately after any such lambda-variable-list that has some affected 
    variables.  Thus, the form
	(DEFUN& FOO (A &optional B) 
		(DECLARE (SPECIAL A) (FIXNUM B)) 
		(PRINT (LIST A B)))
    must expand into something like
	(DEFUN FOO G0025
	       (DECLARE (SPECIAL A) (FIXNUM B))
	       (AND (OR (< G0025 1) (> G0025 2)) 
		    (ERROR 'WNA (LIST 'FOO G0025 '(1 . 2))))
	       ((LAMBDA (A) 
			((LAMBDA (B)
				 (PROGN (PRINT (LIST A B))))
			    (ARG 2)))
		    (ARG 1)))
    rather than
	(DEFUN FOO G0025
	       (AND (OR (< G0025 1) (> G0025 2)) 
		    (ERROR 'WNA (LIST 'FOO G0025 '(1 . 2))))
	       ((LAMBDA (A) 
			((LAMBDA (B)
				 (PROGN (DECLARE (SPECIAL A) (FIXNUM B))
					(PRINT (LIST A B))))
			    (ARG 2)))
		    (ARG 1)))


3.) Also, I THINK the "flattening" of contours, where there is no need
    for the sequentialization of optional arg computations, would be a 
    very easy step which could make the code more readable to the human
    eye, and less likely to produce multiple SPECBINDings in the compileed
    code.   Thus the example above could turn into
	(DEFUN FOO G0025
	       (DECLARE (SPECIAL A))
	       (AND (OR (< G0025 1) (> G0025 2)) 
		    (ERROR 'WNA (LIST 'FOO G0025 '(1 . 2))))
	       ((LAMBDA (A B) 
			(PROGN (PRINT (LIST A B))))
		    (ARG 1) (ARG 2)))
Some function, perhaps like the one in my file AI:JONL;CNVD >
    (DEFUN CERTIFY-NO-VAR-DEPENDENCY (FORM BAD-VARS BOUND-VARS) . . . 
could be pressed into service, applying it to the various initialization
forms with BAD-VARS starting out as alist of all required and optional
arguments, and BOUND-VARS starting out () .