;; Simple function to calculate the prime factors of a (non-prime) integer n
;; /Mic

(defun primefac (n)

  (if (not (numberp n))
     (progn
        (format t "~s is not a number!" n)
        (return)))

  (format t "The prime factors of ~a are: " n)

  (tagbody loop_1
     (if (= (/ n 2) (truncate (/ n 2)))
        (progn
           (format t "2 ")
           (setf n (/ n 2))
           (if (> n 1.0) (go loop_1)))))

  (setf x 3)
  (setf iters 0)

  (tagbody loop_2
     (setf iters (+ iters 1))
     (if (= (/ n x) (truncate (/ n x)))
        (progn
          (format t "~a " x)
          (setf n (/ n x)))
        ;; Increase x by 2 since all primes are odd, except 2 of course
        (setf x (+ x 2)))
     ;; Give up after 500,000 iterations, or when the remaining factor is 1
     (if (and (< iters 500000) (> n 1.0)) (go loop_2)))

)
   