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

Re: DIGITP and DIGIT-WEIGHT



Isn't the problem here that lisp as we
think of it has the strange property of non-null truthity?	
We get efficiency in runtime and codesize by having
predicates return useful values. However, most
of our control structures still don't support
this fully (although many suggestions and private macros abound).
I think the elegance of a return value of a predicate is wiped
out if I then see people doing:

(DEFUN FOO ( .... &AUX TEMP)

   (CASEQ (SETQ TEMP (FOOBARP X))
	   <code-section-1> )  <code-section-2>)

This is especialy gross if because of compiler deficiency
the programmer re-uses (i.e. SETQ's), the variable TEMP
in either code sections 1 or 2.

Having a uniform set of predicates doesn't solve the whole 
efficiency/modularity/elegance problem if its not backed
up by good control structures.

Another perhaps parallel way of aproaching this is to give
predicates very special consideration in the compiling.
When compiling "(IF (FOOBARP X) ...)" you might try
"opening up" the routine FOOBARP if it is suggested by the
properties of FOOBARP. This is not very novel and will only
win (be practical) under certain conditions, however it
does allow you to have your cake (general predicates)
and it eat too (efficiency), in many cases.

This DIGITP guy seems to cry out for a macro expansion
generalization which I heard about first from ALAN.
If the macro DIGITP gets a second argument of VALUE, EFFECT, or 
PREDICATE. Then it can do nice things, (IF (DIGITP X) ...) =>
(IF (MEMBER X '(#/0 #/1 ... #/9)) ...) Which in turn opens
up to a LOOP construct with two exit forms, one for the IF and one
for the THEN conditions. 

"Compilation" of a predicate (either by machine or by hand),
then becomes one of generating the usual code for returning NIL
or a value, and also generating optimizers and predicates to
look for possible optimizations. Automaticaly getting
feedback from user code (which all passes through the compiler),
is then probably more important than any amount of
arguing tivialities like DIGITP/DIGIT-WEIGHT.


-gjc

p.s. I wish ALAN's second argument to macros was implemented
as soon as possible by all reasonable lisps. It would give
us more to play with and less to argue about.

Think about (IF (DIGITP X) <FOO> <BAR>) going to

(DO ((J #/0 (1+ J)))
    ((> J #/9) <BAR>)
    (AND (= X J) (RETURN <FOO>)))