[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TYPOL Copy or Reference Semantics?




In article <37618@sophia.inria.fr>, kuehne@isa.informatik.th-darmstadt.de (Thomas Kuehne) writes:
|> Hello TYPOL specialists,
|> 
|> i have a small question about the meaning of the following TYPOL rule:
|> 
|> |- op_lang1(A) -> op_lang2(a(op_lang1(A)));
|> 
|> op_langx are operators from two different languages.
|> 
|> Variable 'A' is of type 'lang1'.
|> 
|> Operator 'a' is of type 'lang2' and 'implemented as TREE' with METAL.
|> 
|> 
|> The purpose of the rule is to stop a conversion from 'lang1' to 'lang2'
|> with a reference node from 'lang2' to some node in 'lang1'.
|> This works well, my only questions is:
|> 
|>   Is the reference a real sharing of the contents of 'A' or
|>   does the TYPOL rule imply copy semantics?
|> 
|> The answer is not relevant for the semantics of the example but for the
|> question whether this 'referencing' allows data to be shared efficiently.
|> 
|> My experiences indicate copy semantics, but this might be due to clever
|> data holding of Centaur.
|> When i change the contents of an editor with text that is referenced or simply 
|> close it the refering data is not affected.
|> However, i doubt this clearly implys copying.
|> 
|> Please let me know, whether my 'references' are memory consumers or 
|> memory savers.

There is sharing during the execution of Typol, and then a copy when the
result is sent back to the Lisp word.

Let us see in details what appends.
1- your data is somewhere in the Lisp word, may be in a ctedit;
2- a prolog term is contructed (that is a copy of this data);
3- your rules are executed; during this execution there is sharing, due to
   the prolog implementation: the free variable A in op_lang2(a(op_lang1(A))) is
   unified with the bound variable A in the subject, resulting in a reference;
4- the resulting prolog term (with references to the subject) is sent back to
   the lisp word; this means that a new tree is built that is a copy of the
   prolog term, but at this point the references are lost.

This is the important point. You may construct a small prolog term (because
there is a lot of sharing in it) that will be expanded in a huge centaur tree.

Centaur is not designed for sharing trees (each node contains a pointer to
its father). But it is still possible to replace a copy by a reference.
If you replace your rule by
|- op_lang1(A) -> op_lang2(a(subject)); (same definitions for the operators)
the result will contain a path (subject) that is a reference to the subject of 
the rule. This path is itself a tree and will be copied when the result
is sent back to Centaur. Then it is possible to interprete this path in Lisp
to retrive the original object.

This may be used for example as in the error messages mechanism used for Metal,
Ppml or Typol. Error messages are trees that contain paths that are references
to erroneous subtrees. These paths are not unparsed by Ppml (it shoud be
a "s(s(s...)))") but when you click on the "show error" button, there are used
to retrived the erroneous path of your program.

Thierry.
-- 
Send contributions and compliments to centaur@sophia.inria.fr. Registration
and administrative matters should be sent to centaur-request@sophia.inria.fr.
+---------------------------------------------------------------------------+
|     Thierry Despeyroux      | email: Thierry.Despeyroux@sophia.inria.fr   |
| I.N.R.I.A. Sophia-Antipolis | phone: +33 93 65 77 07 fax: +33 93 65 77 66 |
+---------------------------------------------------------------------------+