char-generator Bradley Lucier (14 Jan 2024 17:45 UTC)
Re: char-generator Per Bothner (14 Jan 2024 17:59 UTC)
Re: char-generator Marc Nieper-Wißkirchen (14 Jan 2024 18:02 UTC)
Re: char-generator John Cowan (16 Jan 2024 02:28 UTC)
Re: char-generator Per Bothner (16 Jan 2024 06:10 UTC)
Re: char-generator Antero Mejr (16 Jan 2024 16:49 UTC)
Re: char-generator John Cowan (17 Jan 2024 02:49 UTC)
Re: char-generator Marc Nieper-Wißkirchen (14 Jan 2024 18:00 UTC)
Re: char-generator Bradley Lucier (14 Jan 2024 18:04 UTC)
Re: char-generator Marc Nieper-Wißkirchen (14 Jan 2024 18:06 UTC)
Re: char-generator Antero Mejr (15 Jan 2024 03:17 UTC)
Re: char-generator John Cowan (16 Jan 2024 01:40 UTC)

char-generator Bradley Lucier 14 Jan 2024 17:44 UTC

The draft document states:

char-generator does not use an SRFI 14 char-set. This means, for
implementations that use Unicode, char-generator may generate characters
that are not valid Unicode code points. I think this is the correct
behavior, since invalid code points fulfill the char? predicate.

First question: Why do "invalid code points fulfill the char?
predicate"?  It does seem to be true, at least for Gambit, but is there
some document somewhere that specifies this?

Second question: The character generator in SRFI 231's test-arrays.scm,
which was written under Gambit, is

(define (random-inclusive a #!optional b)
   (if b
       (+ a (test-random-integer (- b a -1)))
       (test-random-integer (+ a 1))))

(define (random-char)
   (let ((n (random-inclusive (##max-char-code))))
     (if (or (fx< n #xd800)
             (fx< #xdfff n))
         (integer->char n)
         (random-char))))

This is because (integer->char n) throws an error if n is not a valid
Unicode code point.
=============================
Aside: In Gambit, while (##integer->char n) does no error checking, it
also does things like:

 > (##integer->char -1)
#f
=============================
So I don't believe that the sample implementation

     (define (char-generator)
       (gcons* #\null
               (gmap integer->char (make-random-integer-generator 0
max-char))))

will work on Gambit.

I guess I would propose that (char-generator) return only valid
characters according to whatever the implementation supports.

Brad