0

I'm implementing a Tetris game in Lisp (Common Lisp), a language I'm not familiarized with, and I've come up with an error which I don't really understand why it's happening.

(defun tabuleiro-remove-linha! (tabuleiro linha)
    (let ((coluna 0))
        (if (equal linha 17)
            ((loop while (<= coluna 9) do(setf (aref tabuleiro linha coluna) nil)))
            ((loop while (<= coluna 9) do((setf (aref tabuleiro linha coluna) (aref tabuleiro (+ linha 1) coluna)))
             (tabuleiro-remove-linha! tabuleiro (+ linha 1)))))))

It's showing:

TABULEIRO-REMOVE-LINHA! in lines 51..56 : Not the name of a function:
     (LOOP WHILE (<= COLUNA 9) DO (SETF (AREF TABULEIRO LINHA COLUNA) NIL))
If you continue (by typing 'continue'): Ignore the error and proceed

Any clues? I have searched and both loop and while exist in CLISP. My CLISP is 2.49. Thanks in advance.

2 Answers 2

4

So if you have a function like + and put parentheses around with some operands like (+ 2 3) lisp applies operator + with 2 and 3 as arguments.

In you code you have:

((loop while (<= coluna 9) do(setf (aref tabuleiro linha coluna) nil)))

which means the operand is (loop while (<= coluna 9) do(setf (aref tabuleiro linha coluna) nil)) and you have no arguments. Common Lisp points out that this is neither a symbol, like +, nor a anonymous function like (lambda (x) (+ x x)). Thus (loop while (<= coluna 9) do(setf (aref tabuleiro linha coluna) nil)) is an invalid function.

It could happen you are using parentheses as decoration but it is the same as putting extra parentheses after statements in C family languages. eg. floor(5)() have the same effect.

Grouping staements in blocks, like with {curlies} in C family languages are done with (progn ...) in Common Lisp. The last expression to be evaluated is the "return"

(loop while (<= coluna 9) do(setf (aref tabuleiro linha coluna) nil)) is the same as:

while( coluna <= 9 )
   tabuleiro[linha][coluna] = null;

So when you remove the excess parentheses you are left with several infinite loops since coluna and linha never change. loop does support iterating like (loop :for var :from 3 :to 10 :collect var) ; ==> (3 4 5 6 7 8 9 10)

Sign up to request clarification or add additional context in comments.

1 Comment

Got it! Thank you for the explanation :)
3
((loop while ...

That's one pair of parentheses too much around your loop forms. This way the evaluator searches for a function named (loop while ... which it obviously won't find.

This happens another time later in your code, too.

You should also consider formatting your code with line breaks and correct indentation to highlight its underlying structure. Lastly there's a lot of assumptions hardcoded ... not a very "lispy" looking function.

1 Comment

Thanks! Yeah it doesn't really seem very "lispy"... shame, I really enjoy all these Artificial Intelligence problems, but the AI masters really love Prolog, LISP and all those creepy functional programming languages and that concept is yet to be fully clear to me...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.