Syntax error in general Lisp Loop mode

It refuses to compile. Commenting out a string (setf roll allows you to compile it. However, (setf roll... itself correctly evaluates REPL.

Program:

 ;; loop n times ; sum up number of hits over value v (defun num-hits (nv) (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))) 
+4
source share
1 answer

The loop macro requires a “do” in front of the loop body. You

 (loop for i from 1 to n (stuff) 

and you need

 (loop for i from 1 to n do (stuff)) 
+8
source

Source: https://habr.com/ru/post/1301939/


All Articles