more mset hackery. Parallel assignment.



The commercial macsyma system allows this, but Maxima allows this
only if you read in the file referred to earlier, msethack.lisp
or its compiled form.

[a,b,c]: [1,2,3]    sets,  in parallel, a:1, b:2, c:3.

the parallel part means that

a:45;
[a,b]:[a+100,a]

sets a to 145, b to 45.

You can also do [a,b,c]:100,
in which case all the variables are set to 100.
The value returned from the assignment is [100,100,100].

Since this is a pure extension to Maxima, not changing any
previous valid behavior, it seems like a benefit.

For the curious, the rather short lisp code needed is given here.


(defparameter mset_extension_operators  ;; make MLIST acceptable on LHS of assign.
     (cons (cons 'mlist '$mlistassign) mset_extension_operators))

(defmfun $mlistassign (tlist vlist)

   ;; tlist is  ((mlist..)  var[0]... var[n])  of targets
   ;; vlist is either((mlist..)  val[0]... val[n]) of values
   ;; or possibly just one value.

   (if (and (listp vlist)
	   (eq (caar vlist) 'mlist)
	   (not (= (length tlist)(length vlist))))
       (merror "Illegal list assignment: different lengths of ~M and ~M." tlist vlist))
;; end of error checking

;; handle the [a,b,c]:v case

   (unless (and (listp vlist)
	   (eq (caar vlist) 'mlist))
     (setf vlist (cons (car tlist) ;; if [a,b,c]:v  then make a list [v,v,v]
		      (make-sequence 'list (1-(length tlist)) :initial-element vlist))))

;; this one line does all the work.

   (map nil #'mset (cdr tlist)(cdr vlist))

;; return value from ":"
    vlist)