Thanks for the help to my specific problem. More generally, what should have clued me in to a contract or type error when the only message received had to do with y plot bounds? Just looking for practical advice to help me figure out things on my own going forward.
On Tuesday, June 15, 2021 at 9:46:37 AM UTC-4 Ben Greenman wrote: > On 6/15/21, Britt Anderson <britt.u...@gmail.com> wrote: > > > > I was starting to explore plot and I am getting a behavior I do not > > understand. plot doesn't seem to be able to figure out the bounds for > > something that seems pretty straight-forward. When I give bounds as an > > optional argument I don't see the line I expect to see. Can anyone > provide > > me some pointers? I feel like I am just missing something conceptually > and > > would appreciate some guidance. Here is some minimal code to demonstrate > > the problem. I get a plot square, but no line, and I can demonstrate that > > the function generates reasonable numbers for this range of inputs. > > > > > > > > #lang racket > > (require plot) > > (require math/distributions) > > > > (define (norm-prior mu) > > (lambda (sd) > > (lambda (ind) > > (* ind (flnormal-pdf mu sd ind #f))))) > > > > (define d ((norm-prior 0.5) 0.1)) > > > > (plot (function d 0 1 #:y-min 0.0 #:y-max 2.0 #:samples 100)) > > > > (map d (range 0.0 1.0 0.01)) > > > > This is tricky. > > Plot is calling your function `d` with inputs like 0, 1/99, and 1. All > of those give contract errors --- try (d 0) for yourself. > > But when a plot function throws an error, the library ignores the > problem & keeps trying to draw a picture. > > To fix, I'd change `norm-prior` to make a flonum: > > (define (norm-prior mu) > (lambda (sd) > (lambda (ind) > (* ind (flnormal-pdf mu sd (exact->inexact ind) #f))))) > > [[ Maybe plot should check if a function renderer produces no output > and throw an error then. ]] > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/8021ed6d-f5f2-4279-9481-ad66eab9e762n%40googlegroups.com.