Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Simple characters in the CL Standard

瀏覽次數:23 次
跳到第一則未讀訊息

Paul Dietz

未讀,
1998年4月10日 凌晨3:00:001998/4/10
收件者:

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

未讀,
1998年4月10日 凌晨3:00:001998/4/10
收件者:

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

未讀,
1998年4月11日 凌晨3:00:001998/4/11
收件者:

* 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

未讀,
1998年4月11日 凌晨3:00:001998/4/11
收件者:

* 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 則新訊息