?iga,
Thanks for your mail to me.
Barton Willis and I hold the copyright on nset, but it is released
under GPL (like the rest of Maxima), so you don't need our permission
to do things with it.
On the other hand, user-visible design changes should be discussed on
the Maxima mailing list (as you're doing) and we should reach some
sort of consensus.
Personally, I'm not a big fan of 'flatten', because I think it
encourages sloppy programming and subtle errors (what if what are
logically leaves are represented as lists?).
The explicit-n version of flatten is a better idea, except for one
thing: it should give an error if n > 0 and the argument is not of the
appropriate type.
Examples:
flatten( [a,b,c], 0) => [a,b,c]
flatten( [a,b,c], 1) => error: a does not have operator '['
flatten( f( f( 2 ) ), 0) => f(f(2))
flatten( f( f( 2 ) ), 1) => f(2)
flatten( f( f( 2 ) ), 2) => error: 2 does not have operator 'f'
That gives the user appropriate warnings.
-s
On Fri, May 15, 2009 at 6:32 AM, ?iga Lenar?i? <ziga.lenarcic at gmail.com> wrote:
> 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
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>