[Maxima] Push and pop in Maxima

Žiga Lenarčič ziga.lenarcic at gmail.com
Tue Sep 8 05:20:08 CDT 2009


Hi!

Perhaps it would be nice to have 'push' and 'pop' in Maxima, since  
Maxima's lists are 'real' lists. I found some old implementation of  
push and pop in maxima language in /share/ but I think it would be  
nice to have a fast lisp version in Maxima by default.

Here's some code I quickly threw toghether (it works, but there's no  
error checking, documentation yet):

(defmspec $push (args)
           (let* ((element (meval (second args)))
                  (ms (third args))
                  (value (meval ms))
                  (head (pop value))
                  (contents (push element value)))
             (set ms (cons head contents))))

(defmspec $pop (args)
   (let* ((ms (second args))
          (contents (if (boundp ms)
                      (meval ms)
                      nil))
          (head (pop contents))
          (first-el (pop contents)))
     (set ms (cons head contents))
     first-el))

I think I should use (symbol-value ms) instead of (meval ms) to get  
the list attached to the symbol, right? Also it's possible to push  
and pop from an mtimes or mplus expression or to function arguments..  
Should Maxima's push and pop only work on mlist-s or on other  
expressions also (pushing on a matrix would be rather dangerous..)? I  
think it should work only on lists. 'push' and 'pop' may be useful  
when constructing lists from somewhere inside the algorithm (loop).

If there's any interest I can write documentation, make code nicer in  
order to include it in Maxima.

Regards,
Ziga


More information about the Maxima mailing list