flatten() extended functionality



Hi!

I've sent this email to Starvos (since he is the copyright holder of  
nset.lisp) a couple of days ago, but I haven't gotten any response.  
Therefore I'm sending this on maxima mailing list.

I've modified $flatten in nset.lisp:
--------------------------
(defun flattenl-op (e op num)
   (mapcan #'(lambda (e)
	        (cond ((or (= num 0) (mapatom e) (not (alike1 (mop e) op)))
	  	     (list e))
	  	    (t (flattenl-op (margs e) op (1- num)))))
	    e))

(defun $flatten (e &optional (num nil))
   (unless (and (not (null num)) (integerp num) (> num -1))
     (merror "flatten: Second argument must be a non-negative  
integer: ~M" num))
   (when (null num) (setf num -1))
   (cond ((or (= num 0) (specrepp e) (mapatom e)) e)
     (t (mcons-op-args (mop e) (flattenl-op (margs e) (mop e) num)))))
-------------------------

It works as before for flatten(expr). For 'flatten(expr, num)' the  
result is, that flatten 'flattens' 'num' times:

%i84: aa:[[a,b], [[c]], d, [[h],[[d],s]]];
%o84: [[a,b],[[c]],d,[[h],[[d],s]]]

%i134: flatten(aa,1);
%o134: [a,b,[c],d,[h],[[d],s]]

%i135: flatten(aa,2);
%o135: [a,b,c,d,h,[d],s]

%i136: flatten(aa,3);
%o136: [a,b,c,d,h,d,s]
..

My lisp sucks (feel free to rewrite), I know, but what do you think  
about the functionality? This would breach the gap between table and  
create_list output, as
flatten( table(i+j,[i,3],[j,3]) , 1) == create_list(i+j, i,1,3, j,1,3).

Also such flatten functionality can come in handy in many places when  
working with lists of perhaps coordinates [x,y,z] and you don't want  
to flatten out the whole list all together...

I can include this to CVS if I get developer access... Otherwise it  
would be nice if someone did it instead of me.

Regards,
Ziga Lenarcic