lisppa.htm

来自「Delphi脚本控件」· HTM 代码 · 共 1,141 行 · 第 1/3 页

HTM
1,141 行
字号
The first statement is implied, you have no a need to use it explicitly. Note, the delete statement 
destroys P variable, not terminal of P. So, the statement sequence

<blockquote>
<pre>
<font color="blue"><b>Dim</b></font> A, P
A = 100
P = <font color="blue"><b>AddressOf</b></font> A
MsgBox A
MsgBox P
<font color="blue"><b>delete</b></font> P
MsgBox A
MsgBox P
</pre>
</blockquote>

produces

<blockquote>
<pre>
100
100
100
NULL
</pre>
</blockquote>


To destroy A by means of P, you have to use TerminalOf operator: 


<blockquote>
<pre>
<font color="blue"><b>Dim</b></font> A, P
A = 100
P = <font color="blue"><b>AddressOf</b></font> A
MsgBox A
MsgBox P
<font color="blue"><b>delete TerminalOf</b></font> P
MsgBox A
MsgBox P
</pre>
</blockquote>

These statements produce

<blockquote>
<pre>
100
100
NULL
NULL
</pre>
</blockquote>

Let's note there are only 2 places where you might use the TerminalOf operator. 

<p>
The first place is the delete statement. You can delete either P or terminal of P. 

<p>
The second place is the assignment statement. The assignment statement has the following grammar:

<blockquote>
<pre>
[<font color="blue"><b>Reduced</b></font>][<font color="blue"><b>TerminalOf</b></font>] Expr1 = [<font color="blue"><b>AddressOf</b></font> [<font color="blue"><b>TerminalOf</b></font>]] Expr2
</pre>
</blockquote>

The reduced modifier is used to avoid a memory leak. It has been considered above.

<p>
The TerminalOf at the left part of the assignment statement should be used only when Expr1 is alias and 
AddressOf is presented at the right part of the statement.  
(Because <font color="blue"><b>TerminalOf</b></font> Expr1 = Expr2 
produces the same assignment as Expr1 = Expr2 in all another cases). When AddressOf is presented at the right 
part, the use of TerminalOf in the left part allows you to assign alias of Expr2 to terminal of Expr1. For 
example:


<blockquote>
<pre>
<font color="blue"><b>Dim</b></font> A[10], B, C, P
B = 300
C = 500
P = <font color="blue"><b>AddressOf</b></font> A(5)
<font color="blue"><b>TerminalOf</b></font> P = <font color="blue"><b>AddressOf</b></font> B
MsgBox P
MsgBox A[5] 
P = <font color="blue"><b>AddressOf</b></font> C
MsgBox A[5] 
MsgBox P
</pre>
</blockquote>

It produces

<blockquote>
<pre>
300
300
300
500
</pre>
</blockquote>

The TerminalOf at the left part of the assignment statement should be used only when Expr2 is an alias.
In this case, the use of TerminalOf allows you to assign Expr1 as alias of terminal of Expr2. For example

<blockquote>
<pre>
<font color="blue"><b>Dim</b></font> P1 = <font color="Red">"X"</font>
<font color="blue"><b>Dim</b></font> P2 = <font color="Red">"Y"</font>
<font color="blue"><b>Dim</b></font> T1 = [<font color="Red">"R"</font>, [<font color="Red">"F"</font>, <font color="blue"><b>AddressOf</b></font> P1]]
<font color="blue"><b>Dim</b></font> T2 = [<font color="Red">"R"</font>, <font color="blue"><b>AddressOf</b></font> P2]
<font color="blue"><b>Dim</b></font> Q1 = <font color="blue"><b>AddressOf</b></font> T1[1]
<font color="blue"><b>Dim</b></font> Q2 = <font color="blue"><b>AddressOf</b></font> T2[1]
<font color="blue"><b>TerminalOf</b></font> Q2 = <font color="blue"><b>AddressOf</b></font> <font color="blue"><b>TerminalOf</b></font> Q1
</pre>
</blockquote>


This example illustrates how the search of most general unifier works (mechanical theorem proving). 
T1 and T2 represent terms, P1 and P2 are parameters of T1 and T2 accordingly. The last statement 

<blockquote>
<pre>
<font color="blue"><b>TerminalOf</b></font> Q2 = <font color="blue"><b>AddressOf</b></font> <font color="blue"><b>TerminalOf</b></font> Q1
</pre>
</blockquote>

changes parameters, not source terms. 
</ul>


<a name ="LISPPA and Symbolic Computation">
<h3>
LISPPA and Symbolic Computation
</h3>

The use of LISPPA considerably simplify the programming of symbolic computation in the imperative languages.
Indeed, how one can characterize a language which is well-suited for the symbolic computations? Such language
should provide a simple way for representation of terms and flexible control structures allowing to process
terms. LISPPA-extension of such imperative languages as Pascal or Basic can ensure both conditions: array
constructors provide a suitable way for the term representation, aliases allows to process terms effectively.

<p>
Let's consider an example written in paxBasic. This is the most general unifier algorithm, the heart of the
theorem proving and logic programming:

<blockquote>
<pre>
<font color="blue"><b>Function</b></font> Unify(N <font color="blue"><b>As</b></font> <font color="blue"><b>Integer</b></font>, T1 <font color="blue"><b>As</b></font> <font color="blue"><b>Variant</b></font>, T2 <font color="blue"><b>As</b></font> <font color="blue"><b>Variant</b></font>) <font color="blue"><b>As</b></font> <font color="blue"><b>Boolean</b></font>
  <font color="blue"><b>Dim</b></font> I <font color="blue"><b>As</b></font> <font color="blue"><b>Integer</b></font>
  <font color="blue"><b>Dim</b></font> P1, P2 <font color="blue"><b>As</b></font> <font color="blue"><b>Variant</b></font>
  <font color="blue"><b>For</b></font> I=N <font color="blue"><b>to</b></font> T1.length - 1
    P1 = <font color="blue"><b>AddressOf</b></font> T1(I)
    P2 = <font color="blue"><b>AddressOf</b></font> T2(I)
    <font color="blue"><b>If</b></font> IsCompound(P1) <font color="blue"><b>And</b></font> IsCompound(P2) <font color="blue"><b>Then</b></font>
      <font color="blue"><b>If</b></font> <font color="blue"><b>Not</b></font> Unify(0, P1, P2) <font color="blue"><b>Then</b></font>
        <font color="blue"><b>Return</b></font> false
      <font color="blue"><b>End</b></font> <font color="blue"><b>If</b></font>
    <font color="blue"><b>ElseIf</b></font> IsVar(P1) <font color="blue"><b>And</b></font> (<font color="blue"><b>Not</b></font> Inside(P1, P2)) <font color="blue"><b>Then</b></font>
      <font color="blue"><b>TerminalOf</b></font> P1 = <font color="blue"><b>AddressOf</b></font> <font color="blue"><b>TerminalOf</b></font> P2
    <font color="blue"><b>ElseIf</b></font> IsVar(P2) <font color="blue"><b>And</b></font> (<font color="blue"><b>Not</b></font> Inside(P2, P1)) <font color="blue"><b>Then</b></font>
      <font color="blue"><b>TerminalOf</b></font> P2 = <font color="blue"><b>AddressOf</b></font> <font color="blue"><b>TerminalOf</b></font> P1
    <font color="blue"><b>ElseIf</b></font> P1 <> P2 <font color="blue"><b>Then</b></font>
      <font color="blue"><b>Return</b></font> false
    <font color="blue"><b>End</b></font> <font color="blue"><b>If</b></font>
  <font color="blue"><b>Next</b></font>
  <font color="blue"><b>Return</b></font> true
<font color="blue"><b>End</b></font> <font color="blue"><b>Function</b></font>
</pre>
</blockquote>

The most general unifier algorithm is the "litmus paper" of applicability of a programming language for
symbolic computations. While functional languages offer simple solutions, the imperative languages based on
using pointers will increase the complexity of the implementation of the algorithm. The example above shows
a simple solution in the imperative style of the programming.



<a name ="LISPPA and COM Technology">
<h3>
LISPPA and COM Technology
</h3>

A possibility to represent and to process complex data structures in LISPPA on the base of Variant data 
types can important for the COM technology. There are a few data types which are admissible in COM:
selected scalar data types and variants. Let's suppose both the server and client of Automation supports 
LISPPA (as was stated above, LISPPA can be implemented as a simple extension of Variant type concept). 
For example, our server can contain an expert system and we pass set of facts to the expert system
as a parameter. The set of facts can be easily represented as a variant array which contains
terms as elements.  Server will send to client a value represented as a term as well. 

<p>
The LISPPA allows you to transfer complex data structures between server and 
client without having to encode/decode the data. It can considerably increase the total speed of data 
processing at both sides. LISPPA provides an uniform way for the data representation.
 

<a name ="Demos">
<h3>
Demos
</h3>

<ul>

<a name ="paxBasic">
<li>paxBasic
<ul>
<li><a href="demo_basic_lists.htm">Linked lists</a>
<li><a href="demo_basic_2lists.htm">Two way linked lists</a>
<li><a href="demo_basic_trees.htm">Binary trees</a>
<li><a href="demo_basic_polynomials.htm">Polynomials</a>
<li><a href="demo_basic_euler.htm">Euler algorithm</a>
<li><a href="demo_basic_diff.htm">Symbolic differentiation</a>
<li><a href="demo_basic_theorem.htm">Mechanical theorem proving</a>
</ul>

<a name ="paxC">
<li>paxC
<ul>
<li><a href="demo_c_lists.htm">Linked lists</a>
<li><a href="demo_c_2lists.htm">Two way linked lists</a>
<li><a href="demo_c_trees.htm">Binary trees</a>
<li><a href="demo_c_polynomials.htm">Polynomials</a>
<li><a href="demo_c_euler.htm">Euler algorithm</a>
</ul>

<a name ="paxJavaScript">
<li>paxJavaScript
<ul>
<li><a href="demo_js_lists.htm">Linked lists</a>
<li><a href="demo_js_2lists.htm">Two way linked lists</a>
<li><a href="demo_js_trees.htm">Binary trees</a>
<li><a href="demo_js_polynomials.htm">Polynomials</a>
<li><a href="demo_js_euler.htm">Euler algorithm</a>
</ul>

<a name ="paxPascal">
<li>paxPascal
<ul>
<li><a href="demo_pascal_lists.htm">Linked lists</a>
<li><a href="demo_pascal_2lists.htm">Two way linked lists</a>
<li><a href="demo_pascal_trees.htm">Binary trees</a>
<li><a href="demo_pascal_polynomials.htm">Polynomials</a>
<li><a href="demo_pascal_euler.htm">Euler algorithm</a>
<li><a href="demo_pascal_diff.htm">Symbolic differentiation</a>
<li><a href="demo_pascal_theorem.htm">Mechanical theorem proving</a>
</ul>

</ul>


You can try these demos with the paxScript IDE. (See Download 
section at<a href="http://www.paxscript.com"> www.paxscript.com</a>).


<a name ="Conclusions">
<h3>
Conclusions
</h3>

<ol>

<li>
LISPPA technology is based on 4 main concepts:

<ol>
<li>Polymorphic arrays.
<li>Array constructors.
<li>Reduced assignments.
<li>Aliases or delegates of variable. Terminals.
</ol>

The first 2 concepts are not new, they are presented in many programming languages. Just let's remind: 
a variable of a polymorphic array type is actually a reference. Hence more than one variable 
can refer to the same polymorphic array. The assignment statement executes copying references, not actual 
arrays. The copy of A array can be created by the unary plus operator (+ A). 
                                                                                     
<p>
The third concept is optional as it can be expressed via already known concepts. 

<p>
Aliases and terminals are not new concepts too, I have adjusted their semantics for the processing
of polymorphic arrays.

<li>
LISPPA technology considerably simplify the processing of dynamic data structures in comparison with 
the technology based on the use of pointers. For example, the structure of statement which expresses 
operation of the insertion of item into the list 

<blockquote>
<pre>
P = [NewItem, P]
</pre>
</blockquote>

and structure of statement which expresses operation of the removing item from the list 

<blockquote>
<pre>
<font color="blue"><b>reduced</b></font> P = P(1)
</pre>
</blockquote>

are uniform. In another words, <b>they are do not depend from the position of insertion or deleting</b> 
(at the top, at the middle, at the tail of list). You are moving alias, not changing structure of the 
statement. Both operations are expressed by single statement. You do not use allocation and deallocation of 
memory explicitly. The programming of the dynamic data structures becomes more safe and free of bugs.

<li>
Well known variant types can be easy extended to provide LISPPA. paxScript scripting engine implements
LISPPA on the base of an extension of the Variant type. In particular, the alias type is a Variant 
sub-type. So LISPPA can be implemented in all programming systems which support the variant types.

<li>
LISPPA considerably extends the applicability of imperative programming languages in the symbolic 
computations and AI applications.

<li>
LISPPA can be important for the COM technology (representation and processing of data in Variants).

<li>
Java views pointers as something that are too much trouble to deal with, and therefore 
doesn't expose them to the programmer. .NET paradigm relaxes this strict limitation but does not allow 
the use of pointers in "normal" code. 
Therefore LISPPA technology can be important for both directions. (Variant types are absent in Java 
and .NET Frameworks however the support of LISPPA can be easily implemented).

<li>
Implementation LISPPA in paxJavaScript can be used as a background of possible development of ECMA 
standard of the JavaScript language.

<li>
The Variant types provide the most easy way of the LISPPA implementation. However, this is not 
a necessary condition. We might introduce new data types such as pa-integer (polymorphic array
of integers), pa-double (polymorphic array of doubles) etc to privide the strict data typing in the
processing of dynamic data structures and to increase the performance. More general, if T is a data 
type, we can consider pa-T, the polymorphic array of elements of T type. 

<li>
LISPPA has theoretical value as it allows to concisely describe well-known data structures and 
algorithmes on the base of the concept of the polymorphic array. For example, linked lists, trees and
graphs can be considered as partial cases of polymorphic array.

</ol>


<a name ="References">
<h3>
References
</h3>

For the first time the use polymorphic arrays for the processing of dynamic data structures has been 
presented in the articles: 

<ol>
<li>Baranovsky A.I. (1998) The Universal Programming Language VIRT. Kibernetika i
        sistemny analiz, ISSN 0023-1274, N5, Kiev, p. 130-150. 
<BR>
<li>Baranovsky A.I. (1999) Using the VIRT Language for the Symbolic Computations,
        Artificial Intelligence, ISSN 1561-5359, N1, Donetsk, p. 59-69. 
<BR>
<li>Baranovsky A.I. (1999) Using the VIRT Language for the Mechanical Theorem Proving. Kibernetika i
        sistemny analiz, ISSN 0023-1274, N6, p. 87-99 Kiev. 
</ol>

<p>
<HR>
<font size = 1 color ="gray">
Copyright &copy; 1999-2005
VIRT Laboratory. All rights reserved.
</font>
</body>
</html>
                                      

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?