Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port-writes-special? ⊂"running under Dr Racket" #234

Open
greghendershott opened this issue Dec 7, 2024 · 2 comments
Open

port-writes-special? ⊂"running under Dr Racket" #234

greghendershott opened this issue Dec 7, 2024 · 2 comments
Labels
test engine topics related to the test engine

Comments

@greghendershott
Copy link

greghendershott commented Dec 7, 2024

The assumption here seems to be that, is if the output port can write "specials", then we're running under Dr Racket:

;; exact fractions - slight hack as we know for what numbers DrRacket generates special snips
(define (use-number-markup? x)
(and (number? x)
(exact? x)
(real? x)
(not (integer? x))))
(define fraction-view
(case (sl-runtime-settings-fraction-style settings)
[(mixed-fraction mixed-fraction-e) 'mixed]
[(repeating-decimal repeating-decimal-e) 'decimal]))
(pretty-print-show-inexactness #t)
(pretty-print-exact-as-decimal (eq? fraction-view 'decimal))
(pretty-print-print-hook
(let ([oh (pretty-print-print-hook)])
(λ (val display? port)
(cond
[(and (not (port-writes-special? port))
(is-image? val))
(display img-str port)]
[(and (use-number-markup? val)
(port-writes-special? port))
(write-special (number val #:exact-prefix 'never #:inexact-prefix 'always #:fraction-view fraction-view) port)]

However that's not necessarily true. Racket Mode presents an output port that accepts write-special. Therefore it ends up getting these number-markup structs. It had been surprised by these, ergo greghendershott/racket-mode#732.

I merged an accommodation for that, today. But generally, it seems like port-writes-special? isn't a sufficient test for "port that knows how to handle number-markup structs, and will end up in a snip in the DrRacket GUI"? I don't know enough to propose a better test, but I wanted to ask.

@rfindler
Copy link
Member

rfindler commented Dec 7, 2024

I agree that the port-writes-special? predicate isn't precise enough; I'm not sure what's the best thing to do in general, however.

For the specific case of the teaching languages and the markup that gets written, there is an API that will print these things in an ascii mode (drawing boxes and whatnot). It would be nice if we could arrange that this got used.

But I don't think it makes sense for that to be something that happens in Racket mode; it would be nice if Racket mode's port could just be like "no thanks" and there would be a fallback to the ascii. I'm really stuck here mentally as I can't get past "there should be a change to Racket's ports" which really isn't a very good direction, just as a general rule!

@shhyou shhyou added the test engine topics related to the test engine label Dec 8, 2024
@greghendershott
Copy link
Author

It seems this is about the "host" environment supplying the port, rather than the port per se.

A mechanism that occurs to me is read-language get-info. Although typically that's used to get lang info to the host, there's also a preexisting example of the REPL submit predicate key, which is a function in the lang called by the host.

In that vein: Could that use-number-markup? function in bsl/runtime.rkt instead be a parameter (or function with parameter-like signature) exposed via a new get-info key? It could default to false (good for things like command-line racket, Racket Mode, etc.). DrRacket could set it true.

(I'm not sure what to name the key, because I don't understand how structs in specials like number-markup end up as objects in GUI "snips". A straw man name: 'simple-tree-lib-markup-structs.)


there is an API that will print these things in an ascii mode (drawing boxes and whatnot). It would be nice if we could arrange that this got used.

IIUC So then maybe the parameter isn't a boolean. Maybe there are three values: "plain", "ascii fallback", "full structs". Whatever you think makes sense. In any case, still the basic idea of using get-info to let the host environment pick which (instead of the lang trying to guess which).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test engine topics related to the test engine
Projects
None yet
Development

No branches or pull requests

3 participants