notjack
2021-2-16 08:13:24

the writer part would probably be implementable with something like that, but really the API should look like a simple function and it should be up to the #lang implementation whether to use something like parser-tools to implement that function


notjack
2021-2-16 08:14:15

this is on my mind lately because it’s the only way I can think of to get my resyntax project to work on non-s-exp languages


notjack
2021-2-16 08:15:12

speaking of which: made another attempt at a cleanup pull request! this time in the main racket repository https://github.com/racket/racket/pull/3689


laurent.orseau
2021-2-16 10:25:36

This is very nice!! I like how many case-lambda have been quite simplified.



notjack
2021-2-16 10:27:51

Seems maybe worth doing, but I’d rather invest my time in improving the let-to-define rules


notjack
2021-2-16 10:28:36

I’m considering restricting the rules to only fire when they eliminate let forms entirely, so that the pull requests I make with those rules are more obviously useful and require less review effort


soegaard2
2021-2-16 11:11:06

I wonder whether the original lambda was chosen in order to reduce the indentation?


notjack
2021-2-16 11:16:37

could have just formatted it like this instead then: (define (make-embedding-executable dest mred? verbose? ...) ...)


soegaard2
2021-2-16 11:17:23

True.


telepopsound
2021-2-16 14:13:01

@telepopsound has joined the channel


gknauth
2021-2-16 14:30:20

JavaScript floating point is IEEE–754. Is that true of Racket as well? I’ve been doing a lot of work with trigonometric functions lately and I get some different results depending on whether I’m using JavaScript or Racket. Unfortunately I only notice there’s a problem after a long chain of calculations. For example, if I’m calculating the great circle distance between two points just less than 100km apart, in one environment I might get 97.1km and in another 96.8km, using the same algorithm. This comes up in my test cases, so I’m trying to figure out where things start to diverge. I’ll have to explore what Racket’s test cases are for trigonometric functions, because I’m sure they exist. One difference is I use exact numbers when that makes sense in Racket, which is not part of JavaScript’s model, Racket’s numeric tower generally being more sophisticated. It’s one of those situations where I’m trying to figure out which system is right and where the results start to diverge and what should I do about it.


ryanc
2021-2-16 15:15:08

Out of curiosity, would using the the Chez version of call/cc to implement escaping be safe? That is, is it safe to use Chez call/cc to capture a continuation and invoke it if both happen in the same OS thread?


samth
2021-2-16 15:21:20

Yes, it is IEEE–754. Likely the difference is in various math functions, such as exp or sin, which are not specified in IEEE 754.


mflatt
2021-2-16 15:33:10

Yes, that should be safe. (It doesn’t even have to be the same OS thread.)


soegaard2
2021-2-16 15:40:06

@pavpanchekha A job for Herbie?


soegaard2
2021-2-16 15:40:18

ryanc
2021-2-16 15:44:15

Okay, thanks!


pavpanchekha
2021-2-16 16:06:33

Hi @gknauth I’m kinda the floating point guy around here. I would expect Racket’s answer to be, on average, a little more accurate, and can give you details if you want.


pavpanchekha
2021-2-16 16:07:10

Herbie, linked above, could help rewrite your computation into a generally more accurate form. Maybe! Let me know if it doesn’t work :slightly_smiling_face:


soegaard2
2021-2-16 16:56:34

@gknauth Also, check out https://docs.racket-lang.org/math/bigfloat.html It’s useful to figure which of the two implementations are most precise.


gknauth
2021-2-16 18:34:09

Thanks everyone. I’ll check all these things out. Basically I’ve been working from examples on this page https://www.movable-type.co.uk/scripts/latlong.html and this page https://www.movable-type.co.uk/scripts/latlong-vincenty.html and my results were slightly different. I also have lots of material from an expert just about everyone cites (John P. Snyder), but first order of business, I need my tests to be accurate so I can verify my computations are within promised ranges of accuracy. An interesting journey for sure. Thanks again.


gknauth
2021-2-16 18:38:20

Herbie looks awesome BTW.


pavpanchekha
2021-2-16 21:24:10

Thanks!


jestarray
2021-2-17 00:43:18

is there a way to get the line number of where the print statement is? similar to rusts dbg!() macro? I have lots of (println) statements littered everywhere and its a pain to find them


notjack
2021-2-17 00:44:45

@jestarray with macros, yes. there’s a few packages that add handy debugging macros, like the debug package


notjack
2021-2-17 00:45:58

to use it, change your #lang <whatever> to #lang debug <whatever>, then stick #R in front of expressions you want to see


notjack
2021-2-17 00:46:41

#lang debug racket/base (define x #R(+ 1 2 3)) prints out: (+ 1 2 3) = 6


notjack
2021-2-17 00:47:20

if you use #RR or #RRR instead of #R, you’ll get more information. #RR gives you line numbers: (+ 1 2 3) = 6 on line 2


notjack
2021-2-17 00:48:58

(to install, run raco pkg install --auto debug)


hazel
2021-2-17 02:42:38

oh this is great all my time with (define (dbg x) (pretty-print x) x)… a waste


dvanhorn
2021-2-17 02:46:08

I’ve noticed the following change moving from 7.9 CS to 8.0. The following program which uses the ffi, works when run from racket but I get “internal error: terminated in atomic mode!” when running raco test: ☞ cat entry.c void (*error_handler)(); void entry() { error_handler(); } ☞ cat small.rkt #lang racket (require ffi/unsafe) (define libt.so (ffi-lib "entry.so")) (define entry (get-ffi-obj 'entry libt.so (_fun -> _int64))) (set-ffi-obj! "error_handler" libt.so _pointer (function-ptr (λ () (raise 'err)) (_fun -> _void))) (with-handlers ((symbol? identity)) (entry)) ☞ gcc -c entry.c -o entry.o ☞ gcc -shared entry.o -o entry.so ☞ racket small.rkt 'err ☞ raco test small.rkt raco test: "small.rkt" 'err internal error: terminated in atomic mode!


mflatt
2021-2-17 02:47:53

Callbacks in Racket CS are always in atomic mode. That is indeed a difference compared to BC.


mflatt
2021-2-17 02:48:51

And an exception doesn’t end atomic mode.


dvanhorn
2021-2-17 02:48:56

But… this was working in 7.9 CS. Also why does raco test make a difference?


mflatt
2021-2-17 02:49:24

Yes, this did change since v7.9.


mflatt
2021-2-17 02:49:47

I think raco test ends up doing something that isn’t allowed in atomic mode.


mflatt
2021-2-17 02:50:58

Getting escapes in callbacks to work in Chez Scheme turns out to be tricky. Possibly a new ffi/unsafe library should provide better support for it.


mflatt
2021-2-17 02:53:54

To put things another way, it didn’t really work in v7.9, but there were fewer constraints in place to help highlight when you’re entered a bad state.


dvanhorn
2021-2-17 02:55:40

Thanks. So adding a call to end-atomic in the handler is what I want here?


mflatt
2021-2-17 02:58:56

That will avoid the error in this case, but it’s not really the right change.


mflatt
2021-2-17 03:00:19

There’s an example of something that can work in readline/rktrl.rkt.


mflatt
2021-2-17 03:01:35

It’s complicated, and the essential ingredient is that it creates a new OS thread to isolate the call and callback from Racket threads.


dvanhorn
2021-2-17 03:02:37

at least in my particular case, when the callback is invoked, I’m done with the library, if that simplifies things.


dvanhorn
2021-2-17 03:05:47

:eyes:


dvanhorn
2021-2-17 03:05:55

oh boy


mflatt
2021-2-17 03:23:34

I’ll extract the relevant part of that code.


dvanhorn
2021-2-17 03:27:28

thanks Matthew. That code is beyond my level.


mflatt
2021-2-17 03:29:07

I think the part you need is much simpler, because you don’t need the callback to be in non-atomic mode, which is the case for readline.


mflatt
2021-2-17 03:32:10

Hm… a relevant facet of the readline code, though, is that it works at the level of the Chez Scheme FFI. I don’t think I can make it work on the outside of the Racket FFI layer (i.e., without changing the Racket FFI).


mflatt
2021-2-17 03:40:29

I started to think more about why I haven’t had to solve this simpler problem before, and that lead me to relevant code in “draw-lib/racket/draw/unsafe/callback.rkt”.


mflatt
2021-2-17 03:45:03

It turns out that the (enable-interrupts) there is no longer needed (which is consistent with the comment about this being fragile). Probably this code should be part of the core FFI.

Meanwhile, assuming you need things to work earlier, that’s reasonable code to use for now.


dvanhorn
2021-2-17 03:45:35

OK, thanks for your help.


notjack
2021-2-17 03:54:36

Today I learned that splicing syntax classes can be spliced into templates without using ellipses (define-splicing-syntax-class three-forms (pattern (~seq _ _ _))) (syntax-parse #'(a b c d e f g h) [(triplet:three-forms rest ...) #`(TRIPLET #,@#'triplet REST rest ...)]) ;; result: (TRIPLET a b c REST d e f g h) The #,@#'var part was the part I didn’t realize would work. I initially tried TRIPLET triplet … REST rest … and when that didn’t work I assumed it wasn’t possible.


kellysmith12.21
2021-2-17 03:58:52

It’d be nice if there were a tidier way to use splicing syntax classes in templates. I generally use #'(foo {~@ . var} bar), which isn’t great. I find the #,@#'var to be rather noisy-looking.


kellysmith12.21
2021-2-17 04:08:39

(I generally don’t use ellipses to splice in a splicing syntax class if it isn’t itself defined with an ellipsis pattern. Now that I think about it, I can’t really explain why I do that, but I think it has to do with clarifying, in the template, how I think about the grammar.)