[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Current release has CHARCODE included



CHARCODE

The facilities in this file make it possible to gain the efficiency
that comes from dealing with character codes instead of character atoms
without losing the symbolic advantages of the latter.

Two functions (with appropriate macros, etc.) are provided:

charcode[c]  Nlambda that returns the character code structure specified
	by c.  If c is a 1-character atom or string, the corresponding character
	code is simply returned.  Thus (CHARCODE A) is 65, (CHARCODE 0) is 48.
	If c is a list structure, the value is an image of c with all the
	leaves replaced by the corresponding character codes.  E.g.,
	(CHARCODE (A (B C))) is (65 (66 67)).

	charcode permits easy specification of certain peculiar character
	codes:
	  A multi-character atom or string whose first character is ^ is
	  interpreted as the control-character corresponding to its second
	  character.  Thus, (CHARCODE ^A) is 1, the code for control-A.

	  The following key words are mapped into the indicated codes:
		CR	13
		LF	10
		SPACE or SP	32
		EOL	31
		ESCAPE or ESC	27
		BELL	7
		BS	8
		TAB 	9
		NULL	0
		DEL	127

	Finally, charcode maps NIL into NIL.  This is included because
	some character-code producing functions sometimes return NIL
	(e.g. NTHCHARCODE); a test for that value can be included
	in a charcode list along with true character-code values.

Charcode of symbolic arguments can be used wherever a structure of
character codes would be appropriate.  For example
	(FMEMB (NTHCHARCODE X 1) (CHARCODE (CR LF SPACE)))  or
	(EQ (BIN FOO) (CHARCODE ^C))

There is a macro for charcode which causes the character-code structure
to be constructed at compile-time.  Thus, the compiled code for these
examples is exactly as efficient as the less readable
	(FMEMB (NTHCHARCODE X 1) (QUOTE (13 10 32)))
	(EQ (BIN FOO) 3)

The second function in this file is a selection function similar to
SELECTQ, except that the selection keys are determined by applying
charcode (instead of QUOTE) to the key-expressions:

selcharq[e;clause1...clausen;default]  Nlambda like selectq.  If the value of
	e is a character code or NIL and it is EQ or MEMB to the result
	of applying charcode to the first element of a clause, the remaining
	forms of that clause are evaluated.  Otherwise, the default is evaluated.
Thus
	(SELCHARQ (BIN FOO)
		  ((SPACE TAB) (FUM))
		  ((^D NIL) (BAR))
		  (a (BAZ))
		  (ZIP))
is exactly equivalent to
	(SELECTQ  (BIN FOO)
		  ((32 9) (FUM))
		  ((4 NIL) (BAR))
		  (97 (BAZ))
		  (ZIP))

Furthermore, selcharq has a macro such that it always compiles as
an equivalent selectq.

-----
Comments and suggestions to Ron Kaplan
-------