Function: calc-unpack-item

calc-unpack-item is a byte-compiled function defined in calc-vec.el.gz.

Signature

(calc-unpack-item MODE ITEM)

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calc-vec.el.gz
(defun calc-unpack-item (mode item)
  (cond ((not mode)
	 (if (or (and (not (memq (car-safe item) '(frac float cplx polar vec
							hms date sdev mod
							intv)))
		      (math-objvecp item))
		 (eq (car-safe item) 'var))
	     (error "Argument must be a composite object or function call"))
	 (if (eq (car item) 'intv)
	     (cdr (cdr item))
	   (cdr item)))
	((> mode 0)
	 (let ((dims nil)
	       type new)
	   (setq item (list item))
	   (while (> mode 0)
	     (setq type (calc-unpack-type (car item))
		   dims (cons type dims)
		   new (calc-unpack-item nil (car item)))
	     (while (setq item (cdr item))
	       (or (= (calc-unpack-type (car item)) type)
		   (error "Inconsistent types or dimensions in vector elements"))
	       (setq new (append new (calc-unpack-item nil (car item)))))
	     (setq item new
		   mode (1- mode)))
	   (if (cdr dims) (setq dims (list (cons 'vec (nreverse dims)))))
	   (cond ((eq calc-unpack-with-type 'pair)
		  (list (car dims) (cons 'vec item)))
		 (calc-unpack-with-type
		  (append item dims))
		 (t item))))
	((eq calc-unpack-with-type 'pair)
	 (let ((calc-unpack-with-type nil))
	   (list mode (cons 'vec (calc-unpack-item mode item)))))
	((= mode -3)
	 (if (eq (car-safe item) 'hms)
	     (cdr item)
	   (error "Argument must be an HMS form")))
	((= mode -13)
	 (if (eq (car-safe item) 'date)
	     (cdr item)
	   (error "Argument must be a date form")))
	((= mode -14)
	 (if (eq (car-safe item) 'date)
	     (math-date-to-dt (math-floor (nth 1 item)))
	   (error "Argument must be a date form")))
	((= mode -15)
	 (if (eq (car-safe item) 'date)
	     (append (math-date-to-dt (nth 1 item))
		     (and (not (math-integerp (nth 1 item)))
			  (list 0 0 0)))
	   (error "Argument must be a date form")))
	((eq (car-safe item) 'vec)
	 (let ((x nil)
	       (y nil)
	       res)
	   (while (setq item (cdr item))
	     (setq res (calc-unpack-item mode (car item))
		   x (cons (car res) x)
		   y (cons (nth 1 res) y)))
	   (list (cons 'vec (nreverse x))
		 (cons 'vec (nreverse y)))))
	((= mode -1)
	 (if (eq (car-safe item) 'cplx)
	     (cdr item)
	   (if (eq (car-safe item) 'polar)
	       (cdr (math-complex item))
	     (if (Math-realp item)
		 (list item 0)
	       (error "Argument must be a complex number")))))
	((= mode -2)
	 (if (or (memq (car-safe item) '(cplx polar))
		 (Math-realp item))
	     (cdr (math-polar item))
	   (error "Argument must be a complex number")))
	((= mode -4)
	 (if (eq (car-safe item) 'sdev)
	     (cdr item)
	   (list item 0)))
	((= mode -5)
	 (if (eq (car-safe item) 'mod)
	     (cdr item)
	   (error "Argument must be a modulo form")))
	((memq mode '(-6 -7 -8 -9))
	 (if (eq (car-safe item) 'intv)
	     (cdr (cdr item))
	   (list item item)))
	((= mode -10)
	 (if (eq (car-safe item) 'frac)
	     (cdr item)
	   (if (Math-integerp item)
	       (list item 1)
	     (error "Argument must be a rational number"))))
	((= mode -11)
	 (if (eq (car-safe item) 'float)
	     (list (nth 1 item) (math-normalize (nth 2 item)))
	   (error "Expected a floating-point number")))
	((= mode -12)
	 (if (eq (car-safe item) 'float)
	     (list (calcFunc-mant item) (calcFunc-xpon item))
	   (error "Expected a floating-point number")))
	(t
	 (error "Invalid unpacking mode: %d" mode))))