是否存在gensym在前缀中附加唯一数字的功能派上用场的情况?我不明白为什么会有gensym时
(let ((str "batman"))
(eq (make-symbol str)
(make-symbol str)))
Run Code Online (Sandbox Code Playgroud)
总是回来nil.
例如,GENSYM使调试生成的代码稍微容易一些.
例:
看到这个LOOP宏的扩展.您可以通过查看其名称来查看哪些符号相同,即使它们未在包中实现.有两个未处理的临时变量.不同的名称现在使用清楚.
CL-USER 4 > (pprint (macroexpand '(loop for i in '(1 2 3) sum i)))
(BLOCK NIL
(MACROLET ((LOOP-FINISH () '(GO #:|end-loop-1103|)))
(LET ((I NIL) (#:|tail-1106| '(1 2 3)) (#:|by-1107| 'SYSTEM:CDR$CONS))
(LET ((#:|accumulator-1104| 0))
(DECLARE (TYPE NUMBER #:|accumulator-1104|))
(TAGBODY
#:|begin-loop-1102| NIL
(PROGN
(WHEN (OR (ENDP #:|tail-1106|)) (GO #:|end-loop-1103|))
(LET ((#:|temp-1109| (FUNCALL #:|by-1107| #:|tail-1106|))
(#:|temp-1108| (SYSTEM:CAR$CONS #:|tail-1106|)))
(SETQ I #:|temp-1108|)
(SETQ #:|tail-1106| #:|temp-1109|)))
(INCF #:|accumulator-1104| I)
(GO #:|begin-loop-1102|)
#:|end-loop-1103| (RETURN-FROM NIL #:|accumulator-1104|))))))
Run Code Online (Sandbox Code Playgroud)