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

Re: Removing Strings from a list

38 views
Skip to first unread message

WJ

unread,
Mar 19, 2012, 8:56:53 PM3/19/12
to
Pascal Bourguignon wrote:

> (defun delete-strings-from-mylist-and-return-them (mylist)
> (loop
> :for item :in (mylist-elements mylist)
> :if (stringp item) :collect item :into strings
> :else :collect item :into others
> :finally (setf (mylist-elements mylist) others)
> (return strings)))
>
> [53]> (defparameter *ml* (make-mylist :elements (list 1 2 "one" "two" 'one 'two)))
> *ML*
> [54]> (delete-strings-from-mylist-and-return-them *ml*)
> ("one" "two")
> [55]> *ml*
> #S(MYLIST :ELEMENTS (1 2 ONE TWO))

Clojure:

user=> (group-by string? (list 1 2 "one" "two" 'one 'two))
{false [1 2 one two], true ["one" "two"]}

WJ

unread,
Apr 23, 2012, 9:06:53 PM4/23/12
to
WJ wrote:

> Pascal Bourguignon wrote:
>
> > (defun delete-strings-from-mylist-and-return-them (mylist)
> > (loop
> > :for item :in (mylist-elements mylist)
> > :if (stringp item) :collect item :into strings
> > :else :collect item :into others
> > :finally (setf (mylist-elements mylist) others)
> > (return strings)))
> >
> > [53]> (defparameter ml (make-mylist :elements (list 1 2 "one" "two" 'one 'two)))
> > ML
> > [54]> (delete-strings-from-mylist-and-return-them ml)
> > ("one" "two")
> > [55]> ml
> > #S(MYLIST :ELEMENTS (1 2 ONE TWO))
>
> Clojure:
>
> user=> (group-by string? (list 1 2 "one" "two" 'one 'two))
> {false [1 2 one two], true ["one" "two"]}

Racket:

> (partition string? (list 1 2 "one" "two" 'one 'two))
'("one" "two")
'(1 2 one two)


WJ

unread,
Jan 7, 2015, 11:40:53 PM1/7/15
to
WJ wrote:

> Pascal Bourguignon wrote:
>
> > (defun delete-strings-from-mylist-and-return-them (mylist)
> > (loop
> > :for item :in (mylist-elements mylist)
> > :if (stringp item) :collect item :into strings
> > :else :collect item :into others
> > :finally (setf (mylist-elements mylist) others)
> > (return strings)))
> >
> > [53]> (defparameter ml (make-mylist :elements (list 1 2 "one" "two" 'one 'two)))
> > ML
> > [54]> (delete-strings-from-mylist-and-return-them ml)
> > ("one" "two")
> > [55]> ml
> > #S(MYLIST :ELEMENTS (1 2 ONE TWO))

Gauche Scheme:

(partition string? (list 1 2 "one" "two" 'one 'two))
===>

WJ

unread,
Jan 11, 2016, 5:01:30 PM1/11/16
to
Why this is marked as abuse? It has been marked as abuse.
Report not abuse
MatzLisp (Ruby):

["one",2,"three",:four,5].partition{|x| x.is_a? String}
===>
[["one", "three"], [2, :four, 5]]

--
From the New York Times of October 11, 1991, ... we learn that ... researchers
at Boston University admitted that, "There is no question but that Dr. King
plagiarized in the dissertation." ... "Dr. Martin Luther King, Jr." [Michael
King] spent his last night on Earth having sexual intercourse with two women at
the motel and physically beating and abusing a third. -- K. A. Strom
0 new messages