I am trying to learn Common Lisp with the book Common Lisp: A gentle introduction to Symbolic Computation. In addition, I am using SBCL, Emacs, and Slime.
In the advanced section of chapter 7, the author suggests the use of the trace function. This is definetly a really valuable tool. I was glad to see it working.
However, apparently, my tool does not work fully as the one presented by the author.
After doing the following definition:
(defun find-first-odd (x)
(find-if #’oddp x))
And running on the REPL:
> (dtrace find-first-odd oddp)
He gets:
> (find-first-odd ’(2 4 6 7 8))
----Enter FIND-FIRST-ODD
| X = (2 4 6 7 8)
| ----Enter ODDP
| | NUMBER = 2
| \--ODDP returned NIL
| ----Enter ODDP
| | NUMBER = 4
| \--ODDP returned NIL
| ----Enter ODDP
| | NUMBER = 6
| \--ODDP returned NIL
| ----Enter ODDP
| | NUMBER = 7
| \--ODDP returned T
\--FIND-FIRST-ODD returned 7
7
On my environment, using the same definition:
(defun find-first-odd (x)
(find-if #’oddp x))
And doing the trace (with a sanity check):
CL-USER> (trace)
NIL
CL-USER> (trace find-first-odd oddp)
(FIND-FIRST-ODD ODDP)
I get:
CL-USER> (find-first-odd '(2 4 6 7 8))
0: (FIND-FIRST-ODD (2 4 6 7 8))
0: FIND-FIRST-ODD returned 7
This seems awkward since the (trace) evaluation indicates the inclusion of the odd predicate. However, after the function call it does not appear as a traced operation.
In another example in which both of my functions were definied by me and no primitive such as oddp predicate were involved, it worked perfectly:
(defun half (n) (* n 0.5))
(defun average (x y)
(+ (half x) (half y)))
CL-USER> (trace half average)
(HALF AVERAGE)
CL-USER> (average 3 7)
0: (AVERAGE 3 7)
1: (HALF 3)
1: HALF returned 1.5
1: (HALF 7)
1: HALF returned 3.5
0: AVERAGE returned 5.0
5.0
Is there a way to solve this?