applying at levels



Actually, I had the Mma behavior wrong.
flatten(expr,n) flattens levels 1 through n, which is probably
more useful. There isn't really very much to write, just add
a little bit to the existing code for flatten.

(defun $nflatten (e &optional nmax)
  (cond ((eq nmax nil) ($flatten e))
	((or (specrepp e) (mapatom e)) e)
	(t (mcons-op-args (mop e) (nflattenl-op (margs e) (mop e) nmax  0 )))))

(defun nflattenl-op (e op nmax n)
  (mapcan #'(lambda (e)
	      (cond ((or (eq n nmax) (mapatom e) (not (alike1 (mop e) op)))
		     (list e))
		    (t (nflattenl-op (margs e) op nmax (1+ n)))))
	  e))

regards,
John