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

Re: (COP pred form)



That's a cute idea. Your example ought perhaps be called MAPTREE though, since
it really is far more general than copying (and far less constrained).

Re: Your query about better semantics... 
How about making pred have to return T if it wanted the object copied, and then
using a standard system method for copying that object (a la typecaseq or 
more general method or flavors or whatever) ... eg

	(DEFUN COP (PRED X)
	  (IF (NOT (FUNCALL PRED X)) X
	      (TYPE-CASEQ X
		((CONS PAIR LIST) (CONS (COP PRED (CAR X)) (COP PRED (CDR X))))
		((STRING)	  (FORMAT NIL "~A" X))
		... etc ...
		(OTHERWISE	  X) ; Should this be an error?
		)))

(Please assume the obvious meaning/spelling for TYPE-CASEQ if it doesn't exist
 or runs under some other name.)

The only sad thing is that PRED will almost certainly have the form

	#'(LAMBDA (X) (TYPE-CASEQ X ((....) T) (OTHERWISE NIL)))

which means that the case dispatch will be done twice. Maybe a special form
like COP-SURROGATE could be used as follows:

		(COP-SURROGATE types form)

where types was an unevaluated list of types to copy. So

	(COP-SURROGATE (CONS STRING) form)

would turn into (using the obsolete Maclisp LABEL semantics):

	((LABEL COP-SURROGATE-G0001 (X)
		(TYPE-CASEQ X
		    ((CONS) (CONS (FUNCALL COP-SURROGATE-G0001 (CAR X))
				  (FUNCALL COP-SURROGATE-G0001 (CDR X))))
		    ((STRING) (FORMAT NIL "~A" X))
		    (T X)))
	 form)
		            
Note, type dispatch might not be the only kind of thing you want. eg,
I might want to copy all lists, but only hunks with a (CXR 0 h) of G0002
or something. In that case, COP-SURROGATE wouldn't be strong enough and
I'd need the more general COP.

-kmp

ps I suppose COP is symmetric with ASS, MEM, etc. so that's an ok name if
   anyone cares to put it in. COP-SURROGATE is probably not worth putting
   in under any name (certainly not that name!), but I present it only to
   illustrate something I expect to be true of the use of COP.