Plain Lisp Error not understood

I am trying to write a series of guessing games in Lisp as a time-killing project. However, when I try to load a program using SBCL, I get the following error:

debugger invoked on a SB-C::INPUT-ERROR-IN-COMPILE-FILE in thread #<THREAD "initial thread" RUNNING {AA14959}>: READ failure in COMPILE-FILE at character 477: end of file on #<SB-SYS:FD-STREAM for "file /home/andy/Dropbox/Programming/Common Lisp/number-game.lisp" {B4F45F9}> Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL. restarts (invokable by number or by possibly-abbreviated name): 0: [CONTINUE] Ignore runtime option --load "number-game.lisp". 1: [ABORT ] Skip rest of --eval and --load options. 2: Skip to toplevel READ/EVAL/PRINT loop. 3: [QUIT ] Quit SBCL (calling #'QUIT, killing the process). (SB-C::READ-FOR-COMPILE-FILE #<SB-SYS:FD-STREAM for "file /home/andy/Dropbox/Programming/Common Lisp/number-game.lisp" {B4F45F9}> 477) 

What does this error mean? The code is as follows, and an error appears when loading a file and calling (play) from REPL:

 ;;;; number-game.lisp ;;;; ;;;; Andrew Levenson ;;;; 10/25/2010 ;;;; ;;;; Simple number guessing game. User has ;;;; five guesses to determine a number between ;;;; one and one hundred, inclusive (1-100). ;;; Set global variable for the target number: (defparameter *target* nil) ;;; Set the iterator so we may check the number of guesses (defparameter *number-of-guesses* 0) ;;; Welcome the user (defun welcome-user () (format t "Welcome to the number guessing game!~%")) ;;; Prompt for a guess (defun prompt-for-guess () (format t "Please enter your guess (1-100): ") (finish-output nil) ; nil directs finish-output to standard IO (check-guess((read-guess))) ;;; Read in a guess (defun read-guess () (let ((guess (read))) (if (numberp guess) ; If true, return guess. Else, call prompt-for-guess (progn (setq *number-of-guesses* (+ *number-of-guesses* 1)) guess) (prompt-for-guess)))) ;;; Check if the guess is higher than, lower than, or equal to, the target (defun check-guess (guess) (if (equal guess *target*) (equal-to) (if (> guess *target*) (greater-than (guess)) (if (< guess *target*) (less-than (guess)))))) ;;; If the guess is equal to the target, the game is over (defun equal-to () (format t "Congratulations! You have guessed the target number, ~a!~%" *target*) (y-or-np "Play again? [y/n] ")) ;;; If the guess is greater than the target, inform the player. (defun greater-than (guess) (format t "Sorry, ~a is greater than the target.~%" guess) (if (< *number-of-guesses* 6) (prompt-for-guess) (game-over))) ;;; If the guess is less than the target, inform the player. (defun less-than (guess) (format t "Sorry, ~a is less than the target.~%" guess) (if (< *number-of-guesses* 6) (prompt-for-guess) (game-over))) ;;; If the player has run out of guesses, give them the option ;;; of playing the game again. (defun game-over () (y-or-np "You have run out of guesses. Play again? [y/n] ")) ;;; Play the game (defun play () ;; If it their first time playing this session, ;; make sure to greet the user. (unless (> *number-of-guesses* 0) (welcome-user)) ;; Reset their remaining guesses (setq *number-of-guesses* 0) ;; Set the target value (setq *target* ;; Random can return float values, ;; so we must round the result to get ;; an integer value. (round ;; Add one to the result, because ;; (random 100) yields a number between ;; 0 and 99, whereas we want a number ;; from 1 to 100 inclusive. (+ (random 100) 1))) (if (equal (prompt-for-guess) "y") (play) (quit))) 

(Iโ€™m pretty sure that the program doesnโ€™t work minus one error, I'm still a newbie when it comes to Lisp. This is only the first error that I encountered, I understood it myself.)

Oh, and the problem is most likely related to the prompt-for-guess , read-guess and check-guess functions, because these are the ones I was messing with when this error occurred.

+6
lisp common-lisp sbcl
source share
3 answers

It looks like you haven't closed enough partners on your prompt-for-guess defun.

The reader gets to the end of the file and notices that it has an open form and cannot determine where it came from.

The easy way I use to find errors like this is for my text editor to backtrack from the region and make sure everything is arranged as it seems to me.

+6
source share

The command in Emacs is Mx check-parens (it checks everything that is needed for balance, for example, quotation marks). It can be a little mystifying if everything is balanced, because in this case it does nothing.

check-parentheses Command: check for unbalanced parentheses in the current buffer. More precisely, check the narrowed portion of the buffer for the unbalanced expression ("sexps") as a whole. This is done according to the current syntax table and unbalanced brackets or quotation marks will be found as appropriate. (See Info node `(emacs) Parentheses'.) If an imbalance is found, an error is signaled and the dot remains on the first unbalanced character.

+3
source share

end of file while reading, missing closing bracket (or similar). Character 477. Move the cursor in the text to 477 and check what expression it is.

Check your IDE for a command to find unbalanced expressions.

In LispWorks, this will be Mx Find Unbalanced Parentheses .

SLIME should also have some command.

+1
source share

All Articles