(DEFUN strpbrk (charray chars)
(LET* ((lens (LENGTH chars)))
(DOTIMES (i lens)
(IF (SEARCH (STRING (CHAR chars i)) charray)
(RETURN T)))))
(IF (strpbrk "*string.." ".*")
(print "Characters found.")
(print "Characters not found."))
In C, the strpbrk function locates the first occurrence
in the string pointed to by s1 of any character from the string pointed to by s2.
Is there another smaller function to do this in Lisp?
Thank You.
DaveNlp
DaveNlp wrote:
> (DEFUN strpbrk (charray chars)
> (LET* ((lens (LENGTH chars)))
> (DOTIMES (i lens)
> (IF (SEARCH (STRING (CHAR chars i)) charray)
> (RETURN T)))))
>
> (IF (strpbrk "*string.." ".*")
> (print "Characters found.")
> (print "Characters not found."))
>
> In C, the strpbrk function locates the first occurrence
> in the string pointed to by s1 of any character from the string pointed to by s2.
> Is there another smaller function to do this in Lisp?
Something like this should work:
(position-if (lambda (c) (find c ".*")) "*string..")
Pascal
--
Pascal Costanza University of Bonn
···············@web.de Institute of Computer Science III
http://www.pascalcostanza.de R�merstr. 164, D-53117 Bonn (Germany)
DaveNlp:
> (DEFUN strpbrk (charray chars)
> (LET* ((lens (LENGTH chars)))
> (DOTIMES (i lens)
> (IF (SEARCH (STRING (CHAR chars i)) charray)
> (RETURN T)))))
> (IF (strpbrk "*string.." ".*")
>
> (print "Characters found.")
> (print "Characters not found."))
> In C, the strpbrk function locates the first occurrence in the
> string pointed to by s1 of any character from the string pointed to
> by s2.
>
> Is there another smaller function to do this in Lisp?
Pascal Costanza:
> Something like this should work:
>
> (position-if (lambda (c) (find c ".*")) "*string..")
Note quite. DaveNlp is looking for a subsequence.
--
"Hurry if you still want to see something. Everything is vanishing."
-- Paul C�zanne (1839-1906)
·····@gmx.net (Wolfhard Bu�) writes:
> DaveNlp:
> > (DEFUN strpbrk (charray chars)
> > (LET* ((lens (LENGTH chars)))
> > (DOTIMES (i lens)
> > (IF (SEARCH (STRING (CHAR chars i)) charray)
> > (RETURN T)))))
> > (IF (strpbrk "*string.." ".*")
> >
> > (print "Characters found.")
> > (print "Characters not found."))
> > In C, the strpbrk function locates the first occurrence in the
> > string pointed to by s1 of any character from the string pointed to
> > by s2.
> >
> > Is there another smaller function to do this in Lisp?
>
> Pascal Costanza:
> > Something like this should work:
> >
> > (position-if (lambda (c) (find c ".*")) "*string..")
>
>
> Note quite. DaveNlp is looking for a subsequence.
>
so just a little wrapper code gives:
(defun strpbrk (s1 s2)
(let ((pos (position-if (lambda (c) (find c s2)) s1)))
(if pos (subseq s1 pos))))
"Jock Cooper" <·····@mail.com> writes:
> >
> > Note quite. DaveNlp is looking for a subsequence.
> >
>
> so just a little wrapper code gives:
>
> (defun strpbrk (s1 s2)
> (let ((pos (position-if (lambda (c) (find c s2)) s1)))
> (if pos (subseq s1 pos))))
Your solution is perfect!,
even if it was not closely necessary. :)
Thanks you very much.
Greetings.
Dave