philip.mcgrath
2018-9-5 19:17:34

@dthien As @lexi.lambda mentioned, there’s a readtable extension mechanism that can do this. Here’s the introduction from the guide: http://docs.racket-lang.org/guide/hash-reader.html#(part._readtable)


soegaard2
2018-9-5 19:19:54

@dthien If <decimal>*[.<decimal>*] is the only number format you want, I think the easiest is to write your own read-decimal-number that first reads in a string, then calls string->number.


soegaard2
2018-9-5 19:20:12

The standard reader will accept numbers like 1##4 etc.


soegaard2
2018-9-5 19:20:32

(evaluates to 1004 fwiw)


philip.mcgrath
2018-9-5 19:35:48

Once you’ve implemented my-read-number, extending read-syntax is as easy as: (define my-readtable (apply make-readtable (current-readtable) (for/fold ([lst null]) ([d (in-string "0123456789")]) (list* d 'non-terminating-macro my-read-number lst)))) (parameterize ([current-readtable my-readtable]) (read-syntax ...))


dthien
2018-9-5 19:49:11

Thanks all for the help!


blerner
2018-9-5 20:04:08

Quick pict question: I’ve constructed an image using a bitmap and a pin-over, roughly as follows: (pin-over (bitmap "foobar.png") x y (a-translucent-filled-flash-pict)). My resulting image has 2x the dimensions of the original PNG image, as if it’s being rendered in hi-dpi or something. I’m curious, how can I avoid this expansion factor?


blerner
2018-9-5 20:05:21

I looked at the current-expected-text-scale, but it returns (1 1), so I don’t think that’s the multiplier I’m seeing


samth
2018-9-5 21:07:00

what are the dimensions of the flash?


blerner
2018-9-5 21:43:11

Smaller than the png, by a lot. (The png is 1368x764, or whatever that typical screen size is, and the flash is 90x50)


blerner
2018-9-5 21:44:55

I don’t absolutely need to use pict here; I could use 2hdtp/image instead. But it was easier to find the shapes I wanted in pict…


samth
2018-9-5 22:33:06

@blerner this program produces the same answer for both for me: #lang racket (require pict pict/flash) (define x 100) (define y 100) (define c (bitmap "cilk.png")) (define v (pin-over c x y (filled-flash 50 50))) (pict-width c) (pict-width v)


samth
2018-9-5 22:33:31

do you have a hi-DPI screen?


mccrae.f
2018-9-6 00:27:46

@mccrae.f has joined the channel


blerner
2018-9-6 01:27:49

@samth yes, I do. I was surprised by this behavior because when I use 2htdp/image (in other scribble documents), I don’t ever see hidpi scaling.


samth
2018-9-6 01:28:22

what’s the pict-width of the various components?


samth
2018-9-6 01:28:44

also this is almost certainly a bug in racket/draw


samth
2018-9-6 01:29:10

unless the issues are not apparently until you display the image in which case the bug is in racket/gui


blerner
2018-9-6 01:29:35

I’ll check in a moment (an not on that computer yet). And it seems odd to me, in the sense of nondeterministic builds, that such an environmental feature could be incorporated from the same command line invocation


blerner
2018-9-6 01:29:48

No, I’m generating HTML and loading it in a browser


blerner
2018-9-6 01:30:05

Not using drr for this at all


samth
2018-9-6 01:30:09

ah


samth
2018-9-6 01:30:41

then that makes it seem like the bug is in racket/draw


blerner
2018-9-6 01:35:55

The dimensions of the png according to pict-width and pict-height are 1366x728. The dimensions of the flash are 75.0x30.83017… The dimensions of the final pin-over are 1366x728.


blerner
2018-9-6 01:37:04

The dimensions of the final pict#.png are 2744x1468


blerner
2018-9-6 01:37:58

which are just slightly bigger than 2x the original png


samth
2018-9-6 01:38:06

can you convert the pict to png manually (not using scribble, instead using convert) and see if it’s the same result?


blerner
2018-9-6 01:38:18

? using the command line utility?


blerner
2018-9-6 01:38:30

or is convert a Racket function too?


samth
2018-9-6 01:38:40

no, using the convert function from file/convertible


blerner
2018-9-6 01:38:46

ok, lemme try that


samth
2018-9-6 01:39:06

my guess is that something is calling convert with png@2x-bytes


blerner
2018-9-6 01:42:37

once I call convert with ’png-bytes, how do I dump that into a file from within my scribble doc? (I don’t want to figure out how to extract this to a standalone file yet, not least because I don’t want to vary the scribble environment to a racket one and change two variables at once)


samth
2018-9-6 01:43:08

@blerner I explicitly want to try the minimal reproduction, ie a racket environment


blerner
2018-9-6 01:43:29

ah, ok. that’ll take me a bit. hold, please…


samth
2018-9-6 01:43:36

my guess is that you get exactly the results you’re seeing if you use convert with png@2x-bytes


blerner
2018-9-6 01:48:05

Is there an easy way, once I’ve got the png-bytes and png@2x-bytes, to examine their width and height from DrR, or do I need to save them to files and look at them in a browser?


samth
2018-9-6 01:48:49

you can just do bytes-length


samth
2018-9-6 01:48:57

but not really


samth
2018-9-6 01:49:18

you could convert them to a bitmap somehow


samth
2018-9-6 01:49:29

i recommend saving them to a file


blerner
2018-9-6 01:50:28

Is there a bytes->file counterpart to file->bytes?


samth
2018-9-6 01:50:36

write-to-file


blerner
2018-9-6 01:55:41

close; that seems to write it out as a string. but I tried with-output-to-file/write-bytes, and that combo seems to suffice… anyway: the result of (convert the-pict 'png-bytes) has dimensions 1366x728. The result with 'png@2x-bytes has dimensions 2732x1456 — exactly double, and not identical to the results from scribble


blerner
2018-9-6 01:56:13

(It appears scribble stuck a few pixels of transparent border around the image, I don’t know why)


blerner
2018-9-6 02:04:27

(then scribble explicitly sets a margin of –3px all around the image, and explicitly sets its width and height to 1372x734, so the browser scales the image back down to the size it “should” be)


blerner
2018-9-6 02:45:41

ISTM that the png@2x-bytes is coming from current-render-convertible-requests, and maybe picts know how to respond to the 2x request, but 2htdp/images don’t, and that’s why the latter happen to work out “as expected”, but picts show up doubled? (I don’t grep png@2x-bytes anywhere near files that seem related to 2htdp/image, but I do see png-bytes in gui-lib/mrlib/image-core.)


gregor.kiczales
2018-9-6 04:57:17

We are using the handin server together with some of our own design recipe checking material. We are running into a very strange problem with the sandbox evaluator. In the sandbox evaluator the following expressions don’t all produce true.


gregor.kiczales
2018-9-6 04:57:57

(equal? (* 3 3.3) 9.9) ; produces false


gregor.kiczales
2018-9-6 04:58:11

(= (* 3 3.3) 9.9) ; produces false


gregor.kiczales
2018-9-6 04:58:30

(=~ (* 3 3.3) 9.9 .001) ;produces true


gregor.kiczales
2018-9-6 04:59:43

The handin server creates the evaluator with a byte-stream, and the documentation talks about it expecting to get any additional code to evaluate in that same form. Which made me think perhaps there was a printing/reading thing going on here. But I can’t see in the code where that would be happening.


gregor.kiczales
2018-9-6 04:59:45

Any ideas?


mark.warren
2018-9-6 06:37:49

@gregor.kiczales If you just do the calculation (* 3 3.3) you can see you get 9.899999999999999 which is not equal to 9.9 which I think is why the first fails. The same goes for the second, and the third is true because it checks that the numbers are within a range of each other 0.001 of each other in this case (which the numbers are)