Re: [racket-users] Why does 1 count as numeric in xexpr, but 0 does not?

2017-03-14 Thread Marc Kaufmann
Fair enough if that's the specification, even if it is unexpected (to me at 
least). Thanks,

Marc

On Tuesday, March 14, 2017 at 10:41:02 AM UTC-4, Jay McCarthy wrote:
> Hi Marc,
> 
> libxml2 only allows numeric entity references in this range:
> 
> * [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
> * | [#x1-#x10]
> 
> Racket doesn't fully respect that, but both disallow 0. I think we
> should match libxml2 and tighten the contract.
> 
> Jay
> 
> -- 
> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
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.


Re: [racket-users] Why does 1 count as numeric in xexpr, but 0 does not?

2017-03-14 Thread Jay McCarthy
Hi Marc,

libxml2 only allows numeric entity references in this range:

* [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
* | [#x1-#x10]

Racket doesn't fully respect that, but both disallow 0. I think we
should match libxml2 and tighten the contract.

Jay

-- 
-=[ Jay McCarthy   http://jeapostrophe.github.io]=-
-=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
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.


Re: [racket-users] Why does 1 count as numeric in xexpr, but 0 does not?

2017-03-14 Thread Marc Kaufmann
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 "". 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  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] | [#x1-#x10]), 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.


Re: [racket-users] Why does 1 count as numeric in xexpr, but 0 does not?

2017-03-13 Thread Philip McGrath
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 "". 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 
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] | [#x1-#x10]), 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.


[racket-users] Why does 1 count as numeric in xexpr, but 0 does not?

2017-03-13 Thread Marc Kaufmann
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] | [#x1-#x10]), 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.