Hello all,
I am having trouble understanding the behavior of a bit of code I wrote:
(defun get-name ()
(let ((f nil) (l nil))
(setq f (get-firstname))
(setq l (get-lastname))
(terpri)
(princ "You entered: ")
(princ f)
(princ " ")
(princ l)
(terpri)
(cons f (list l))
)
)
(defun get-firstname ()
(princ "Enter first name:")
(read-line)
)
(defun get-lastname ()
(princ "Enter last name:")
(read-line)
)
Nothig too complicated here (I hope), but when I test it I get the following
results:
CL-USER 26 : 2 > (get-name)
Enter first name:z
Enter last name:a
You entered: z
("z" "")
CL-USER 27 : 2 > (get-name)
Enter first name:asdf
Enter last name:z
You entered: asdf z
("asdf" "z")
CL-USER 28 : 2 > (get-name)
Enter first name:z
Enter last name:asdf
You entered: z df
("z" "df")
CL-USER 29 : 2 > (get-name)
Enter first name:zxcv
Enter last name:asdf
You entered: zxcv
("zxcv" "")
So, sometimes it works (as in the case for CL-USER 27) but ususally is
screws up. It seems to always get the first name correct, but not the last.
Can anyone explain the odd behavior?
Thanks,
Pat Summers
Patrick Summers wrote:
> So, sometimes it works (as in the case for CL-USER 27) but ususally is
> screws up. It seems to always get the first name correct, but not the last.
>
> Can anyone explain the odd behavior?
Your code, though not pretty, works for me with both Lispworks 4.1.17 and
ACL 5.0 Lite. And I don't see any reason why it shouldn't work.
Maybe there's something weird going on with your input stream?
Or are you working with a non-Common Lisp?