From: David Douthitt
Subject: Using concat and lists
Date: 
Message-ID: <ce64i8$87g$1@grandcanyon.binc.net>
I'm trying to do something like this:

(concatenate 'string
   (format nil ....)
   (mapcar #'funca listx)
   (format nil ....)
   (mapcar #'funcb listx)
    ...)

However, the result given to concatenate is:

(concatenate 'string
    " abc.... "
    ("abc" "def" "ghi" ... )
    "jkl"
    ("mno" "pqr" ...)
    ....)

What it looks like I need is a function thus:

    (f '(a b c d e f)) ==> a b c d e f

I tried values, but on a "function return" it only gives the first 
value, not a sequence.  I tried using cons to combine the first string 
value with the list, but that returns a list, not a sequence.

Am I going down the wrong path here?  I was hoping to avoid a dozen setq 
and something like two dozen concatenate calls....

From: David Douthitt
Subject: Re: Using concat and lists
Date: 
Message-ID: <ce64ps$87g$3@grandcanyon.binc.net>
David Douthitt wrote:

> I'm trying to do something like this:

I forgot to mention: I'm using SBCL 0.8.9 on GNU/Linux for i386, and am 
using CLtL2 as a reference.
From: Pascal Bourguignon
Subject: Re: Using concat and lists
Date: 
Message-ID: <87u0vt9vsw.fsf@thalassa.informatimago.com>
David Douthitt <·····@mailbag.com> writes:

> David Douthitt wrote:
> 
> > I'm trying to do something like this:
> 
> I forgot to mention: I'm using SBCL 0.8.9 on GNU/Linux for i386, and
> am using CLtL2 as a reference.

Rather use CLHS as a refernce!
http://www.lispworks.com/reference/HyperSpec/Front/index.htm

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

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein
From: David Douthitt
Subject: Re: Using concat and lists
Date: 
Message-ID: <ce68gv$93f$2@grandcanyon.binc.net>
Pascal Bourguignon wrote:

> David Douthitt <·····@mailbag.com> writes:

>>I forgot to mention: I'm using SBCL 0.8.9 on GNU/Linux for i386, and
>>am using CLtL2 as a reference.

> Rather use CLHS as a refernce!
> http://www.lispworks.com/reference/HyperSpec/Front/index.htm

And where can I buy a bound paper copy for $6 like I did the CLtL2?

I prefer paper docs....
From: Alex Mizrahi
Subject: Re: Using concat and lists
Date: 
Message-ID: <2mntlgFofi6mU1@uni-berlin.de>
(message (Hello 'David)
(you :wrote  :on '(Tue, 27 Jul 2004 13:57:11 -0500))
(

 >> Rather use CLHS as a refernce!
 >> http://www.lispworks.com/reference/HyperSpec/Front/index.htm

 DD> And where can I buy a bound paper copy for $6 like I did the CLtL2?

 DD> I prefer paper docs....

nice thing in hyperspec that it can be used as online help - it has an index
and some editors can find symbols in it..
for example, if i need info about format i type in in editor (xemacs with
slime) format - just in open text file (or maybe it's already written if i'm
reading some code) - and press a key - and it opens documentation for
format. it's a hypertext(html), so it's easy to find relating information.
(lispworks has hyperspec search function too).
can you find information in your printed docs so fast? 8-]

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
(prin1 "Jane dates only Lisp programmers"))
From: David Douthitt
Subject: Re: Using concat and lists
Date: 
Message-ID: <ce6pb3$dar$2@grandcanyon.binc.net>
Alex Mizrahi wrote:

> (message (Hello 'David)
> (you :wrote  :on '(Tue, 27 Jul 2004 13:57:11 -0500))
> (
> 
>  >> Rather use CLHS as a refernce!
>  >> http://www.lispworks.com/reference/HyperSpec/Front/index.htm
> 
>  DD> And where can I buy a bound paper copy for $6 like I did the CLtL2?
> 
>  DD> I prefer paper docs....
> 
> nice thing in hyperspec that it can be used as online help - it has an index
> and some editors can find symbols in it..

> can you find information in your printed docs so fast? 8-]

Turn the computer off, or enter your local subway/bus system.  Now try 
looking things up ;-)

Also, when you look things up on the computer, your source has "gone 
away" and is no longer visible...
From: Alex Mizrahi
Subject: Re: Using concat and lists
Date: 
Message-ID: <2mod03FolehbU1@uni-berlin.de>
(message (Hello 'David)
(you :wrote  :on '(Tue, 27 Jul 2004 18:44:14 -0500))
(

 >> nice thing in hyperspec that it can be used as online help - it has
 >> an index and some editors can find symbols in it..

 >> can you find information in your printed docs so fast? 8-]

 DD> Turn the computer off,

i have it always on

 DD>  or enter your local subway/bus system.  Now try  looking things up ;-)

i don't think i will ever need to check some function documentation when not
writting programs..

if it was some interesting readable book(CLtL is more like this).. maybe..
but i don't read paper computer books - last one was about Turbo Pascal 6
years ago, i think.. 8-]

 DD> Also, when you look things up on the computer, your source has "gone
 DD> away" and is no longer visible...

why? there are such things as windows - i can move window with doc, or open
it in separate subwindow of xemacs so everything is visible..
however i rarely need to see both doc and source - possibly my "mind buffer"
is big enough so i can cache them there 8-]

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
(prin1 "Jane dates only Lisp programmers"))
From: Raymond Toy
Subject: Re: Using concat and lists
Date: 
Message-ID: <sxdd62g1dmf.fsf@edgedsp4.rtp.ericsson.se>
>>>>> "David" == David Douthitt <·····@mailbag.com> writes:

    David> Pascal Bourguignon wrote:

    >> David Douthitt <·····@mailbag.com> writes:

    >>> I forgot to mention: I'm using SBCL 0.8.9 on GNU/Linux for i386, and
    >>> am using CLtL2 as a reference.

    >> Rather use CLHS as a refernce!
    >> http://www.lispworks.com/reference/HyperSpec/Front/index.htm

    David> And where can I buy a bound paper copy for $6 like I did the CLtL2?

    David> I prefer paper docs....

Get a copy from ANSI.  I heard it was $18 and you get a crappy scan of
the doc.

Ray
From: David Douthitt
Subject: Re: Using concat and lists
Date: 
Message-ID: <ce99hl$2g7$1@grandcanyon.binc.net>
Raymond Toy wrote:

> Get a copy from ANSI.  I heard it was $18 and you get a crappy scan of
> the doc.

Aside from the appeal of that - the spec isn't exactly readable, but oh 
well.

Is it available as a PDF?  Is there discounts for USENIX members?  Does 
USENIX offer it?  Does ALU offer it?

In comparing such books, I'd much rather have books like O'Reilly's 
"Camel Book" (for Perl) or the "Pick-Axe Book" (for Ruby) which are used 
as definitive sources of learning the specified language in their 
domains - alternatives like K&R for C and the ANSI LISP standard are 
unnecessarily hard to read, seems to me.
From: Edi Weitz
Subject: Re: Using concat and lists
Date: 
Message-ID: <87brhz5sxe.fsf@bird.agharta.de>
On Wed, 28 Jul 2004 17:33:19 -0500, David Douthitt <·····@mailbag.com> wrote:

> In comparing such books, I'd much rather have books like O'Reilly's
> "Camel Book" (for Perl) or the "Pick-Axe Book" (for Ruby) which are
> used as definitive sources of learning the specified language in
> their domains - alternatives like K&R for C and the ANSI LISP
> standard are unnecessarily hard to read, seems to me.

I agree that the Camel Book is nicer to read than the CL spec but
there's a big difference because Common Lisp is a programming language
standardized by ANSI while Perl is a single-implementation language
defined by this very implementation. It's easy to write a "reference"
book if you only have to refer to this one implementation, especially
if you're the author of the language. You'll note, though, that the
Camel Book will only serve as a halfway-decent reference if you happen
to use the correct Perl release, and even then there are a lot of
things that are left unspecified and can only be found out by
experimenting.

Cheers,
Edi.

-- 

"Lisp doesn't look any deader than usual to me."
(David Thornley, reply to a question older than most languages)

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Raymond Toy
Subject: Re: Using concat and lists
Date: 
Message-ID: <sxdk6wmygpx.fsf@edgedsp4.rtp.ericsson.se>
>>>>> "David" == David Douthitt <·····@mailbag.com> writes:

    David> Raymond Toy wrote:

    >> Get a copy from ANSI.  I heard it was $18 and you get a crappy scan of
    >> the doc.

    David> Aside from the appeal of that - the spec isn't exactly readable, but
    David> oh well.

    David> Is it available as a PDF?  Is there discounts for USENIX members?
    David> Does USENIX offer it?  Does ALU offer it?

Don't know.  Once I found out it was a crappy scan, I lost interest.
But if it were a nice book, I would have easily paid 2 or 3 times that
much for a paper copy.  Too bad for them.

    David> domains - alternatives like K&R for C and the ANSI LISP standard are
    David> unnecessarily hard to read, seems to me.

Standards docs aren't meant to be tutorials.  Use a tutorial for
that. :-)

Ray
From: Christopher C. Stacy
Subject: Re: Using concat and lists
Date: 
Message-ID: <u3c3a7ngt.fsf@news.dtpq.com>
>>>>> On Wed, 28 Jul 2004 17:33:19 -0500, David Douthitt ("David") writes:

 David> Raymond Toy wrote:
 >> Get a copy from ANSI.  I heard it was $18 and you get a crappy scan of
 >> the doc.

 David> In comparing such books

The ANSI CL spec is not any kind of tutorial or manual.
You're comparing two different kinds of things.
From: Thomas A. Russ
Subject: Re: Using concat and lists
Date: 
Message-ID: <ymi1xixdsbz.fsf@sevak.isi.edu>
David Douthitt <·····@mailbag.com> writes:

> 
> I'm trying to do something like this:
> 
> (concatenate 'string
>    (format nil ....)
>    (mapcar #'funca listx)
>    (format nil ....)
>    (mapcar #'funcb listx)
>     ...)

Um, if you're already willing to use format to produce the strings, why
not do the entire thing using format?  It has some nice facilities for
iterating over list elements and formatting them as well.  Then you
won't need to deal with the concatenation at all:

(format nil "... ~{~A~} ... ~{~A~} ..."
            (mapcar #'funca listx)
            (mapcar #'funcb listx))


For example:

   (format nil "~{~A~}" '(a b c d))   =>  "ABCD"
   (format nil "~{~A ~}" '(a b c d))   =>  "A B C D "
   (format nil "~{~A~^ ~}" '(a b c d))   =>  "A B C D"  ; no trailing space

and much more.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: David Douthitt
Subject: Re: Using concat and lists
Date: 
Message-ID: <ce6pjc$dff$1@grandcanyon.binc.net>
Thomas A. Russ wrote:

> David Douthitt <·····@mailbag.com> writes:
> 
> 
>>I'm trying to do something like this:
>>
>>(concatenate 'string
>>   (format nil ....)
>>   (mapcar #'funca listx)
>>   (format nil ....)
>>   (mapcar #'funcb listx)
>>    ...)
> 
> 
> Um, if you're already willing to use format to produce the strings, why
> not do the entire thing using format?  It has some nice facilities for
> iterating over list elements and formatting them as well.  Then you
> won't need to deal with the concatenation at all:
> 
> (format nil "... ~{~A~} ... ~{~A~} ..."
>             (mapcar #'funca listx)
>             (mapcar #'funcb listx))
> 
> 
> For example:
> 
>    (format nil "~{~A~}" '(a b c d))   =>  "ABCD"
>    (format nil "~{~A ~}" '(a b c d))   =>  "A B C D "
>    (format nil "~{~A~^ ~}" '(a b c d))   =>  "A B C D"  ; no trailing space
> 
> and much more.

MUCH more... ;-)

The problem I was having was a classic one: insert a comma BETWEEN 
entries, and insert a " and " clause BETWEEN entries.  But with:

(format nil "~{~a ~^ and ~}" listx)

It works!  Not only that, but I wanted to be able to use a list member 
multiple times.  To do that, I did something like:

(format nil "~{~a + ~:*~a ~^ and ~}" listx)

which incorporates the previous example as well.  It's a bit arbitrary, 
but you get the idea.  WOW!  LISP's format function has quite an arcane 
syntax, but it is much more powerful than C's printf.  Reminds me of 
TECO ;-)
From: Pascal Bourguignon
Subject: Re: Using concat and lists
Date: 
Message-ID: <87y8l59vuo.fsf@thalassa.informatimago.com>
David Douthitt <·····@mailbag.com> writes:

> I'm trying to do something like this:
> 
> (concatenate 'string
>    (format nil ....)
>    (mapcar #'funca listx)
>    (format nil ....)
>    (mapcar #'funcb listx)
>     ...)
> 
> However, the result given to concatenate is:
> 
> (concatenate 'string
>     " abc.... "
>     ("abc" "def" "ghi" ... )
>     "jkl"
>     ("mno" "pqr" ...)
>     ....)
> 
> What it looks like I need is a function thus:
> 
>     (f '(a b c d e f)) ==> a b c d e f
> 
> I tried values, but on a "function return" it only gives the first
> value, not a sequence.  I tried using cons to combine the first string
> value with the list, but that returns a list, not a sequence.
> 
> Am I going down the wrong path here?  I was hoping to avoid a dozen
> setq and something like two dozen concatenate calls....

Use APPLY:

(apply (function concantenate) 'string
    (append (list (format nil ....))
            (mapcar (function funca) listx)
            (list (format nil ....))
            (mapcar (function funcb) listx)
            ....))

In other cases, you may want to use MAPCAN:

(apply (function concantenate) 'string
    (mapcan (lambda (item)
                (cond
                 ((symbolp item)  (list item))
                 ((listp item)    (mapcar (lambda (subitem) ...) item))
                 (t               nil)))
            (append 'stuff listx 'barfoo listx 42)))


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

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein
From: David Douthitt
Subject: Re: Using concat and lists
Date: 
Message-ID: <ce68cq$93f$1@grandcanyon.binc.net>
Pascal Bourguignon wrote:

> David Douthitt <·····@mailbag.com> writes:
> 
> 
>>I'm trying to do something like this:
>>
>>(concatenate 'string
>>   (format nil ....)
>>   (mapcar #'funca listx)
>>   (format nil ....)
>>   (mapcar #'funcb listx)
>>    ...)

> Use APPLY:
> 
> (apply (function concantenate) 'string
>     (append (list (format nil ....))
>             (mapcar (function funca) listx)
>             (list (format nil ....))
>             (mapcar (function funcb) listx)
>             ....))

Won't this try to apply the function concatenate to a symbol "string"?

I found another thread on concatenating strings, and wound up using 
with-output-to-string and format with all of its power to do everything 
in a single format call (!).  Got rid of concatenate altogether!

I used ~{ ~} to provide looping across a list, then ~^ to prevent extra 
commas or "and" connectors, and ~:* to backup on element in the list on 
occasion.  Worked quite well, and shortened the code drastically....!
From: Brian Downing
Subject: Re: Using concat and lists
Date: 
Message-ID: <WfBNc.171326$%_6.19360@attbi_s01>
In article <············@grandcanyon.binc.net>,
David Douthitt  <·····@mailbag.com> wrote:
> I found another thread on concatenating strings, and wound up using 
> with-output-to-string and format with all of its power to do everything 
> in a single format call (!).  Got rid of concatenate altogether!
> 
> I used ~{ ~} to provide looping across a list, then ~^ to prevent extra 
> commas or "and" connectors, and ~:* to backup on element in the list on 
> occasion.  Worked quite well, and shortened the code drastically....!

This may be a silly question, but if you got everything down to one format
call, why did you need with-output-to-string at all?  Just (format nil ...)
should work fine.

-bcd
-- 
*** Brian Downing <bdowning at lavos dot net> 
From: David Douthitt
Subject: Re: Using concat and lists
Date: 
Message-ID: <ce6p6e$dar$1@grandcanyon.binc.net>
Brian Downing wrote:

> In article <············@grandcanyon.binc.net>,
> David Douthitt  <·····@mailbag.com> wrote:

> This may be a silly question, but if you got everything down to one format
> call, why did you need with-output-to-string at all?  Just (format nil ...)
> should work fine.

Slap! Doh!

That IS a silly question.... silly of me for not recognizing that.... :-O
From: Kalle Olavi Niemitalo
Subject: Re: Using concat and lists
Date: 
Message-ID: <87smbdcn3z.fsf@Astalo.kon.iki.fi>
David Douthitt <·····@mailbag.com> writes:

> I'm trying to do something like this:
>
> (concatenate 'string
>    (format nil ....)
>    (mapcar #'funca listx)
>    (format nil ....)
>    (mapcar #'funcb listx)
>     ...)

where funca and funcb return strings.
I can think of several ways to do this.

1. String stream.

  (with-output-to-string (stream)
    (format stream ...)
    (dolist (elt listx) (write-string (funca elt) stream))
    (format stream ...)
    (dolist (elt listx) (write-string (funcb elt) stream))
    ...)

2. Build shorter strings with APPLY.
This assumes (< (+ 1 (length listx)) call-arguments-limit).

  (concatenate 'string
    (format nil ...)
    (apply #'concatenate 'string (mapcar #'funca listx))
    (format nil ...)
    (apply #'concatenate 'string (mapcar #'funcb listx))
    ...)

3. Build shorter strings with REDUCE.
I suppose this generates more garbage than APPLY.

  (flet ((concatenate-string (&rest args)
           (apply #'concatenate 'string args)))
    (concatenate 'string
      (format nil ...)
      (reduce #'concatenate-string listx :key #'funca)
      (format nil ...)
      (reduce #'concatenate-string listx :key #'funcb)
      ...))

I think I'd first try a string stream and see if it's good
enough, then examine other schemes if not.
From: Alex Mizrahi
Subject: Re: Using concat and lists
Date: 
Message-ID: <2mnmosFop1ujU1@uni-berlin.de>
(message (Hello 'David)
(you :wrote  :on '(Tue, 27 Jul 2004 12:49:35 -0500))
(

 DD> Am I going down the wrong path here?  I was hoping to avoid a dozen
 DD> setq  and something like two dozen concatenate calls....

i think you can use #'format here
(format nil "~{~A~}" (list "a" "b" "c"))
"abc"
so you can have only one format function call with appropriate format-string
and feed it with all your data and lists..

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
(prin1 "Jane dates only Lisp programmers"))