From: Tin Gherdanarra
Subject: split-sequence
Date: 
Message-ID: <41ianvF1e79scU1@individual.net>
On cliki and in the cl-cookbook I read that
split-sequence:split-sequence is used to
uhm, to split a sequence. The examples show
how it is used to split along a single element,
like this:

(split-sequence:split-sequence #\Space "just whisper 'wermuth'")
gives
("just" "whisper" "wermuth")
22

Is there a way to put split-sequence to work that
it can split a sequence along another sequence,
like this:

(split:sequence:split-sequence "spam" "We have spam we have spam and spam")
shall give
("We have" "we have" "and")

I tried all sorts of args and options, to no avail.
My guess is that split-sequence is not made for this.


An unrelated question:

I miss python's ability to format a /dictionary/ by
passing it together with a format string to a formatter,
like this:

# dictionary "mydict" contains
'title' : 'at swim two birds',
'author' : 'flann o brien',
'condition' : 'hardcover, minted'
'price' : '$ 2.50'

print """
<h3>%(title)s</h3>
<h4>%(author)s</h4>
<u>CONDITION: <u>%(condition)s<br />
<b>PRICE: </b>%(price)s
""" % mydict

gives

<h3>at swim two birds</h3>
<h4>flann o brien</h4>
<u>CONDITION: <u>hardcover, minted<br />
<b>PRICE: </b>$ 2.50

Maybe it can be done with an assoc-list
and clever format-string tricks, but
I have not found it on the web.

Thanks for your attention, what would I do without you?

Tin

From: Paolo Amoroso
Subject: Re: split-sequence
Date: 
Message-ID: <87acek6iy4.fsf@plato.moon.paoloamoroso.it>
Tin Gherdanarra <···········@gmail.com> writes:

> An unrelated question:
>
> I miss python's ability to format a /dictionary/ by
> passing it together with a format string to a formatter,
> like this:
>
> # dictionary "mydict" contains
> 'title' : 'at swim two birds',
> 'author' : 'flann o brien',
> 'condition' : 'hardcover, minted'
> 'price' : '$ 2.50'
>
> print """
> <h3>%(title)s</h3>
> <h4>%(author)s</h4>
> <u>CONDITION: <u>%(condition)s<br />
> <b>PRICE: </b>%(price)s
> """ % mydict
>
> gives
>
> <h3>at swim two birds</h3>
> <h4>flann o brien</h4>
> <u>CONDITION: <u>hardcover, minted<br />
> <b>PRICE: </b>$ 2.50

This might help:

  CL-INTERPOL - string interpolation for Common Lisp
  http://weitz.de/cl-interpol/


Paolo
-- 
Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
Recommended Common Lisp libraries/tools:
- ASDF/ASDF-INSTALL: system building/installation
- CL-PPCRE: regular expressions
- CFFI: Foreign Function Interface
From: justinhj
Subject: Re: split-sequence
Date: 
Message-ID: <1135874537.504798.124120@z14g2000cwz.googlegroups.com>
Paolo Amoroso wrote:
> Tin Gherdanarra <···········@gmail.com> writes:
>
> > An unrelated question:
> >
> > I miss python's ability to format a /dictionary/ by
> > passing it together with a format string to a formatter,
> > like this:
> >
> > # dictionary "mydict" contains
> > 'title' : 'at swim two birds',
> > 'author' : 'flann o brien',
> > 'condition' : 'hardcover, minted'
> > 'price' : '$ 2.50'
> >
> > print """
> > <h3>%(title)s</h3>
> > <h4>%(author)s</h4>
> > <u>CONDITION: <u>%(condition)s<br />
> > <b>PRICE: </b>%(price)s
> > """ % mydict
> >
> > gives
> >
> > <h3>at swim two birds</h3>
> > <h4>flann o brien</h4>
> > <u>CONDITION: <u>hardcover, minted<br />
> > <b>PRICE: </b>$ 2.50
>
> This might help:
>
>   CL-INTERPOL - string interpolation for Common Lisp
>   http://weitz.de/cl-interpol/
>
>
> Paolo
> --
> Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
> Recommended Common Lisp libraries/tools:
> - ASDF/ASDF-INSTALL: system building/installation
> - CL-PPCRE: regular expressions
> - CFFI: Foreign Function Interface#

I needed something like this recently, this is a slightly modified
version of one I found by google searching this news group and does
what you are asking for...

The original was by Frank Bus I think. I've changed it so it strips
leading spaces each item (the original did that too, but not the last
item in the list)

(defun split(string delimiter)
  (let ((start (search delimiter string)))
    (if (not start)
        (if (= 0 (length string))
            nil
          (list (string-trim '(#\Space) string)))
      (let ((value (string-trim '(#\Space) (subseq string 0 start)))
            (rest (subseq string (+ start (length delimiter)))))
        (if (= 0 (length value))
            (split rest delimiter)
          (cons value (split rest delimiter)))))))

CL-USER> (split "A test string with the word spam in it, although I
don't like spam much, spam attack, yeargh!  spam yuk" "spam")
("A test string with the word" "in it, although I don't like" "much,"
"attack, yeargh!" "yuk")
CL-USER>
From: Brian Downing
Subject: Re: split-sequence
Date: 
Message-ID: <ogatf.443837$084.25765@attbi_s22>
In article <························@z14g2000cwz.googlegroups.com>,
justinhj <········@gmail.com> wrote:
> The original was by Frank Bus I think. I've changed it so it strips
> leading spaces each item (the original did that too, but not the last
> item in the list)
> 
> (defun split(string delimiter)
>   (let ((start (search delimiter string)))
>     (if (not start)
>         (if (= 0 (length string))
>             nil
>           (list (string-trim '(#\Space) string)))
>       (let ((value (string-trim '(#\Space) (subseq string 0 start)))
>             (rest (subseq string (+ start (length delimiter)))))
>         (if (= 0 (length value))
>             (split rest delimiter)
>           (cons value (split rest delimiter)))))))

More loopy, less consy, and will work on any kind of sequence if you
don't provide the :string-trim keyword:

(defun split-sequence-subsequence (subsequence sequence &key string-trim)
  (loop for last = 0 then (+ pos (length subsequence))
        for pos = (search subsequence sequence :start2 last)
        for subseq = (subseq sequence last (or pos (length sequence)))
        when string-trim do (setf subseq (string-trim string-trim subseq))
        unless (zerop (length subseq)) collect subseq
        while pos))

-bcd
-- 
*** Brian Downing <bdowning at lavos dot net> 
From: Edi Weitz
Subject: Re: split-sequence
Date: 
Message-ID: <uoe30djmw.fsf@agharta.de>
On Thu, 29 Dec 2005 15:39:45 +0100, Tin Gherdanarra <···········@gmail.com> wrote:

> Is there a way to put split-sequence to work that it can split a
> sequence along another sequence, like this:
>
> (split:sequence:split-sequence "spam" "We have spam we have spam and spam")
> shall give
> ("We have" "we have" "and")

For strings you can use this:

  <http://weitz.de/cl-ppcre/#split>

A fork (probably not in sync with the current version) of CL-PPCRE
which can work on arbitrary sequences was announced here:

  <http://common-lisp.net/pipermail/climacs-devel/2005-May/000210.html>

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Pascal Bourguignon
Subject: Re: split-sequence
Date: 
Message-ID: <87bqyz2fot.fsf@thalassa.informatimago.com>
Tin Gherdanarra <···········@gmail.com> writes:

> On cliki and in the cl-cookbook I read that
> split-sequence:split-sequence is used to
> uhm, to split a sequence. The examples show
> how it is used to split along a single element,
> like this:
>
> (split-sequence:split-sequence #\Space "just whisper 'wermuth'")
> gives
> ("just" "whisper" "wermuth")
> 22


Either you've got a strange split-sequence, or you don't know how to
copy-and-paste:

[159]> (split-sequence:split-sequence #\Space "just whisper 'wermuth'")
("just" "whisper" "'wermuth'") ;
22
>
> Is there a way to put split-sequence to work that
> it can split a sequence along another sequence,
> like this:
>
> (split:sequence:split-sequence "spam" "We have spam we have spam and spam")
> shall give
> ("We have" "we have" "and")

No, this will give an error:

[160]> (split:sequence:split-sequence "spam" "We have spam we have spam and spam")

*** - READ from
       #<INPUT CONCATENATED-STREAM #<INPUT STRING-INPUT-STREAM>
         #<IO TERMINAL-STREAM>>
      : too many colons in token "split:sequence:split-sequence"
The following restarts are available:
ABORT          :R1      ABORT
Break 1 [161]> :q


> I tried all sorts of args and options, to no avail.
> My guess is that split-sequence is not made for this.

Indeed, split sequence is not made for this.

A string is a sequence of CHARACTERS, not a sequence of substrings.

> [...]

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

READ THIS BEFORE OPENING PACKAGE: According to certain suggested
versions of the Grand Unified Theory, the primary particles
constituting this product may decay to nothingness within the next
four hundred million years.