STEP macro does not work in Clozure CL

落花浮王杯 提交于 2020-01-03 15:56:07

问题


I want to use a step function to see how it went to the expected output, but it's not working.

Like this simple example:

(STEP (IF (ODDP 3) 'YES 'NO))

but nothing happens.

Is there any optimization that makes me can't see the trace steps ???

How to turn it off?

Thanks!


回答1:


I don't think Clozure CL supports stepping. IIRC nobody has funded this feature yet. It would need some work, since Clozure CL lacks an interpreter (where stepping could be supported relatively painless).

Other implementations support stepping.




回答2:


It's because CL:STEP is not implemented on CCL that I implemented com.informatimago.common-lisp.lisp.stepper. You can get it with quicklisp. The documentation is at: https://gitorious.org/com-informatimago/com-informatimago/source/2b53ae44e8fa4d040fafcf4d93976500a8e464dc:common-lisp/lisp/stepper-packages.lisp#L146




回答3:


STEP is not supported in CCL.

Solution for TRACE:

When a (globally named) function FOO is defined with DEFUN, the compiler is allowed to assume that functional references to that function name refer to the function being defined (unless they're lexically shadowed); it can therefore skip the implicit SYMBOL-FUNCTION ("call whatever is in the function cell of FOO") on a self-call (a call to FOO from within FOO.) This saves an instruction or two on those calls, but (since TRACE works by changing what SYMBOL-FUNCTION returns) those inlined self-calls can't be traced.

However, the compiler can't do this (can't even assume that something defined by DEFUN won't be redefined later) if the function name is declared NOTINLINE at the point of the self call:

example:

? (defun fact (x acc)
    (declare (notinline fact))
    (if (= x 0)
        acc
        (fact (- x 1) (* x acc))))

? (trace fact)
NIL

? (fact 3 1)
0> Calling (FACT 3 1) 
 1> Calling (FACT 2 3) 
  2> Calling (FACT 1 6) 
   3> Calling (FACT 0 6) 
   <3 FACT returned 6
  <2 FACT returned 6
 <1 FACT returned 6
<0 FACT returned 6

? (step (fact 3 1))
0> Calling (FACT 3 1) 
 1> Calling (FACT 2 3) 
  2> Calling (FACT 1 6) 
   3> Calling (FACT 0 6) 
   <3 FACT returned 6
  <2 FACT returned 6
 <1 FACT returned 6
<0 FACT returned 6

That's the way to say to the compiler, "as a matter of policy, I'd rather have the ability to trace functions which call themselves and are defined with DEFUN and don't care about saving a few cycles per self-call".

from: DebugWithOpenMCL

or Evaluate the following form:

(DECLAIM (OPTIMIZE (DEBUG 3)))

before defining any function to be traced.




回答4:


This library is not distributed on quicklisp anymore however it builds successfully when installed as a local quicklisp project.




回答5:


use cl-stepper:step instead of cl-user:step , 'cause Clozure CL don't support it. if you have already installed quicklisp, try to install it : like this.

(ql:quickload "com.informatimago.common-lisp.lisp.stepper")

(defpackage :test (:use :cl-stepper))
(in-package :test)

(def bar (hoge)
;; define some function
)

(step (bar 3))


来源:https://stackoverflow.com/questions/9415000/step-macro-does-not-work-in-clozure-cl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!