Using lisp is there a way to search a text value for a certain character
and return everything before that character? "member" does exactly
opposite of this. I guess it would be possible to set up by using
"member" to subtract of the characters at the end that I don't want. I
guess I just answered my own question. That's not good. I'm a newbie at
any kind of programing and don't get much time to play with it. I'll
have to try that out.
Thanks,
Justin
Justin wrote:
> Using lisp is there a way to search a text value for a certain character
> and return everything before that character? "member" does exactly
> opposite of this. I guess it would be possible to set up by using
> "member" to subtract of the characters at the end that I don't want. I
> guess I just answered my own question. That's not good. I'm a newbie at
> any kind of programing and don't get much time to play with it. I'll
> have to try that out.
>
> Thanks,
> Justin
I just looked up "member" and it only searches a list. I need a function to
search an atom.
Thanks,
Justin
In article <·················@tricountyi.net>,
Justin <·······@tricountyi.net> writes:
> Justin wrote:
> > Using lisp is there a way to search a text value for a certain character
> > and return everything before that character? "member" does exactly
> > opposite of this.
>
> I just looked up "member" and it only searches a list.
Fortunately, you don't need to use MEMBER.
> I need a function to search an atom.
Strings aren't atoms, they're sequences; more specifically, a string is a
simple-array of characters. (If you mean that you want to examine the print
name of a symbol, then use SYMBOL-NAME on the symbol.)
The functions that will help you are SUBSEQ (which returns a new sequence
consisting of a part of its sequence argument) and POSITION (which returns
the position of an element in a sequence).
(defun everything-before (string character)
(subseq string 0 (position character string)))
Because this uses general sequence functions, it will also work on other
arrays and on proper lists (though it's a little inefficient for lists).
--
Aaron Crane <···········@pobox.com> <URL:http://pobox.com/~aaronc/>
** Please send on-topic followups by Usenet, not email **
···········@pobox.com (Aaron Crane) writes:
> In article <·················@tricountyi.net>,
> Justin <·······@tricountyi.net> writes:
> > Justin wrote:
> > > Using lisp is there a way to search a text value for a certain character
> > > and return everything before that character? "member" does exactly
> > > opposite of this.
> >
> > I just looked up "member" and it only searches a list.
>
> Fortunately, you don't need to use MEMBER.
>
> > I need a function to search an atom.
>
> Strings aren't atoms, they're sequences; more specifically, a string is a
Everything in lisp is either a cons or an atom. One of the things that have
been carried on from days gone by. Of course, it's not very useful to know
that something is an atom... Other than then being able to say that it is
not a cons :-)
Sunil
I'm using MuLisp, so my answer may not be generally applicable. However, I
would use the following:
(Unpack 'this) ==> (T H I S)
(Reverse (Unpack 'this)) ==> (S I H T)
(Pack '(T H I S)) ==> THIS
Hopefully, you can imagine how to get your answer from these clues. Have
fun.
Justin wrote in message <·················@tricountyi.net>...
>Justin wrote:
>
>> Using lisp is there a way to search a text value for a certain character
>> and return everything before that character? "member" does exactly
>> opposite of this. I guess it would be possible to set up by using
>> "member" to subtract of the characters at the end that I don't want. I
>> guess I just answered my own question. That's not good. I'm a newbie at
>> any kind of programing and don't get much time to play with it. I'll
>> have to try that out.
>>
>> Thanks,
>> Justin
>
>I just looked up "member" and it only searches a list. I need a function to
>search an atom.
>
>Thanks,
>Justin
>
>
Justin <·······@tricountyi.net> writes:
>
> Using lisp is there a way to search a text value for a certain character
> and return everything before that character? "member" does exactly
> opposite of this. I guess it would be possible to set up by using
> "member" to subtract of the characters at the end that I don't want. I
> guess I just answered my own question. That's not good. I'm a newbie at
> any kind of programing and don't get much time to play with it. I'll
> have to try that out.
Assuming "text value" means a string:
(defun return-string-preceding (text-value certain-character)
(subseq text-value 0 (position certain-character text-value)))
Note that this will return the whole string text-value if
certain-character doesn't appear in it, and it is case sensitive
Examples:
USER> (return-string-preceding "This is a test" #\i)
"Th"
USER> (return-string-preceding "This is a test" #\a)
"This is "
USER> (return-string-preceding "This is a test" #\w)
"This is a test"
USER> (return-string-preceding "This is a test" #\t)
"This is a "
USER>
--
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu