Scribbling hexadecimal values

26 views
Skip to first unread message

Dominik Pantůček

unread,
Sep 18, 2020, 2:23:24 PM9/18/20
to Racket Users
Hello Racketeers,

I am struggling to make scribble typeset default values in
proc-doc/names in hexadecimal. An example would be:

(proc-doc/names
name
(->* () (integer?) void?)
(()
((argument #x1f)))
@{ some description }) ; yes, at-exp reader

The same applies to values in nested contracts of ->* - like (integer-in
0 #x1f).

Of course #,(~a "~x" #x1f) will produce the string with appropriate
contents - but enclosed in parentheses which does not help much. Also it
is not just a matter of typesetting because the provide form really
contracts the procedure being provided and the actual values should
actually be present.

I would love to see some documentation-stage parameter where I could
just (parameterize ((numbers-as-hexadecimal #t)) (integer-in ...) ...)
and it would keep the values as they are for contract purposes and
render them hexadecimal. Of course, this is quite specific - more
generic solution is probably more appropriate, this is just to explain
the problem I am trying to solve.


Cheers,
Dominik

Ben Greenman

unread,
Sep 18, 2020, 2:36:57 PM9/18/20
to Dominik Pantůček, Racket Users
+1

For now, I've used hacks like `(string->number "#x...")` for typesetting
https://docs.racket-lang.org/pict-abbrevs/index.html
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/aca5b2ab-36b6-98c6-0747-9d5447ae9766%40trustica.cz.
>

William J. Bowman

unread,
Sep 18, 2020, 6:59:54 PM9/18/20
to Ben Greenman, Dominik Pantůček, Racket Users
Same but also binary values "#b...".
I think I've been using @code{} to get these to render right, but this doesn't
work in all contexts.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAFUu9R7xE4j4f8CLqWhV3-jRKMifFxUfLBx7xBogiuaT37OwqA%40mail.gmail.com.

Eric Griffis

unread,
Sep 18, 2020, 9:40:32 PM9/18/20
to Dominik Pantůček, Racket Users
Hi Dominik,

If you put the hex number in a string, many of the formatting functions in the Scribble manual, section 4.2.1.4 will work:

  (proc-doc/names
   name
   (->* () (integer?) void?)
   (()
    ((argument #,(racketvalfont "#x1f"))))
   @{ some description }))

Eric


Dominik Pantůček

unread,
Sep 19, 2020, 3:29:56 AM9/19/20
to Racket Users
Hi Eric,

thank you. Actually I was already using unsyntax for putting the default
values in optional arguments list and didn't recognize that I can use
anything from the scribble API at that point. Now the formatting of
default values is simple and yields expected results. In my case:

(()
((argb #,(racketvalfont (format "#x~x" (arithmetic-shift alpha-max
24))))))

This is really cool.

However, for the contract part, I think the only solution would be
adding a parameter that would change the behavior of
proc-doc-transformer and proc-doc/names transformer or more generally
add support to *defproc's do-one' arg-contracts handling code.

This basically goes down to racketblock0 rendering of numbers.

I am afraid that this needs some with more experience with scribble
internals to implement. I think that adding parameter to configure the
rendering of numbers inside define-code-like forms will be rather easy.
But how to parameterize in provide block and not mess with any of those
proc-doc*transformer code is currently beyond my understanding.

I would appreciate any hints though.


Cheers,
Dominik
> <mailto:racket-users%2Bunsu...@googlegroups.com>.

Robby Findler

unread,
Sep 19, 2020, 10:17:56 AM9/19/20
to Dominik Pantůček, Racket Users
I don't have any good hints but the reader supplies span information that can be used to disambiguate the original versions of some things (notably "#t" vs "#true"). I doubt this is enough for numbers in any general sense but following the path of actually carrying more information from the reader through scribble to the rendered output may be an approach worth considering.

Robby

To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/23557632-fe68-567e-3a2e-c9abf6df5779%40trustica.cz.
Reply all
Reply to author
Forward
0 new messages