From: ·····@stevedurkin.net
Subject: Emacs Lisp print error
Date: 
Message-ID: <1140184757.330104.256890@g14g2000cwa.googlegroups.com>
Can anyone tell me why the following line generates an error (but still
prints the correct output!)?  It's a simple finite automata simulator;
str is a list of integers (ASCII values); and the following line occurs
when the recursive FA function encounters a character from outside of
the alphabet {a, b} (or {97, 98} if you prefer):

(princ (format "%s unrecognized input\nrejected\n" (char-to-string (car
str))) lisp-out)


Wrong type argument: integer-or-marker-p, "y unrecognized
input^Jrejected^J"


Here is the whole program if necessary:


;Assignment: Finite Automata Simulator


(cond ((get-buffer "*lisp-out*") (kill-buffer "*lisp-out*")))
(setq lisp-out (get-buffer-create "*lisp-out*"))

(defun FA (str)
 (cond
  ((null str) state)
  ((equal (car str) 97)
   (cond
     ((equal state 1) (setq state 3))
     ((equal state 2) (setq state 4))
     ((equal state 3) (setq state 4))
     ((equal state 4) (setq state 5))
     ((equal state 5) (setq state 2))
   )
   (princ (format "a - > State %d\n" state) lisp-out)
   (setq i (+ i 1))
   (FA (cdr str))
  )
  ((equal (car str) 98)
   (cond
     ((equal state 1) (setq state 5))
     ((equal state 2) (setq state 1))
     ((equal state 3) (setq state 2))
     ((equal state 4) (setq state 4))
     ((equal state 5) (setq state 3))
   )
   (princ (format "b - > State %d\n" state) lisp-out)
   (setq i (+ i 1))
   (FA (cdr str))
  )
  (t (princ (format "%s unrecognized input\nrejected\n" (char-to-string

(car str))) lisp-out))
 )
)

(defun accept (state)
  (cond
   ((equal (% state 2) 1) 't)
   (t 'f)
  )
)

(setq keepgoing 't)
(while keepgoing
  (setq s (read-string "String:  "))
  (princ (format "String:  %s\n" s) lisp-out)
  (setq s (mapcar 'identity s))
  (cond
   ((equal s '(101 110 100))
     (princ (format "bye\n") lisp-out)
     (setq keepgoing nil)
   )
   (t (princ (format "Start State 1\n") lisp-out)
      (setq state 1)
      (setq i 0)
      (cond
       ((accept (FA s)) (princ (format "accepted\n") lisp-out))
       (t (princ (format "rejected\n") lisp-out))
      ) 
    ) 
  ) 
)