4

This refuses to compile. Commenting out the (setf roll line lets it compile. However, (setf roll... itself evaluates correctly in the REPL.

Program:

;; loop n times
; sum up number of hits over value v
(defun num-hits (n v)
  (let 
     ((roll)
       (table))
    (setq table (make-hash-table))
    ;;until i == n
    (loop for i from 1 to n
      (setf roll (rolld6))
;     (if (nilp (view_hash table))
;         (oxuassign_hash table roll 1)
;       (assign_hash table (+ 1 (view_hash table roll))))
      )
    (+ (view_hash table 5) (view_hash table 6))))

Message:

*** - LOOP: illegal syntax near (SETF ROLL (ROLLD6)) in (LOOP FOR I FROM 1 TO N (SETF ROLL (ROLLD6)))

1 Answer 1

8

The loop macro requires "do" before the loop body. You have

(loop for i from 1 to n
   (stuff)

and you need

(loop for i from 1 to n do
   (stuff))
Sign up to request clarification or add additional context in comments.

Comments

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.