list->string question 
Author Message
 list->string question

Quote:

> I thought (list->string '(bla bla bla)) would return "bla bla bla" but
> it seems not to be case. How can i easily do this ?

Firstly, "list->string" only works with a list of CHARACTERS (I had a
similar question a while back.) So you need to do something like:

(define x (list (\#b \#l \#a \# \#b....)))

then

(list->string x) ==> "bla bla bla"

Secondly '(bla bla bla) is not a list. So list->string will throw a
wobbly when it sees this.

Hope this helps.

--
Johnny Ooi. Aliases: Loopy, Tuxedo Mask, Quote Master.....

WWW             : http://www.*-*-*.com/ ~jjyooi/
ICQ No          : 6155774

"Stay sane guys!"

===============================================================



Fri, 05 Apr 2002 03:00:00 GMT  
 list->string question
: I thought (list->string '(bla bla bla)) would return "bla bla bla" but
: it seems not to be case. How can i easily do this ?

You must map a symbol->string operation over the list to make strings
out of the symbols, and then apply a string-append operation on the
list.

Dirk van Deun                         Ceterum censeo Redmond delendum
--


--
Knight of the Order of the Command Line  ---  http://knights.rave.org



Fri, 05 Apr 2002 03:00:00 GMT  
 list->string question


Quote:
>Secondly '(bla bla bla) is not a list. So list->string will throw a
>wobbly when it sees this.

You started out OK, but then you threw in this paragraph, which is totally
wrong.  (bla bla bla) certainly *is* a list.  It's a list of three symbols.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



Fri, 05 Apr 2002 03:00:00 GMT  
 list->string question

Quote:



> >Secondly '(bla bla bla) is not a list. So list->string will throw a
> >wobbly when it sees this.

> You started out OK, but then you threw in this paragraph, which is totally
> wrong.  (bla bla bla) certainly *is* a list.  It's a list of three symbols.

Fred wrote this:

Quote:
> > (list->string '(bla bla bla))

Now the "'" means quote (e.g. String) so '(bla bla bla) will be treated
as the string "(bla bla bla)" and not a list (bla bla bla) so Scheme
will complain. Or am I wrong? I still consider myself to me an amateur
at all this....

Johnny



Sun, 07 Apr 2002 03:00:00 GMT  
 list->string question

Quote:
>: I thought (list->string '(bla bla bla)) would return "bla bla bla" but
>: it seems not to be case. How can i easily do this ?

>You must map a symbol->string operation over the list to make strings
>out of the symbols, and then apply a string-append operation on the
>list.

That returns "blablabla".  If he wants the spaces, they'll have to be
added.

If you want a function that takes '(bla bla bla) and returns "(bla bla
bla)", see if your Scheme handles output to a string port.  This works
in DrScheme:

(define (stringify obj)
  (let ((o (open-output-string)))
    (display obj o)
    (get-output-string o)))

(stringify '(bla bla bla))
   =>   "(bla bla bla)"

Is this a homework problem?



Sun, 07 Apr 2002 03:00:00 GMT  
 list->string question


Quote:



>> >Secondly '(bla bla bla) is not a list. So list->string will throw a
>> >wobbly when it sees this.

>> You started out OK, but then you threw in this paragraph, which is totally
>> wrong.  (bla bla bla) certainly *is* a list.  It's a list of three symbols.

>Fred wrote this:

>> > (list->string '(bla bla bla))

>Now the "'" means quote (e.g. String) so '(bla bla bla) will be treated
>as the string "(bla bla bla)" and not a list (bla bla bla) so Scheme
>will complain. Or am I wrong? I still consider myself to me an amateur
>at all this....

You're wrong.  In the context of Lisp/Scheme, "quote" means "don't evaluate
as a function call or variable reference".  It doesn't mean "treat as a
string".

Try this, for instance:

(car '(bla bla bla))

To make something be a string, you use double-quotes. '(bla bla) and "(bla
bla)" are completely different.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



Sun, 07 Apr 2002 03:00:00 GMT  
 list->string question

Quote:



>> >Secondly '(bla bla bla) is not a list. So list->string will throw a
>> >wobbly when it sees this.

>> You started out OK, but then you threw in this paragraph, which is totally
>> wrong.  (bla bla bla) certainly *is* a list.  It's a list of three symbols.

> Fred wrote this:

>> > (list->string '(bla bla bla))

> Now the "'" means quote (e.g. String) so '(bla bla bla) will be treated
> as the string "(bla bla bla)" and not a list (bla bla bla) so Scheme
> will complain. Or am I wrong? I still consider myself to me an amateur
> at all this....

In Scheme quote doesn't mean "this is a string".  quote means "don't try to
evaluate this"; this is the difference between inputting a list of three
bla's and applying the procedure bla to bla and bla; also the difference
between getting bla, the symbol, and the value of bla the variable (or
possibly an error if bla hasn't been defined).
In other words, 'x, or (quote x), will evalute to x and not be evaluted any
further.

list->string expects a list of characters (e.g. (#\b #\l #\a)) and then
makes a string out of them.  The elements of (bla bla bla) are not all
characters, so list->string complains.

--Jed



Sun, 07 Apr 2002 03:00:00 GMT  
 list->string question
On Wed, 20 Oct 1999 08:10:27 +0100, Johnny 'Loopy' Ooi

Quote:

>Fred wrote this:

>> > (list->string '(bla bla bla))

>Now the "'" means quote (e.g. String) so '(bla bla bla) will be treated
>as the string "(bla bla bla)" and not a list (bla bla bla) so Scheme
>will complain. Or am I wrong? I still consider myself to me an amateur
>at all this....

No, the single quote tells Scheme not to evaluate the list.
Otherwise, Scheme would try to find the value of (bla bla bla).
Symbol "bla" would be looked for, first as a syntactic form and then
for its binding in the current environment.  The form (bla bla bla)
has the syntax of a procedure call, so any procedure bound to symbol
bla would be called.

In the example given, bla is unlikely to be bound in the current
environment, so most implementations will give an error message.

Strings are introduced by the double quote.  Strings and lists are
different data structures.



Mon, 08 Apr 2002 03:00:00 GMT  
 list->string question
OK OK! I get the point! That's three people who've told me that! :)

--
Johnny Ooi. Aliases: Loopy, Tuxedo Mask, Quote Master.....

WWW             : http://www.dcs.qmw.ac.uk/~jjyooi/
ICQ No          : 6155774

"Stay sane guys!"

===============================================================



Mon, 08 Apr 2002 03:00:00 GMT  
 list->string question

Quote:

> >: I thought (list->string '(bla bla bla)) would return "bla bla bla" but
> >: it seems not to be case. How can i easily do this ?

A clone of Common Lisp's FORMAT would do (modulo case)

   (format #f "~{~A~^ ~}" '(bli bla blu)) ==> "BLI BLA BLU"

If your Scheme system does offer full-blown FORMAT, you may want to
read the recent thread on formatting lists in comp.lang.lisp.

rthappe



Mon, 08 Apr 2002 03:00:00 GMT  
 list->string question


Quote:
> If your Scheme system does offer full-blown FORMAT, you may want to
> read the recent thread on formatting lists in comp.lang.lisp.

And any Scheme that can host SLIB can offer a sufficiently rich FORMAT
with but a (require 'format).  Assuming that's what you really want.


Mon, 08 Apr 2002 03:00:00 GMT  
 list->string question

Quote:
> You must map a symbol->string operation over the list to make strings
> out of the symbols, and then apply a string-append operation on the
> list.

Thank you very much, it works :)

(define list2string
(lambda (list)
(if (= (length list) 1)
(symbol->string (car list))
(string-append (symbol->string (car list)) " " (list2string (cdr list)))
)))

--
  "The next generation of interesting software will be done on the Mac,
    not the IBM PC."      Bill Gates, Business Week, Nov 26, 1984, p.154
_______________________________________________________________________
Deelight      Apfelsaft 6 est enfin sur <http://www.chez.com/apfelsaft>



Wed, 10 Apr 2002 03:00:00 GMT  
 list->string question

+---------------

| > You must map a symbol->string operation over the list...
|
| Thank you very much, it works :)
|
| (define list2string
| (lambda (list)
| (if (= (length list) 1)
| (symbol->string (car list))
| (string-append (symbol->string (car list)) " " (list2string (cdr list)))
| )))
+---------------

And just in case you don't already use a text editor that indents
Lisp/Scheme properly, please try to find one (or do it manually).
It will make your programs *so* much more readable to others:

    (define list2string
      (lambda (list)
        (if (= (length list) 1)
          (symbol->string (car list))
          (string-append (symbol->string (car list))
                         " "
                         (list2string (cdr list))))))

[Yes, I know, some people prefer all three args of an "if" to be
indented the same. But I don't.]

-Rob

-----

Applied Networking              http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.          Phone: 650-933-1673
1600 Amphitheatre Pkwy.         FAX: 650-933-0511
Mountain View, CA  94043        PP-ASEL-IA



Wed, 10 Apr 2002 03:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. question about symbol->string, string->list

2. string->list->string

3. MIT scheme: string->list on long strings

4. Bugs in ST80 4.1 (Stream>>through, List>>copyFrom:to:)

5. SCM list->string

6. Where's the proper list->string ?

7. string -> list

8. String-->list?

9. LIST-->STRING solved

10. Newbie Q: efficiency of list -> string conversion

11. wish-list: Tcl object->string conversion

12. lists - arrays - strings --(newbee question 2)

 

 
Powered by phpBB® Forum Software