From: Francesco Moi
Subject: How to obtain a char from a string?
Date: 
Message-ID: <5b829932.0112170219.35e8c487@posting.google.com>
Hi!

I know that since strings are arrays, and therefore sequences as well,
I can operate on them with the general array and sequence functions.

Could you give me an example to obtain the first char from "Hello"?

Regards.

From: Kyongho Min
Subject: Re: How to obtain a char from a string?
Date: 
Message-ID: <bd09e78f.0112171633.120a2756@posting.google.com>
············@europe.com (Francesco Moi) wrote in message news:<····························@posting.google.com>...
> Hi!
> 
> I know that since strings are arrays, and therefore sequences as well,
> I can operate on them with the general array and sequence functions.
> 
> Could you give me an example to obtain the first char from "Hello"?
> 
> Regards.

(elt "Hello" 0)

cheers,

Kyongho
From: Kent M Pitman
Subject: Re: How to obtain a char from a string?
Date: 
Message-ID: <sfwd71aal92.fsf@shell01.TheWorld.com>
···········@aut.ac.nz (Kyongho Min) writes:

> ············@europe.com (Francesco Moi) wrote in message news:<····························@posting.google.com>...
> > Hi!
> > 
> > I know that since strings are arrays, and therefore sequences as well,
> > I can operate on them with the general array and sequence functions.
> > 
> > Could you give me an example to obtain the first char from "Hello"?
> > 
> > Regards.
> 
> (elt "Hello" 0)

Don't use ELT, which will probably have to do a runtime type check to
decide whether to use CAR or AREF.

ELT should only be used when you're not sure whether you're getting a
list or a sequence and would have to check the type anyway.  And even
the it is almost always the wrong thing because usually the type-check
is a loop invariant and wants to be factored out, and it's hard to do
that if it's bundled into a function call instead of separately managed
as in:

 (if (listp my-seq)
     (dolist (x my-seq) ...use (CAR my-seq)...)
     (dotimes (i (length my-seq)) ...use (AREF my-seq 0)...))

Using ELT causes the typ-check to be done (length my-seq) times when
one would have sufficed.
From: Barry Margolin
Subject: Re: How to obtain a char from a string?
Date: 
Message-ID: <HkbU7.54$TZ5.153958@burlma1-snr2>
In article <···············@shell01.TheWorld.com>,
Kent M Pitman  <······@world.std.com> wrote:
>···········@aut.ac.nz (Kyongho Min) writes:
>
>> ············@europe.com (Francesco Moi) wrote in message
>news:<····························@posting.google.com>...
>> > Hi!
>> > 
>> > I know that since strings are arrays, and therefore sequences as well,
>> > I can operate on them with the general array and sequence functions.
>> > 
>> > Could you give me an example to obtain the first char from "Hello"?
>> > 
>> > Regards.
>> 
>> (elt "Hello" 0)
>
>Don't use ELT, which will probably have to do a runtime type check to
>decide whether to use CAR or AREF.

The OP asked how to operate on them with general sequence functions, he was
just answering the question.  Whether it's advisable is a totally separate
issue.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Cory Spencer
Subject: Re: How to obtain a char from a string?
Date: 
Message-ID: <9vr3gj$nf6$2@nntp.itservices.ubc.ca>
Francesco Moi <············@europe.com> wrote:

> I know that since strings are arrays, and therefore sequences as well,
> I can operate on them with the general array and sequence functions.
>
> Could you give me an example to obtain the first char from "Hello"?

The char function should do the job:

  (char "Hello" 0)
From: Barry Margolin
Subject: Re: How to obtain a char from a string?
Date: 
Message-ID: <NiaU7.38$TZ5.153922@burlma1-snr2>
In article <····························@posting.google.com>,
Francesco Moi <············@europe.com> wrote:
>I know that since strings are arrays, and therefore sequences as well,
>I can operate on them with the general array and sequence functions.
>
>Could you give me an example to obtain the first char from "Hello"?

Using the general array functions: (aref "Hello" 0)

Using the general sequence functions: (elt "Hello" 0)

WTP?

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.