Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple characters in the CL Standard

22 views
Skip to first unread message

Paul Dietz

unread,
Apr 10, 1998, 3:00:00 AM4/10/98
to

I have a question for CL Standards gurus:

Is there a standard way in Common Lisp to determine if a character is a
simple character?

I'd guess that (char= (code-char (char-code c)) c) would work, but as
far as I can tell the standard doesn't say that code-char doesn't set
any implementation defined attributes to non-null values.

The reason I am asking is that a string containing simple characters is
supposed to print readably when *PRINT-READABLY* is true. However, in
two lisps I've tried the string containing a single null character,
produced by

(make-string 1)
or by
(make-string 1 :initial-element (code-char 0))

prints as "^@", even with *PRINT-READABLY* set to true. This reads back
in as a two character string (^ and @).

Paul Dietz
di...@interaccess.com

Paul Dietz

unread,
Apr 10, 1998, 3:00:00 AM4/10/98
to

> | Is there a standard way in Common Lisp to determine if a character is a
> | simple character?
>
> does (typep <character> 'base-char) cut it?

I don't think so, at least not portably. A simple character is defined
to be a character with no attributes except the character code. I don't
see where it says in the standard that a base character has to be
simple, or that simple characters have to be base characters. A simple
character in a string must be a base character, though.


> (length (read-from-string (write-to-string (string (code-char 0)) :readably t)))
>
> returns 2, not 1?
>
> I can't see that it does that anywhere I try it. what do you do to make
> the length become 2?

Oops. My mistake. Emacs was displaying it as ^@ but, of course, it was
only one character.

ObSqueakyVoice: "Never Mind."

Paul

Erik Naggum

unread,
Apr 11, 1998, 3:00:00 AM4/11/98
to

* Paul Dietz

| I have a question for CL Standards gurus:

I'll try to answer, anyway.

| Is there a standard way in Common Lisp to determine if a character is a
| simple character?

does (typep <character> 'base-char) cut it?

| However, in two lisps I've tried the string containing a single null


| character, produced by
|
| (make-string 1)
| or by
| (make-string 1 :initial-element (code-char 0))
|
| prints as "^@", even with *PRINT-READABLY* set to true. This reads back
| in as a two character string (^ and @).

do you mean that

(length (read-from-string (write-to-string (string (code-char 0)) :readably t)))

returns 2, not 1?

I can't see that it does that anywhere I try it. what do you do to make
the length become 2?

#:Erik
--
religious cult update in light of new scientific discoveries:
"when we cannot go to the comet, the comet must come to us."

Erik Naggum

unread,
Apr 11, 1998, 3:00:00 AM4/11/98
to

* Paul Dietz

| I don't think so, at least not portably. A simple character is defined
| to be a character with no attributes except the character code. I don't
| see where it says in the standard that a base character has to be simple,
| or that simple characters have to be base characters. A simple character
| in a string must be a base character, though.

I couldn't find such a requirement myself, but STANDARD-CHAR _is_ defined
to be a simple character ("any character that is not simple is not a
standard character"), although this excludes most control characters and
any 8-bit characters you may have. however, no Lisp I have found have
answered true to (typep #3\a 'base-char) or (typep #\M-a 'base-char),
although the reason is that Allegro CL answers NIL, CMUCL 17f doesn't
support bits or fonts to begin with, and CLISP doesn't support BASE-CHAR.

however, I might think the question is moot, now that the minor confusion
over "^@" has been resolved.

0 new messages