|
From: Eduardo O. <edu...@gm...> - 2025-10-04 04:34:44
|
Hi list, my "Lisptree" thing - see <https://anggtwu.net/eev-maxima.html#lisptree> - has several parts that were written in a very naive way, and that I am trying to rewrite... in particular, I tried to see if Lisptree would handle "superquoted" objects correctly - see: https://github.com/maxima-project-on-github/maxima-packages https://github.com/maxima-project-on-github/maxima-packages/tree/master/robert-dodier/superq and it turns out that it doesn't. Here's an example that shows that Lisptree simplifies a ((MFACTORIAL) 5) to 120: (%i20) o1 : superq(n!); (%o20) superq(n!) (%i21) o2 : superq(5!); (%o21) superq(5!) (%i22) format0(o1); (%o22) (($SUPERQ) ((MFACTORIAL) $N)) (%i23) format0(o2); (%o23) (($SUPERQ) ((MFACTORIAL) 5)) (%i24) lisptree(o1); (%o24) superq | ! | n (%i25) lisptree(o2); (%o25) superq | 120 (%i26) Now the real question. I would like to try to replace the Lisptree functions that traverse Maxima objects/trees by other functions that don't simplify subobjects/subtrees, and I am looking for _idiomatic_ ways to do that in Lisp. The real question is: does Maxima have an utility function that receives a Maxima object and returns a version of it "with a simp added if needed"? I'm thinking on something that would work like this: (addsimp '((mfactorial) 5)) ;; -> '((mfactorial simp) 5)) (addsimp '((mfactorial simp) 5)) ;; -> '((mfactorial simp) 5)) (addsimp 42) ;; -> 42 (addsimp "foo") ;; -> "foo" and that would be better than this quick-and-dirty hack... (defun addsimp-inner (flags) (if (member 'simp flags) flags (cons 'simp flags))) (defun addsimp (o) (if (consp o) `((,(caar o) ,@(addsimp-inner (cdar o))) ,@(cdr o)) o)) Thanks in advance! Eduardo |