The following works as expected when evaluated, but throws an error when compiling.
(defun hashmap-to-hashtable (hashmap &key (keyfun #'identity) (valfun #'identity) (invert? nil) &allow-other-keys &rest rest) (let ((keyset (#"keySet" hashmap)) (table (apply 'make-hash-table (remf :invert? (remf :valfun (remf :keyfun rest)))))) (with-constant-signature ((iterator "iterator" t) (hasnext "hasNext") (next "next")) (loop with iterator = (iterator keyset) while (hasNext iterator) for item = (next iterator) do (if invert? (setf (gethash (funcall valfun (#"get" hashmap item)) table) (funcall keyfun item)) (setf (gethash (funcall keyfun item) table) (funcall valfun (#"get" hashmap item))))) table)))
-> Error
&REST/&BODY must be followed by a variable. [Condition of type PROGRAM-ERROR]
Restarts: 0: [ABORT] Abort compilation. 1: [ABORT] Return to SLIME's top level. 2: [ABORT] Abort thread.
Backtrace: 0: (SYSTEM:MAKE-CLOSURE (LAMBDA (#:G29656 &KEY (# NIL #:G29659) (# NIL #:G29661) (# NIL) &ALLOW-OTHER-KEYS ...) NIL) NIL) 1: (JVM::P1-COMPILAND #S(JVM::COMPILAND :NAME HASHMAP-TO-HASHTABLE :LAMBDA-EXPRESSION (LAMBDA (#1=#:G29656 &KEY ((:KEYFUN #:G29658) NIL #:G29659) ((:VALFUN #:G29660) NIL #:G29661) ((:INVERT? #2=#:G29662).. 2: (JVM::P1-FUNCTION #'(SYSTEM:NAMED-LAMBDA HASHMAP-TO-HASHTABLE (HASHMAP &KEY (KEYFUN #'IDENTITY) (VALFUN #'IDENTITY) (INVERT? NIL) &ALLOW-OTHER-KEYS ...) (BLOCK HASHMAP-TO-HASHTABLE (LET # #)))) 3: (JVM::P1 #'(SYSTEM:NAMED-LAMBDA HASHMAP-TO-HASHTABLE (HASHMAP &KEY (KEYFUN #'IDENTITY) (VALFUN #'IDENTITY) (INVERT? NIL) &ALLOW-OTHER-KEYS ...) (BLOCK HASHMAP-TO-HASHTABLE (LET # #)))) Locals: "??" = "??" 4: (JVM::P1 (SYSTEM:NAMED-LAMBDA HASHMAP-TO-HASHTABLE (HASHMAP &KEY (KEYFUN #'IDENTITY) (VALFUN #'IDENTITY) (INVERT? NIL) &ALLOW-OTHER-KEYS ...) (BLOCK HASHMAP-TO-HASHTABLE (LET # #)))) 5: (JVM::P1-LET*-VARS #S(JVM::LET/LET*-NODE :FORM NIL :COMPILAND #S(JVM::COMPILAND :NAME NIL :LAMBDA-EXPRESSION (LAMBDA NIL (SYSTEM:%DEFUN 'HASHMAP-TO-HASHTABLE (SYSTEM:NAMED-LAMBDA HASHMAP-TO-HASHTABLE .. 6: (JVM::P1-LET/LET* (LET* ((#:G29655 #)) (SYSTEM:%DEFUN 'HASHMAP-TO-HASHTABLE #:G29655))) 7: (JVM::P1 (LET* ((#:G29655 #)) (SYSTEM:%DEFUN 'HASHMAP-TO-HASHTABLE #:G29655))) 8: (JVM::P1-FUNCTION-CALL (SYSTEM:%DEFUN 'HASHMAP-TO-HASHTABLE (SYSTEM:NAMED-LAMBDA HASHMAP-TO-HASHTABLE (HASHMAP &KEY # # # &ALLOW-OTHER-KEYS ...) (BLOCK HASHMAP-TO-HASHTABLE #)))) 9: (JVM::P1-BODY ((SYSTEM:%DEFUN 'HASHMAP-TO-HASHTABLE (SYSTEM:NAMED-LAMBDA HASHMAP-TO-HASHTABLE # #)))) 10: (#<FUNCTION {79F502}>) 11: (#<FUNCTION {C49395}>) 12: (#<FUNCTION {E4ED69}> NIL (LAMBDA NIL (DEFUN HASHMAP-TO-HASHTABLE (HASHMAP &KEY # # # &ALLOW-OTHER-KEYS ...) (LET # #)))) 13: (#<FUNCTION (LAMBDA ()) {B5506C}>) 14: (JRUN-EXCEPTION-PROTECTED #<FUNCTION (LAMBDA ()) {B5506C}>) 15: ((FLET SWANK-BACKEND:SWANK-COMPILE-STRING) "(defun hashmap-to-hashtable (hashmap &key (keyfun #'identity) (valfun #'identity) (invert? nil) &allow-other-keys &rest rest) (let ((keyset (#"..