Re: [eclipse-clp-users] Copying Eclipse Data / Re: OutOfProcessEclipse Error

From: Joachim Schimpf <joachim.schimpf_at_...269...>
Date: Fri, 25 Jun 2010 10:30:18 +1000
Christian Wirth wrote:
> I'm trying to copy a nested term structure (a list and a tree).

Use one of the following, they all preserve variable sharing:

writeq/2 and read/2:  Use writeq to write the term to any I/O stream
(file/pipe/socket/queue etc), and use read/2 to read it back.

term_string/2 for term to string and string to term.  Does basically
the same thing as the writeq/read pair, except it makes an explicit
string.

term_to_bytes/2 and bytes_to_term/2 also convert arbitrary terms to
strings and back, but the format is not human readable.

Examples:

?- Old = foo(X, [3, X, Y]), open(queue(""), update, Q), writeq(Q, Old), read(Q, New).
Old = foo(_83, [3, _83, _96])
X = _83
Y = _96
Q = 27
New = foo(_550, [3, _550, _559])
Yes (0.00s cpu)

?- Old = foo(X, [3, X, Y]), term_string(Old, String), term_string(New, String).
Old = foo(_82, [3, _82, _95])
X = _82
Y = _95
String = "foo(_82, [3, _82, _95])"
New = foo(_466, [3, _466, _475])
Yes (0.00s cpu)

?- Old=foo(X,[3,X,Y]), term_to_bytes(Old,String), bytes_to_term(String,New).
Old = foo(_82, [3, _82, _95])
X = _82
Y = _95
String =
"\000\000\000\030\001\002\v\002\003foo\377\b\000\n\376\b\001X\n\003\000\016\377\b\000\022\377\026\t\376\026\001Y"
New = foo(_460, [3, _460, _467])
Yes (0.00s cpu)


-- Joachim
Received on Fri Jun 25 2010 - 01:28:13 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:20 CEST