Possible reader bug



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))

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

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

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

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

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

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

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)))))

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 - I’ll see if I can reproduce the problem.


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))


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



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.


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


That one was expected. :)