#1

Hello,

during my setup of a simple quaternions library I got this weird behaviour:

79454> uLisp 3.4
79999> (defun qtn (x i j k) (list x i j k))
qtn

79978> (defun qx (q) (car q))
qx

79966> (defun qi (q) (cadr q))
qi

79955> (defun qj (q) (caddr q))
qj

79944> (defun qk (q) (car (cdr (cddr q))))
qk

79928> (defun q+ (a b)
(qtn (+ (qx a)(qx b))
(+ (qi a)(qi b))
(+ (qj a)(qj b))
(+ (qk a)(qk b))))
q+

79883> (defvar q1 (qtn -1.0 2.0 3.0 3.0))
q1

79872> q1
(-1.0 2.0 3.0 3.0)

79872> (q+ q1 q1)
(-2.0 4.0 6.0 6.0)

79872> (defun q* (a b)
(qtn (- (* (qx a) (qx b)) (* (qi a) (qk b)))))
q*

79842> (q* q1 q1)
Error: ‘qtn’ too few arguments
79842> (edit q*)
Error: unknown variable: (lambda (a b) (qtn (- (* (qx a) (qx b)) (* (qi a) (qk b)))))

Is it something expected? I don’t recall anything special about “q*” as special LISP form.

Thanks,
Fausto

#2

Thanks - I’ll see if I can reproduce the problem.

#3

I found my error: it’s

(edit 'q*)

But I got a different error in a different place in the function.
This is the complete definition:

(defun q* (a b)
(qtn (- (* (qx a) (qx b))
(* (qi a) (qi b))
(* (qj a) (qj b))
(* (qk a) (qk b)))
(+ (* (qi a) (qx b))
(* (qx a) (qi b))
(* (qj a) (qk b))
(- (* (qk a) (qj b))))
(+ (* (qx a) (qj b))
(- (* qi a) (qk b))
(* (qj a) (qx b))
(* (qk a) (qi b)))
(+ (* (qx a) (qk b))
(* (qi a) (qj b))
(- (* qj a) (qi b))
(* (qk a) (qx b)))))

if I execute this function I have:

79720> (q* q1 q1)
Error: ‘*’ argument is not a number: (lambda (q) (cadr q))

#4

Why do you have:
(- (* qj a) (qi b)) and (- (* qi a) (qk b))
This explains your ‘*’ argument is not a number error.
Did you forget some parens? :-o

``    -Rusty-``

#5

Also, in

79842> (q* q1 q1)
Error: ‘qtn’ too few arguments

Your def of q* calls qtn with only 1 argument yet expects 4.
A list of 4 numbers doesn’t expand to 4 separate arguments when passed to a function.

#6

Thanks a lot for spotting the missing one. I triple checked the code and I wasn’t able to find it.

#7

That one was expected. :)

#8