chansey97
2020-11-25 17:56:43

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.



gknauth
2020-11-25 18:05:37

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.


chansey97
2020-11-25 18:13:02

@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…


samth
2020-11-25 18:14:28

You can also write (debug test e) if you care about a particular call-site.


samth
2020-11-25 18:14:58

But, printing lots of log messages is precisely what you’re asking for.


chansey97
2020-11-25 18:29:54

@samth It’s useful, thanks.


chansey97
2020-11-25 18:29:58

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.


cris2000.espinoza677
2020-11-25 23:13:29

once i set a label on a message% as for example a string can i not set it to a bitmap% ?


samth
2020-11-26 01:32:42

Yes, that’s correct


sorawee
2020-11-26 02:22:41

If you think mischief is too heavy, you can use https://docs.racket-lang.org/debug/ instead


sorawee
2020-11-26 02:23:42

Just insert #R in front of (match ..., and you will be able to trace the value produced by the expression.