NOTE:
I've closed this question because it turns out that there was nothing wrong with my program that should have caused it to behave as it did, and it was likely a compiler bug or something.
I'm also now using the style that John recommended, it looks much nicer than the code I posted here.
- - -- --- ----- -------- -------------
I've just started playing around with Lisp, and have been using Project Euler as a source of simple activities to practice with. I'm currently working on problem 4:
Find the largest palindrome made from the product of two 3-digit numbers.
I've completed code that should complete the task as requested, but whenever I run it (using the Steel Bank Common Lisp compiler) my computer starts to hang. Here's my code.
(defun isPalindromic (n)
(let
((stringed (format nil "~D" n)))
(string= stringed (reverse stringed))))
(defun euler004 ()
(let
((start 100) ; all 3-digit numbers...
(limit 999) ; fall within this range
(largest 0))
(do
((x start (1+ x)))
((> x limit))
(do
((y start (1+ y)))
((> y limit))
(let
((product (* x y)))
(if
(and
(> product largest) ; cheap?
(isPalindromic product)) ; expensive?
(setq largest product)))))
(return-from euler004 largest)))
(print (euler004))
If anyone could help me find the problem I would appreciate it. I would also appreciate any remarks you might have regarding style or best practices for Lisp code as I am largely uninformed about them and have probably made some fairly terrible mistakes.
Thank you.