Numbers in x-expressions are interpreted as XML entities, not as the string
representation of the number. The value of (xexpr->string '(html 1)), to
use your example, is "<html>&#1;</html>". The 1 represents the character
that Racket would represent as #\u0001, i.e. the value of (integer->char
1). In contrast, (char->integer #\1) produces 49.

-Philip

On Mon, Mar 13, 2017 at 8:38 PM, Marc Kaufmann <marc.kaufman...@gmail.com>
wrote:

> Hi,
>
> I am creating matrices of 0s and 1s that I display in HTML-tables and
> somewhat surprisingly I found out that 0s are not permissible in
> X-expressions, while 1s are:
>
> (require web-server/http)
>
> (response/xexpr '(html 1)) ; Fine, no trouble.
> (response/xexpr '(html 0)) ; Blow-up.
>
> The specific violation is the following:
>
> "response/xexpr: contract violation;
>  Not an Xexpr. Expected a string, symbol, valid numeric entity, comment,
> processing instruction, or list, given 0"
>
> After some digging around, it turns out that only numbers that satisfy
> valid-char? are acceptable, which means "exact-nonnegative-integer whose
> character interpretation under UTF-8 is from the set ([#x1-#xD7FF] |
> [#xE000-#xFFFD] | [#x10000-#x10FFFF]), in accordance with section 2.2 of
> the XML 1.1 spec."
>
> First, should 0 really not be accepted? (I am not going to try and figure
> out the UTF-8 interpretation...) And second, is the reason that negative
> numbers are not acceptable that they are not under the XML spec above? This
> took me by surprise and means I have to put number->string in a bunch of
> places.
>
> Cheers,
> Marc
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to