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.
············@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
···········@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.
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.
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)
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.