Changeset 4470

Show
Ignore:
Timestamp:
09/22/08 08:18:55 (4 months ago)
Author:
pmoura
Message:

Added a syntax construct for easy access to parametric object proxies represented as Prolog facts when sending a message ({Proxy}::Message). Updated the "proxies" example to illustrate this new functionality.

Location:
trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4468 r4470  
    78837883 
    78847884 
     7885% convenient access to parametric object proxies 
     7886 
     7887'$lgt_tr_msg'(Pred, {Proxy}, (call(Proxy), TPred), This) :- 
     7888    !, 
     7889    '$lgt_tr_msg'(Pred, Proxy, TPred, This). 
     7890 
     7891 
    78857892% translation performed at runtime 
    78867893 
  • trunk/examples/proxies/proxies.lgt

    r3227 r4470  
    33% object proxy arguments and to encapsulate relevant predicates: 
    44 
    5 :- object(circle(_Radius, _Color)). 
     5:- object(circle(_Id, _Radius, _Color)). 
    66 
    77    :- public([ 
    8         radius/1, 
    9         color/1, 
    10         area/1, 
    11         perimeter/1, 
    12         print/0]). 
     8        id/1, radius/1, color/1, 
     9        area/1, perimeter/1, 
     10        print/0 
     11    ]). 
     12 
     13    id(Id) :- 
     14        parameter(1, Id). 
    1315 
    1416    radius(Radius) :- 
    15         parameter(1, Radius). 
     17        parameter(2, Radius). 
    1618 
    1719    color(Color) :- 
    18         parameter(2, Color). 
     20        parameter(3, Color). 
    1921 
    2022    area(Area) :- 
     
    2729 
    2830    print :- 
    29         area(Area), write('area: '), write(Area), 
     31        id(Id), write('id: '), write(Id), 
     32        area(Area), write(', area: '), write(Area), 
    3033        perimeter(Perimeter), write(', perimeter: '), write(Perimeter), 
    3134        color(Color), write(', color: '), write(Color), nl. 
     
    3437 
    3538 
    36 % parametric object proxies (with an extra argument to represent identity): 
     39% parametric object proxies: 
    3740 
    3841circle('#1', 1.23, blue). 
  • trunk/examples/proxies/SCRIPT.txt

    r4466 r4470  
    1818% print the area and the perimeter for all circle proxies: 
    1919 
    20 | ?- forall(circle(Id, R, C), (write(Id), write(' '), circle(R, C)::print)). 
     20| ?- forall(circle(Id, R, C), circle(Id, R, C)::print). 
    2121 
    22 #1 area: 4.75291, perimeter: 7.72831, color: blue 
    23 #2 area: 43.2412, perimeter: 23.3106, color: yellow 
    24 #3 area: 0.477836, perimeter: 2.45044, color: green 
    25 #4 area: 103.508, perimeter: 36.0655, color: black 
    26 #5 area: 217.468, perimeter: 52.2761, color: cyan 
    27 yes 
     22id: #1, area: 4.75291, perimeter: 7.72831, color: blue 
     23id: #2, area: 43.2412, perimeter: 23.3106, color: yellow 
     24id: #3, area: 0.477836, perimeter: 2.45044, color: green 
     25id: #4, area: 103.508, perimeter: 36.0655, color: black 
     26id: #5, area: 217.468, perimeter: 52.2761, color: cyan 
     27true. 
     28 
     29 
     30% print the area and the perimeter for the circle #2: 
     31 
     32| ?- {circle('#2', R, C)}::print. 
     33 
     34id: #2, area: 43.2412, perimeter: 23.3106, color: yellow 
     35R = 3.71, 
     36C = yellow. 
  • trunk/manuals/index.html

    r4466 r4470  
    3232    <div class="copyright"> 
    3333        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/>  
    34         <span>Last updated on: August 25, 2008</span> 
     34        <span>Last updated on: September 22, 2008</span> 
    3535    </div> 
    3636    <div class="navbottom"> 
  • trunk/manuals/userman/index.html

    r4447 r4470  
    304304    <div class="copyright"> 
    305305        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/> 
    306         <span>Last updated on: August 25, 2008</span> 
     306        <span>Last updated on: September 22, 2008</span> 
    307307    </div> 
    308308    <div class="navbottom"> 
  • trunk/manuals/userman/objects.html

    r4270 r4470  
    194194</p> 
    195195<p> 
    196 Compound terms with the same functor and (usually) the same number of arguments as a parametric object identifier may act as <em>proxies</em> to a parametric object. Proxies may be stored on the database as Prolog facts and be used to represent different instantiations of a parametric object identifier. 
     196Compound terms with the same functor and (usually) the same number of arguments as a parametric object identifier may act as <em>proxies</em> to a parametric object. Proxies may be stored on the database as Prolog facts and be used to represent different instantiations of a parametric object identifier. Logtalk provides a convenient notation for accessing proxies represented as Prolog facts when sending a message: 
     197</p> 
     198<pre>{Proxy}::Message</pre> 
     199<p> 
     200In this context, the proxy argument is proved as a plain Prolog goal. If successful, the message is sent to the corresponding parametric object. Typically, the proof allows retrieving of parameter instantiations. This notation supports backtracking over the Prolog facts that unify with the proxy term. When this behavior is unwanted, is possible to commit to the first unifying fact by writing: 
     201</p> 
     202<pre>{Proxy}::(!, Message)</pre> 
     203<p> 
     204In most cases, however, the use of cuts is not necessary as this construct is usually used with a proxy argument that is partially instantiated in order to unify with a single Prolog fact. 
    197205</p> 
    198206 
     
    439447    <div class="copyright"> 
    440448        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/>  
    441         <span>Last updated on: May 21, 2008</span> 
     449        <span>Last updated on: September 22, 2008</span> 
    442450    </div> 
    443451    <div class="navbottom"> 
  • trunk/RELEASE_NOTES.txt

    r4468 r4470  
    1515 
    16162.33.1 - October ??, 2008 
     17 
     18    Added a syntax construct for easy access to parametric object proxies 
     19    represented as Prolog facts when sending a message ({Proxy}::Message). 
     20    Updated the "proxies" example to illustrate this new functionality. 
    1721 
    1822    Corrected a bug in the Logtalk compiler that would result in failure to