2016-11-17 109 views
2

我試圖使用guile函數跟蹤,但每次我都會得到一個可能的未綁定變量。未綁定變量'trace'

[email protected](guile-user)> (define (fact1 n) 
(if (zero? n) 1 
(* n (fact1 (- n 1))))) 
[email protected](guile-user)> (trace fact1) 
;;; <stdin>:4:0: warning: possibly unbound variable `trace' 
<unnamed port>:4:0: In procedure #<procedure 10e4080c0 at <current input>:4:0()>: 
<unnamed port>:4:0: In procedure module-lookup: Unbound variable: trace 

Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. 
[email protected](guile-user) [1]> 

我想知道如果有人知道爲什麼這不起作用。

+0

狡詐沒有一個'默認包含trace'功能。看起來,['(冰-9調試)'](https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Tracing.html)模塊包括一個,但。你在哪裏看到一些讓你相信'trace'會在Guile中工作的東西? –

+0

我的導師給了我們這個例子來解決問題。 – AmaCode

+0

好的,你可能需要使用'(use-modules(ice-9 debug))'來首先導入'trace'。 –

回答

2

使用,trace

GNU Guile 2.0.12 
Copyright (C) 1995-2016 Free Software Foundation, Inc. 

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. 
This program is free software, and you are welcome to redistribute it 
under certain conditions; type `,show c' for details. 

Enter `,help' for help. 
[email protected](guile-user)> (define (fact1 n) 
... (if (zero? n) 1 
... (* n (fact1 (- n 1))))) 
[email protected](guile-user)> ,trace (fact1 5) 
trace: | (#<procedure 110221480> #(#<directory (guile-user) 10f9fabd0> #f)) 
trace: | #(#<directory (guile-user) 10f9fabd0> fact1) 
trace: (#<procedure 11022e1e0 at <current input>:2:0()>) 
trace: (fact1 5) 
trace: | (fact1 4) 
trace: | | (fact1 3) 
trace: | | | (fact1 2) 
trace: | | | | (fact1 1) 
trace: | | | | | (fact1 0) 
trace: | | | | | 1 
trace: | | | | 1 
trace: | | | 2 
trace: | | 6 
trace: | 24 
trace: 120