4

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!

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Juanito Fatas
  • 9,419
  • 9
  • 46
  • 70
  • 1
    "It is technically permissible for a conforming implementation to take no action at all other than normal execution of the form. In such a situation, (step form) is equivalent to, for example, (let () form). In implementations where this is the case, the associated documentation should mention that fact." ([CLHS](http://www.lispworks.com/documentation/HyperSpec/Body/m_step.htm#step)) I have no idea, whether Clozure resorts to this "solution"... – Dirk Feb 23 '12 at 14:34
  • here's a relevant question regarding SBCL: http://stackoverflow.com/questions/8617064/a-simple-example-of-using-the-stepper-in-sbcl – Vsevolod Dyomkin Feb 23 '12 at 15:06

5 Answers5

5

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

informatimago
  • 147
  • 1
  • 4
  • It is now at framagit: https://framagit.org/com-informatimago/com-informatimago (with the issues list) there's also a mirror at gitlab: https://gitlab.com/com-informatimago/com-informatimago and anotherw one at github: https://github.com/informatimago/lisp – informatimago Oct 20 '20 at 17:10
4

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.

Community
  • 1
  • 1
Juanito Fatas
  • 9,419
  • 9
  • 46
  • 70
  • Thank you so much, I never thought I would be able to find the link again, as I had bookmarked it on a previous computer that crashed. This is exactly the solution on how to trace in CCL. Thank you so much and for the Debug With OpenMCL link. – Jason Robinson May 01 '22 at 02:46
3

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.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
  • 4
    A quick look at the source confirms that. From ccl:lib;macros.lisp: (defmacro step "…" (form) form). – danlei Feb 23 '12 at 20:23
1

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

lucaregini
  • 21
  • 3
0

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))