Apparently, the documentation is bad: this per the former maintainer of calc-vec.el, Jay Belanger. His advice (besides contacting [email protected]) was to simply go to the main Calc docs (e.g. this and this) and use those function names (usually the one in brackets) prefixed by calcFunc-
. Another curiosity is you need to refer to a vector in its "internal" format, namely a list: (vec 1 2 3)
, which then can be seen as a normal Calc vector with calc-eval
:
(setq myv1 '(vec 1 2 3))
=> (vec 1 2 3)
(calc-eval myv1)
=> "[1, 2, 3]"
(calcFunc-subvec myv1 1 3)
=> (vec 1 2)
(calcFunc-vlen myv1)
=> 3
but it can get ugly. . .
(setq myv2 '(vec 2 4 6 8))
(calcFunc-arrange myv2 1)
=> (vec (vec 2) (vec 4) (vec 6) (vec 8))
requiring calc-eval
to make it pretty
(calc-eval (calcFunc-arrange myv2 1))
=>"[[2], [4], [6], [8]]"
why calc-eval
does this, I don't know.
But this is not always easy. Here's an example that seems only calc-eval
-friendly:
(calc-eval "deg(37@ 26' 36.42\")")
=> "37.44345"
This is as close as I can get
(calcFunc-deg '(hms 37 26 36))
=> (float 374433333333 -10)
but it won't accept 36.42
for some reasons better minds than mine might understand from this calc-math.el
code:
;;; Convert A from HMS or radians to degrees.
(defun calcFunc-deg (a) ; [R R] [Public]
(cond ((or (Math-numberp a)
(eq (car a) 'intv))
(math-with-extra-prec 2
(math-div a (math-pi-over-180))))
((eq (car a) 'hms)
(math-from-hms a 'deg))
((eq (car a) 'sdev)
(math-make-sdev (calcFunc-deg (nth 1 a))
(calcFunc-deg (nth 2 a))))
(math-expand-formulas
(math-div (math-mul 180 a) '(var pi var-pi)))
((math-infinitep a) a)
(t (list 'calcFunc-deg a))))
(put 'calcFunc-deg 'math-expandable t)
. . . yes, the lengths some people go to stay in Emacs, i.e., I'm trying to follow a Coursera course that wants me to use Python, but I know a better way. . .
(math-concat [1, 2] [3, 4])
gives(vec [1 (\, 2)] [3 (\, 4)])
but(vec-length [1, 2, 3, 4])
and(build-vector 1 5]
etc give void function errors.,
has a special meaning in ELisp (evaluation of the following expression in the context of a quoted expression). Thus a vector would be spelled[1 2]
, not[1, 2]
.void function
. As I said above,calcFunc-fact
works, butvec-length
doesn't. I can only assume I haven't loaded the proper library/package. As far as how to do a vector, I was just following the examples.calc-vlen
.