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

newbie: problems with strings

23 views
Skip to first unread message

Josip Krapac

unread,
Feb 13, 2002, 7:10:34 AM2/13/02
to
If this is true:

1. strings are vectors of characters
2. function vector constructs a simple-vector from the given objects
3. individual characters are denoted by #\ prefix

Why then this fails:

(setf test-vector-1 (vector #\f #\o #\o))
(setf test-vector-2 "foo")

(string-equal test-vector-1 test-vector-2)

CMUCL reports this:

Type-error in KERNEL::OBJECT-NOT-TYPE-ERROR-HANDLER:
#(#\f #\o #\o) is not of type (OR BASE-STRING SYMBOL BASE-CHAR)

If I understand correct, problem is that #(#\f #\o #\o) is not sting (it
is simple vector) and function string-equal requires stings.

My questions are:

If strings are vectors of characters then why (vector #\f #\o #\o) is
not a string?

Are strings also simple-vectors of characters?

What is the difference bewteen simple-vectors and non-simple-vectors?

Dr. Edmund Weitz

unread,
Feb 13, 2002, 7:38:24 AM2/13/02
to
Josip Krapac <josip....@fsb.hr> writes:

Strings don't need to be simple vectors but they need to be
_specialized_ vectors. The function VECTOR will return _general_
vectors:

* (defparameter *test-vector-1* (vector #\f #\o #\o))
*TEST-VECTOR-1*
* (type-of *test-vector-1*)
(SIMPLE-VECTOR 3)
* (typep *test-vector-1* 'string)
NIL
T
* (defparameter *test-vector-2* (make-array 3 :element-type 'base-char))
*TEST-VECTOR-2*
* (type-of *test-vector-2*)
(SIMPLE-BASE-STRING 3)
* (typep *test-vector-2* 'string)
T
T

HTH,
Edi.

--

Dr. Edmund Weitz
Hamburg
Germany

The Common Lisp Cookbook
<http://agharta.de/cookbook/>

Erik Naggum

unread,
Feb 13, 2002, 7:40:21 AM2/13/02
to
* Josip Krapac <josip....@fsb.hr>

| If strings are vectors of characters then why (vector #\f #\o #\o) is not
| a string?

Because strings are _specialized_ vectors of characters.

| Are strings also simple-vectors of characters?

No.

| What is the difference bewteen simple-vectors and non-simple-vectors?

The homogeneity of the type of the elements.

In other words, a string is a vector that can _only_ store characters.

///
--
In a fight against something, the fight has value, victory has none.
In a fight for something, the fight is a loss, victory merely relief.

Dr. Edmund Weitz

unread,
Feb 13, 2002, 8:10:35 AM2/13/02
to
Erik Naggum <er...@naggum.net> writes:

> * Josip Krapac <josip....@fsb.hr>


> | What is the difference bewteen simple-vectors and non-simple-vectors?
>
> The homogeneity of the type of the elements.

No. I think you've overseen the OP's questions and expected another
one instead. The correct answer from the CLHS is that a simple-vector
is "not displaced to another array, has no fill pointer, and is not
expressly adjustable." The question whether a vector is a string or
not is orthogonal to it being simple or not as far as I understand it.

Kent M Pitman

unread,
Feb 13, 2002, 8:47:52 AM2/13/02
to
e...@agharta.de (Dr. Edmund Weitz) writes:

> Erik Naggum <er...@naggum.net> writes:
>
> > * Josip Krapac <josip....@fsb.hr>
> > | What is the difference bewteen simple-vectors and non-simple-vectors?
> >
> > The homogeneity of the type of the elements.
>
> No. I think you've overseen the OP's questions and expected another
> one instead. The correct answer from the CLHS is that a simple-vector
> is "not displaced to another array, has no fill pointer, and is not
> expressly adjustable." The question whether a vector is a string or
> not is orthogonal to it being simple or not as far as I understand it.

The problem is that a "string" is a "vector" that is "simple", but it is
not a "simple vector".

This was an editorial choice I made in the presentation of ANSI CL (and
hence CLHS). It is never the case that an English phrase that is the same
name as a class does not mean the same as the class. The name SIMPLE-VECTOR
has a meaning, so I forcd "simple vector" to mean what it means. But if I'd
had my way, and if compatibility didn't matter (which it did), we might
have renamed SIMPLE-VECTOR to SIMPLE-GENERAL-VECTOR, which would have allowed
the terminology that Josip was imagining (without reading the actual spec to
see) was in play. Note, though, that this would have probably meant other
unpleasant changes like renaming the VECTOR function to GENERAL-VECTOR, or at
least creating a new class GENERAL-VECTOR that calling VECTOR would
instantiate. There's a problem with punning on VECTOR, right now; the name
is used both for 1d and for general-1d stuff, and that's a major confusion.

(As I recall, there is a similar design error in the condition system,
confusing naming of class prototypes with instantiated types, but I'm
not going to try to dredged it up out of long-term memory right now. I'm
just going to observe that this is a subtlety that is not easily noticed at
initial design time until one develops terminology for the paradigm of the
problem and a hygiene for avoiding it. Languages are designed seldom
enough, and often by committees rather than individuals, such that things
like this creep in easily by either disuse of the skill or people involved
not having the skill of doing good naming. Once deployed, one might notice
these things, but compatibility becomes paramount, and early decisions are
often hard to back out of.)

From the CLHS glossary:

array n. an object of type array, which serves as a container for
other objects arranged in a Cartesian coordinate system.

simple adj.
1. (of an array) being of type simple-array.
2. (of a character) having no implementation-defined attributes,
or else having implementation-defined attributes each of which
has the null value for that attribute.

simple array n. an array of type simple-array.

simple general vector n. a simple vector.

simple string n. a string of type simple-string.

simple vector n. a vector of type simple-vector, sometimes called a
``simple general vector.'' Not all vectors that are simple are simple
vectors---only those that have element type t.

string n. a specialized vector that is of type string, and whose
elements are of type character or a subtype of type character.

vector n. a one-dimensional array.


From the CLHS dictionary, these are the class precedence list and/or
supertypes of various classes:

Class ARRAY -- array, t

Type SIMPLE-ARRAY -- simple-array, array, t

Type SIMPLE-STRING -- simple-string, string, vector,
simple-array, array, sequence, t

Type SIMPLE-VECTOR -- simple-vector, vector, simple-array,
array, sequence, t

Class STRING -- string, vector, array, sequence, t

Class VECTOR -- vector, array, sequence, t

Dr. Edmund Weitz

unread,
Feb 13, 2002, 9:12:10 AM2/13/02
to

Thanks. Looks like I didn't read the HyperSpec carefully enough. I
expected the adjective 'simple' to be 'just an adjective' in that a
'simple vector' would be the same as a vector which is 'simple'. I
have to admit that the CLHS is clear on the subject albeit a bit
subtle. (I also should have noticed that the entry for the
simple-vector type explicitely says "is able to hold elements of any
type".)

Sorry for the confusion that I may have caused.

Erik Naggum

unread,
Feb 13, 2002, 10:51:25 AM2/13/02
to
* Dr. Edmund Weitz

| No. I think you've overseen the OP's questions and expected another one
| instead.

Huh? He was talking about strings and vectors of characters, not about
fill-pointers and displacement. So where did that come from? I am not a
big fan of answering questions out of context.

| The correct answer from the CLHS is that a simple-vector is "not
| displaced to another array, has no fill pointer, and is not expressly
| adjustable." The question whether a vector is a string or not is
| orthogonal to it being simple or not as far as I understand it.

Well, you did not ask the question. My goal is to help people undestand,
not anal-retentively regurgitate the standard.

Dr. Edmund Weitz

unread,
Feb 13, 2002, 11:27:20 AM2/13/02
to
Erik Naggum <er...@naggum.net> writes:

> * Dr. Edmund Weitz
> | No. I think you've overseen the OP's questions and expected
> | another one instead.
>
> Huh? He was talking about strings and vectors of characters, not
> about fill-pointers and displacement. So where did that come
> from? I am not a big fan of answering questions out of context.
>
> | The correct answer from the CLHS is that a simple-vector is "not
> | displaced to another array, has no fill pointer, and is not
> | expressly adjustable." The question whether a vector is a string
> | or not is orthogonal to it being simple or not as far as I
> | understand it.
>
> Well, you did not ask the question. My goal is to help people
> undestand, not anal-retentively regurgitate the standard.

I _thought_ your posting was wrong and tried to correct it. As it
turns out and was clarified by Kent Pitman, it was _me_ who was
wrong and I've apologized for the confusion.

I nevertheless see no reason for your aggressive and insulting
language, but that's your problem and not mine.

[My last posting in this thread.]

Erik Naggum

unread,
Feb 13, 2002, 2:13:07 PM2/13/02
to
* Dr. Edmund Weitz

| I _thought_ your posting was wrong and tried to correct it.

Just assume that what I write is correct. It will save you a lot of
trouble. I spend a lot of time and energy to make sure that I do not
post trash when answering technical questions. When I am uncertain, I
post questions, not answers -- that is how I got where I am today. I
think you should adopt a similar strategy, as it would lead to a lot less
opportunity to insult people with an implied "you're lazy and wrong" even
when they have paid attention and made a serious effort to be correct.
You have an _obligation_ not to post misinformation and wrong answers,
and it is _terribly_ insulting to imply that somebody else has not done
either by following up a correct answer with bogus reply, accident or
not. It is not as if you do not have time to look things up before you
reply to something you think it incorrect. It is not as if you could not
first listen and then try to correct if it turns out _actually_ wrong.
Intellectual laziness is flat out unforgivable in my book, and implying
that somebody is guilty of this when they clearly are not is ipso facto
deeply insulting.

| As it turns out and was clarified by Kent Pitman, it was _me_ who was
| wrong and I've apologized for the confusion.

Curiously, you chose to insult me again instead of apologizing to me,
even though it was me you insulted to begin with. Then you try to make
it my fault that you insult me, which I do _not_ appreciate. That you do
not seem to understand this is not encouraging, either. Who knows, now,
how much bogosity has crept into your other postings? You clearly did
not check up on what I said before you thought it was wrong. This is a
_very_ bad sign. I expect _so_ much better from someone who signs his
posts with his doctorate degree.

| I nevertheless see no reason for your aggressive and insulting language,
| but that's your problem and not mine.

You just _made_ it your problem as well as mine. Why did you do this?
Furthermore, I have explained to you that you implied wrongdoing on the
part of somebody else where the only wrongdoing was your own laziness.
If you do not see this a reason to dislike your response, just grow a
clue. If you think my response was aggressive and insulting, grow
another clue: you just gave me a good reason to _be_ aggressive and
insult you because you had the very bad taste to post your whining
opinion that imputed even more wrongdoing to me. How do you expect me to
respond when _you_ are such an insulting bastard towards me? _Here is a
clue: Stop being so whiny about things you do not understand. LISTEN to
other people! They may be right even when you think they are wrong, in
more ways than merely technical, and it _is_ insulting and arrogant to
assume that you do not need to check your references properly when you
want to correct someone else, even when you _are_ right. The reason I am
correct almost all the time, is precisely that I check up on what I write
before I respond. The reason I get pissed at people who post trash is
that I listen to them first, but then it turns out that most of them are
just lazy idiots who post crap, not only wasting my time, but ridiculing
every person who pays attention to details, who strives to post correct
technical answers, who spends time and energy to help people with serious
suggestions. Because very few opinions are _clearly_ wrong, one must
look beyond the conclusion to find the observations it is based on and
the method used to reach the conclusion, and when the conclusion and
opinion is based on almost no observations and complete lack of method,
it was an insult to the audience to post the opinion the first place.

| [My last posting in this thread.]

I assume you have your reasons to take this so personally and to be so
goddamn snotty about it, too, but would you mind keeping that to yourself
and _try_ to whine to somebody who cares instead of going off the handle
publicly? Thank you for not replying with more of the same crap.

Erann Gat

unread,
Feb 13, 2002, 3:54:30 PM2/13/02
to
In article <32226163...@naggum.net>, Erik Naggum <er...@naggum.net> wrote:

> Just assume that what I write is correct. It will save you a lot of
> trouble.

Truer words are rarely seen on comp.lang.lisp. But did you expect Dr.
Weitz to know this before you told him?

> I spend a lot of time and energy to make sure that I do not
> post trash when answering technical questions. When I am uncertain, I
> post questions, not answers

Being certain is not the same as being correct. And most people are
certain more often than they are correct (myself included -- of that I am
certain).

> -- that is how I got where I am today.

And where is that?

E.

0 new messages