Is there any convenient way to print the return value of a procedure in Racket? For example, (define (test exp)
(match exp
[(...) some-value-1]
[(...) some-value-2]
[(...) some-value-3]))
What I want to do is to embed some debugging printf
in the test
, something like: (define (test exp)
(begin0
(match exp
[(...) some-value-1]
[(...) some-value-2]
[(...) some-value-3])
(printf "test return ~v\n" *last-value*) ; <-- *last-value* needed
))
Current workaround is using let
, but not convenient: (define (test exp)
((let ((result (match exp
[(...) some-value-1]
[(...) some-value-2]
[(...) some-value-3])))
(printf "test return ~v\n" result)
result)))
Thanks.
I never knew about (require debug). I never wrote code that didn’t have bugs. Now that I have been given an umbrella, perhaps the rain will stop.
@samth I just installed mischief. Do you mean to define the test
procedure by define/debug
? It works, thanks. Although it will print many wordy log messages and slow…
You can also write (debug test e)
if you care about a particular call-site.
But, printing lots of log messages is precisely what you’re asking for.
@samth It’s useful, thanks.
BTW, It would be nice, if some log messages could be reduced. For example, from #;>> function:
#;>> contract
#;>> [e:\......\xxxxxx.rkt:9.15]
#; ! Argument redex: '(redex (* (* 1 2) (* 3 (* 4 0))))
#; ! Result: '(* 1 (* 2 (* 3 (* 4 0))))
to #;>> function: contract
#; ! Argument redex: '(redex (* (* 1 2) (* 3 (* 4 0))))
#; ! Result: '(* 1 (* 2 (* 3 (* 4 0))))
I have tagged the conract
procedure by define/debug
, so there is no need to tell me where this file is.
once i set a label
on a message%
as for example a string
can i not set it to a bitmap%
?
Yes, that’s correct
If you think mischief is too heavy, you can use https://docs.racket-lang.org/debug/ instead
Just insert #R
in front of (match ...
, and you will be able to trace the value produced by the expression.