Using trace to display the procedure in a racket

I worked on the last exercises ch 1 from SICP, where some exercises use higher order functions. I am currently trying to debug the problem in my solution to 1.45, which increases the arity mismatch. The function that raises the error is the result of double applying the averaging operation to solve the fixed point function.

This would make my debugging efforts easier if I could just reset some view of the procedures, given that the procedure was started by several other procedures that modify it before it causes an error. I looked through the debugging documentation for DrRacket, added (require racket/trace)it (require errortrace)to my module, and I think that I am familiar with all the functions of the debugging system - but I still don’t know how to do it,

The answer for DrRacket would be perfect, but anything can help.

+4
source share
2 answers

( racket/trace) - . (trace function-name), ( ) , .

(define sum (λ (x y) (+ x y)))
(define multiply
  (λ (x y)
    (multiply-aux x y x)
    ))
(define multiply-aux (λ (x y res) 
                       (if (= y 0) 0 
                           (if (= y 1) res 
                               (multiply-aux x (- y 1) (sum res x))))))
(require racket/trace)
(trace sum)

:

> (multiply 4 5)
>(sum 4 4)
<8
>(sum 8 4)
<12
>(sum 12 4)

DrRacket 6.0.1

, .

+5

. , -, , :

( ) ( * + +)

* + , , +, .

+1

Source: https://habr.com/ru/post/1544621/


All Articles