From: Louis Glassy
Subject: Vector syntax for a string?
Date: 
Message-ID: <754ije$514$1@netra.msu.montana.edu>
Time to get back to Lisp hacking (finals over, yay!)...

Is there a way a CL implementation can read a vector of
characters and recognize it as a string?

Here's what I'd like to do...

> #( #\c #\a #t )		; & I'd like to see:

"cat"

> (typep #( #\c #\a #t ) 'string)

T

i.e., a vector of "some kind of char" should be internally
stored as an object of type string.

It would be fine if I had to do something like

> #( (frob #\c) (frob #\a) (frob #\t) )

where frob is some function that turns a standard-char 
into whatever kind of char (a base-char?) that lives in a real string.

Is there a frob-like function in CL?  If not, is character handling
of this sort doomed to be implementation-dependent, or is there 
another slick way of doing this (having a vector of some kind
of char, be read in and identically stored as a string)?


None of the CL's to which I have access-
	GCL (v2.2 and v2.2.2)
	CLISP version "1996-07-22 (July 1996)"

seem to handle this business of character handling
consistently relative to each other, 
or to what I've read in CLtL2 and the HyperSpec.

GCL appears to be converting the characters in #( #\c #\a #t )
into some type other than STANDARD-CHAR, though in GCL docs it
doesn't say what this internal type is, nor how to make a STANDARD-CHAR
into this internal type.

CLISP (version mentioned above) doesn't accept #( #\c #\a #t )
as a valid syntax, but says

(typep #\a 'string-char)
T
>

So I'm confused.  

I'm fixing the read and print parts of the r-e-p-l loop in 
a small Lisp interpreter, and if I can, I'd like my version of the 
interpreter to handle characters and strings in a way that's
consistent with CL.  (Hence, the questions above.)

Thanks in advance,

-Lou


Lou Glassy (······@cs.montana.edu)

From: Erik Naggum
Subject: Re: Vector syntax for a string?
Date: 
Message-ID: <3122685926969359@naggum.no>
* Louis Glassy <······@acheta.nervana.montana.edu>
| Is there a way a CL implementation can read a vector of
| characters and recognize it as a string?

  no.  reading vectors using the standard syntax can only create simple
  vectors, i.e., of type (vector t).  strings are like (vector character).

| into whatever kind of char (a base-char?) that lives in a real string.

  (array-element-type "cat") => character

  note that STRING-CHAR is no longer a type in ANSI Common Lisp.

| I'm fixing the read and print parts of the r-e-p-l loop in a small Lisp
| interpreter, and if I can, I'd like my version of the interpreter to
| handle characters and strings in a way that's consistent with CL.

  the reader for #( is basically (apply #'vector (read-delimited-list #\))).

#:Erik
-- 
  man who cooks while hacking eats food that has died twice.
From: Larry Hunter
Subject: Re: Vector syntax for a string?
Date: 
Message-ID: <rbiufd2yco.fsf@work.nlm.nih.gov>
Louis Glassy asks:

 Is there a way a CL implementation can read a vector of characters and
 recognize it as a string? Here's what I'd like to do...

 > #( #\c #\a #t )		; & I'd like to see:
 "cat"

Well, vectors are strings are different predefined types in lisp, but vectors
of characters are easily coerced to be strings:

 USER(15): (coerce #(#\c #\a #\t) 'string)
 "cat"

Larry

-- 
Lawrence Hunter, PhD.
National Library of Medicine               phone: +1 (301) 496-9303
Bldg. 38A, 9th fl, MS-54                   fax:   +1 (301) 496-0673
Bethesda. MD 20894 USA                     email: ······@nlm.nih.gov