[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sending list
From: |
Alex Shinn |
Subject: |
Re: sending list |
Date: |
12 Sep 2001 10:00:44 -0400 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/21.0.104 |
>>>>> "Manuel" == Manuel Giraud <address@hidden> writes:
Manuel> Martin Grabmueller <address@hidden> writes:
>> You need to convert the list to a string before sending it to
>> the port. Consider the following:
>>
guile> (call-with-output-string (lambda (s) (write '(define a 8)
guile> s)))
>> "(define a 8)"
>>
Manuel> I don't really understand the behaviour of
Manuel> `call-with-output-string', the documentation says :
Manuel> "Calls the one-argument procedure @var{proc} with a newly
Manuel> created output port. When the function returns, the
Manuel> string composed of the characters written into the port is
Manuel> returned."
Manuel> I don't understand how useful can be a "newly created
Manuel> output port" on which you have no control (is a socket, a
Manuel> file? which one?).
Neither, it's just an output port. In Martin's example the port is
passed as the argument to the (lambda (s) ...) expression. Inside the
procedure he writes to the s port, and when the procedure is done, all
the output to s is collected and returned by the c-w-o-s expression as
a single string.
Manuel> Anyway, is it possible with this function and
Manuel> `call-with-input-string' to send a s-expression (as a
Manuel> string) over socket, retrieve it on the server side and
Manuel> evaluate it?
Sure, you just want to convert the s-expression to a string somehow.
Scheme will also do this for you automatically if you use
(write '(define a 8) port)
In this sense read and write are opposites, and anything you can read
you can write. The converse is not true, there are things like ports
themselves and smobs which have a written representation but cannot be
read back in.
--
Alex Shinn <address@hidden>