Re: predicate->char-set considered harmful
Brad Lucier 19 Dec 2000 02:33 UTC
>
> From: Brad Lucier <xxxxxx@math.purdue.edu>
>
> > I hope you don't try to define predicate->bitset in a later SRFI ;-).
> >
> > Well, I guess it's too late to put it into the lset-... suite of
> > operations in SRFI 1...
>
> My unstated (definitely understated) point is that predicate->bitset
> will never return in the general case, which isn't much different from
> how long it will take predicate->char-set to return on systems that use
> a four-byte character representation.
>
> Yep, I understood. Just a little bit of wry academic humor there, on my
> part.
>
> Clearly people who use 4-byte char types will have to stear clear of
> ops that are linear in the type size.
> -Olin
>
I'm trying to think of a way to embed an escape procedure into
predicate->char-set[!]. Is the following legal? Does it solve
the "I only want to examine ASCII characters to build this set"
problem?
(define cs
(let ((result (char-set)))
(call-with-current-continuation
(lambda (exit)
(predicate->char-set! (lambda (ch) (or (char=? ch #\newline)
(and (> (char->integer ch) 127)
(exit))))
result)))
result))
I suppose one would need a guarantee that characters are examined in
(char->integer ch) order, and it would have to add the character to
result immediately when the predicate returned true, and it isn't
linear update, and ...
Oh well.
Brad