From: Francesco Moi
Subject: Converting a list to a string
Date: 
Message-ID: <5b829932.0111270824.71e26d54@posting.google.com>
Hello.

My name is Francesco. I would like to convert
my list ("Files Program" "Application" "Folder") to
this string: "Files Program>Application>Folder"

Is it possible? I tried with "list-to-string" but
it does not work (Perhaps my interpreter does not
count with "list-to-string")....

From: Drew McDermott
Subject: Re: Converting a list to a string
Date: 
Message-ID: <3C03E65E.94EFEEEA@yale.edu>
--------------FB95520F96388CCDFF7898F4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Francesco Moi wrote:

> Hello.
>
> My name is Francesco. I would like to convert
> my list ("Files Program" "Application" "Folder") to
> this string: "Files Program>Application>Folder"
>
> Is it possible? I tried with "list-to-string" but
> it does not work (Perhaps my interpreter does not
> count with "list-to-string")....

(defun strings->mac-path-name (sl)
   (cond ((null sl) ">")  ;; I'm guessing
         (t
          (reduce #'(lambda (s1 s2)
                       (concatenate
                          'string s1 ">" s2))
                  sl))))

You could be slightly more efficient by avoiding concatenating the same
string over and over, but it's probably not worth it in this
application.

    -- Drew McDermott


--------------FB95520F96388CCDFF7898F4
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Francesco Moi wrote:
<blockquote TYPE=CITE>Hello.
<p>My name is Francesco. I would like to convert
<br>my list ("Files Program" "Application" "Folder") to
<br>this string: "Files Program>Application>Folder"
<p>Is it possible? I tried with "list-to-string" but
<br>it does not work (Perhaps my interpreter does not
<br>count with "list-to-string")....</blockquote>
<tt>(defun strings->mac-path-name (sl)</tt>
<br><tt>&nbsp;&nbsp; (cond ((null sl) ">")&nbsp; ;; I'm guessing</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (t</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (reduce
#'(lambda (s1 s2)</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(concatenate</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
'string s1 ">" s2))</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sl))))</tt><tt></tt>
<p><tt>You could be slightly more efficient by avoiding concatenating the
same string over and over, but it's probably not worth it in this application.</tt><tt></tt>
<p><tt>&nbsp;&nbsp;&nbsp; -- Drew McDermott</tt>
<br><tt></tt>&nbsp;</html>

--------------FB95520F96388CCDFF7898F4--
From: Lieven Marchand
Subject: Re: Converting a list to a string
Date: 
Message-ID: <m3pu64nq29.fsf@localhost.localdomain>
············@europe.com (Francesco Moi) writes:

> Hello.
> 
> My name is Francesco. I would like to convert
> my list ("Files Program" "Application" "Folder") to
> this string: "Files Program>Application>Folder"
> 
> Is it possible? I tried with "list-to-string" but
> it does not work (Perhaps my interpreter does not
> count with "list-to-string")....

Assuming you use Common Lisp, which is the default assumption in this
newsgroup, use format.

(format nil ······@[>~]~}" '("Files Program" "Application" "Folder"))

Otherwise, you will have to be more precise about the Lisp dialect
you're working in.

-- 
Lieven Marchand <···@wyrd.be>
She says, "Honey, you're a Bastard of great proportion."
He says, "Darling, I plead guilty to that sin."
Cowboy Junkies -- A few simple words
From: Tim Bradshaw
Subject: Re: Converting a list to a string
Date: 
Message-ID: <fbc0f5d1.0111280605.53d0570f@posting.google.com>
Lieven Marchand <···@wyrd.be> wrote in message news:<··············@localhost.localdomain>...
> 
> (format nil ······@[>~]~}" '("Files Program" "Application" "Folder"))

I'd do this as "~{~A~^>~}".  I guess it doesn't matter which.  It
doesn't look like homework, does it? if it did I reckon there has to
be a solution involving exploding the strings into lists and then
using a serious lot of line-noise in FORMAT to iterate over the lists
in turn...

(incidentally, I wonder why we don't see so many anti-FORMAT rants as
we do anti-LOOP rants?  If LOOP is hard to read, what is FORMAT?  I
just wrote a report method for a parse error which prints the obvious

Bad thing happened: expecting something but got :END-SET
    "fff,}"
         ^ here

type message, and it's a good half a line of lots-of-tildes.)

--tim
From: Lieven Marchand
Subject: Re: Converting a list to a string
Date: 
Message-ID: <m3elmi7sxe.fsf@localhost.localdomain>
··········@tfeb.org (Tim Bradshaw) writes:

> (incidentally, I wonder why we don't see so many anti-FORMAT rants as
> we do anti-LOOP rants?  If LOOP is hard to read, what is FORMAT?  I
> just wrote a report method for a parse error which prints the obvious
> 
> Bad thing happened: expecting something but got :END-SET
>     "fff,}"
>          ^ here
> 
> type message, and it's a good half a line of lots-of-tildes.)

I think because the esoteric features of FORMAT are less used. 

-- 
Lieven Marchand <···@wyrd.be>
She says, "Honey, you're a Bastard of great proportion."
He says, "Darling, I plead guilty to that sin."
Cowboy Junkies -- A few simple words
From: Erik Naggum
Subject: Re: Converting a list to a string
Date: 
Message-ID: <3215958628245501@naggum.net>
* Tim Bradshaw
| incidentally, I wonder why we don't see so many anti-FORMAT rants as
| we do anti-LOOP rants?  If LOOP is hard to read, what is FORMAT?

  It is because loop is actually _too_ easy to read and does unexpected
  things for those who do not understand that it is a formal language.  In
  contrast to this, format is pure magic and not understood by the whiners.

///
-- 
  The past is not more important than the future, despite what your culture
  has taught you.  Your future observations, conclusions, and beliefs are
  more important to you than those in your past ever will be.  The world is
  changing so fast the balance between the past and the future has shifted.
From: Tim Bradshaw
Subject: Re: Converting a list to a string
Date: 
Message-ID: <fbc0f5d1.0111290641.69a67335@posting.google.com>
Erik Naggum <····@naggum.net> wrote in message news:<················@naggum.net>...
> * Tim Bradshaw
> | incidentally, I wonder why we don't see so many anti-FORMAT rants as
> | we do anti-LOOP rants?  If LOOP is hard to read, what is FORMAT?
> 
>   It is because loop is actually _too_ easy to read and does unexpected
>   things for those who do not understand that it is a formal language.  In
>   contrast to this, format is pure magic and not understood by the whiners.

I can feel a macro coming on here...  Erm, say:

  (� // x >= 1 < 10 & // y = (* x 2)
     ? (evenp x) => ! (print x)
     ? (oddp x) => ! (print (* x y))
     _ ^ 3)

It's not really obscure enough, I guess.
From: Gareth McCaughan
Subject: Re: Converting a list to a string
Date: 
Message-ID: <slrna0dah6.2dab.Gareth.McCaughan@g.local>
Tim Bradshaw wrote:

> I can feel a macro coming on here...  Erm, say:
> 
>   (� // x >= 1 < 10 & // y = (* x 2)
>      ? (evenp x) => ! (print x)
>      ? (oddp x) => ! (print (* x y))
>      _ ^ 3)
> 
> It's not really obscure enough, I guess.

No, but it might just fit right in to Paul Graham's new
dialect. *That*'s why he had such an impoverished set of
looping constructs: he was waiting for � to come along!

-- 
Gareth McCaughan  ················@pobox.com
.sig under construc
From: Francesco Moi
Subject: Re: Converting a list to a string
Date: 
Message-ID: <5b829932.0111280817.4f1f2fcd@posting.google.com>
Hi. Thank you for answering.

If I try what you suggest, I get:

LISP error:
Format error: arguments exhausted.
          V
······@[>~]~}"
---------------------------

Lieven Marchand <···@wyrd.be> wrote in message news:<··············@localhost.localdomain>...
> ············@europe.com (Francesco Moi) writes:
> 
> > Hello.
> > 
> > My name is Francesco. I would like to convert
> > my list ("Files Program" "Application" "Folder") to
> > this string: "Files Program>Application>Folder"
> > 
> > Is it possible? I tried with "list-to-string" but
> > it does not work (Perhaps my interpreter does not
> > count with "list-to-string")....
> 
> Assuming you use Common Lisp, which is the default assumption in this
> newsgroup, use format.
> 
> (format nil ······@[>~]~}" '("Files Program" "Application" "Folder"))
> 
> Otherwise, you will have to be more precise about the Lisp dialect
> you're working in.
From: Lieven Marchand
Subject: Re: Converting a list to a string
Date: 
Message-ID: <m3here7t0v.fsf@localhost.localdomain>
············@europe.com (Francesco Moi) writes:

> Hi. Thank you for answering.
> 
> If I try what you suggest, I get:
> 
> LISP error:
> Format error: arguments exhausted.
>           V
> ······@[>~]~}"
> ---------------------------
> 

If you've entered it correctly it should work.

Lispworks/Linux:

CL-USER 1 > (format nil ······@[>~]~}" '("Files Program" "Application" "Folder"))
"Files Program>Application>Folder"

Allegro/Linux:

USER(1): (format nil ······@[>~]~}" '("Files Program" "Application" "Folder"))
"Files Program>Application>Folder"

What implementation are you using?

-- 
Lieven Marchand <···@wyrd.be>
She says, "Honey, you're a Bastard of great proportion."
He says, "Darling, I plead guilty to that sin."
Cowboy Junkies -- A few simple words
From: Pierre R. Mai
Subject: Re: Converting a list to a string
Date: 
Message-ID: <871yiileol.fsf@orion.bln.pmsf.de>
Lieven Marchand <···@wyrd.be> writes:

> If you've entered it correctly it should work.
> 
> Lispworks/Linux:
> 
> CL-USER 1 > (format nil ······@[>~]~}" '("Files Program" "Application" "Folder"))
> "Files Program>Application>Folder"
> 
> Allegro/Linux:
> 
> USER(1): (format nil ······@[>~]~}" '("Files Program" "Application" "Folder"))
> "Files Program>Application>Folder"
> 
> What implementation are you using?

All of CMU CL, CLISP and ECLS have problems with the format control as
given.  As it stands, I fail to see why it should work the way you
think it should.  Quoting from Section 22.3.7.2 Tilde Left-Bracket:
Conditional Expression:

  ··@[consequent~] tests the argument. If it is true, then the
  argument is not used up by the ~[ command but remains as the next
  one to be processed, and the one clause consequent is processed. If
  the arg is false , then the argument is used up, and the clause is
  not processed. The clause therefore should normally use exactly one
  argument, and may expect it to be non-nil."

At the end of the list, only one argument remains, which is consumed
by the ~A.  Therefore no argument remains that could be tested for the
·@[>~] directive, and hence an error is signalled.

If my interpretation is correct, then no implementation is required to
work the way you expect it to work.  If you think otherwise, I'd be
interested in the reasoning behind your expectation.

Regs, Pierre.

-- 
Pierre R. Mai <····@acm.org>                    http://www.pmsf.de/pmai/
 The most likely way for the world to be destroyed, most experts agree,
 is by accident. That's where we come in; we're computer professionals.
 We cause accidents.                           -- Nathaniel Borenstein
From: Lieven Marchand
Subject: Re: Converting a list to a string
Date: 
Message-ID: <m3itbtjpjh.fsf@localhost.localdomain>
"Pierre R. Mai" <····@acm.org> writes:

> If my interpretation is correct, then no implementation is required to
> work the way you expect it to work.  If you think otherwise, I'd be
> interested in the reasoning behind your expectation.

Thanks for setting me straight. I think you're right. I've constructed
this from memory without checking the spec and got misled by the
behaviour of both implementations. Grepping through my code showed a
few places where I'd done this. Earlier in the thread someone gave the
correct ~^ solution.

-- 
Lieven Marchand <···@wyrd.be>
She says, "Honey, you're a Bastard of great proportion."
He says, "Darling, I plead guilty to that sin."
Cowboy Junkies -- A few simple words
From: Tijs van Bakel
Subject: Re: Converting a list to a string
Date: 
Message-ID: <lum7ksci0md.fsf@dutiaw13.twi.tudelft.nl>
············@europe.com (Francesco Moi) writes:

> My name is Francesco. I would like to convert
> my list ("Files Program" "Application" "Folder") to
> this string: "Files Program>Application>Folder"
> 
> Is it possible? I tried with "list-to-string" but
> it does not work (Perhaps my interpreter does not
> count with "list-to-string")....

I have never heard of list-to-string.  Is it Common Lisp you are
using?  If so, the following uses functions that you can all find back
in the HyperSpec:

(reduce #'(lambda (x y)
	    (concatenate 'string x ">" y))
	'("Files Program" "Application" "Folder"))

Hope this helps, and does not spoil any homework.

--
Tijs van Bakel, <·····@wanadoo.nl>