I understand that the number 1 is different from the string (although I would probably have expected it to be turned into a string before being passed to the browser or something, but it doesn't matter for my purposes). What does surprise me is that (xexpr->string 1) gives , yet (xexpr->string 0) does not give � but throws an error. Is this due to the XML specification, or due to the Racket implementation of X-expressions?
Cheers, Marc On Monday, March 13, 2017 at 10:32:50 PM UTC-4, Philip McGrath wrote: > 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></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.ka...@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...@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.