home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / modprolg / mod-prol.lha / Prolog / modlib / src / $bmeta.P < prev    next >
Encoding:
Text File  |  1992-05-30  |  4.7 KB  |  136 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24.  
  25. /****************************************************************************
  26.  *                                                                          *
  27.  * This file has been changed by to include Modules Extensions              *
  28.  * Changes by : Brian Paxton 1991/92                                        *
  29.  * Last update : June 1992                                                  *
  30.  *                                                                          *
  31.  * Organisation : University of Edinburgh.                                  *
  32.  * For : Departments of Computer Science and Artificial Intelligence        * 
  33.  *       Fourth Year Project.                                               *
  34.  *                                                                          *
  35.  ****************************************************************************/
  36.  
  37. /* $bmeta.P */
  38.  
  39. $bmeta_export([$atom/1,$atomic/1,$integer/1,$number/1,$structure/1,
  40.     $functor0/2,$bldstr/3,$arg/3,$arity/2,$real/1,$float/1,$mkstr/3,
  41.     $is_buffer/1,$bldstr/4,$functor0/2,$functor0/3,
  42.     $function/1,$predicate/1]).
  43.  
  44. % $function/1 succeeds if its argument is a function (not a predicate or
  45. % a buffer).
  46. % At the user level, this is called function/1.
  47.  
  48. $function(X) :- 
  49.     ( $atom(X) -> true ; $structure(X) ),
  50.     $symtype(X, 0).
  51.  
  52. % $predicate/1 succeeds if its argument is a predicate (not a function or
  53. % a buffer).
  54. % At the user level, this is called predicate/1.
  55.  
  56. $predicate(X) :-
  57.     ( $atom(X) -> true ; $structure(X) ),
  58.     ( $symtype(X, 1) -> true ; $symtype(X, 2) ).
  59.  
  60. $atom(X) :- '_$builtin'(66).
  61.  
  62. $atomic(X) :- '_$builtin'(68).
  63.  
  64. $integer(X) :- '_$builtin'(67).
  65.  
  66. $number(X) :- integer(X) -> true ; real(X).
  67.  
  68. $structure(X) :- '_$builtin'(129).
  69.  
  70. $functor0(T, F) :- '_$builtin'(81).
  71.  
  72. % $functor0/3 does basically the same jobs as $functor0, but takes into
  73. % account functions declared as 'fun X = Y'.
  74. % Requires the current structure tag to operate.
  75.  
  76. $functor0(X,Y,perv) :- !,
  77.     $functor0(X,Y).
  78.  
  79. $functor0(Structure,Name,Tag) :-
  80.     $isa_structuretag(Tag),
  81.     $functor0(Structure,Internal),
  82.     $arity(Structure,Arity),
  83.         $symtype($mapped_function(_,_,_,_),Type),
  84.         ( ( Type > 0 , 
  85.             $mapped_function(Name0, Arity, Internal, Tag) ) -> true ;
  86.           Name0 = Internal ),
  87.         ( $dismantle_name(Name0,Name1,perv) ->
  88.                $dismantle_name(Name2,Name1,Tag) ;
  89.                Name2 = Name0 ),
  90.         $dismantle_name(Name2,Intname,_),
  91.         ( $pervasive0(Intname) -> 
  92.                Name = Intname ;
  93.                ( ( Type > 0,
  94.                    $mapped_function(Name2, 0, Name, Tag) ) -> true ;
  95.                  Name = Name2 ) ).
  96.  
  97. $bldstr(F, N, T) :-
  98.     '_$builtin'(84).
  99.  
  100. % $bldstr/4 does basically the same jobs as $bldstr/3, but takes into
  101. % account functions declared as 'fun X = Y'.
  102. % Requires the current structure tag to operate.
  103. % At the user level, this predicate is called bldstr/4.
  104.  
  105. $bldstr(Atom,Arity,Structure,Currenttag) :-
  106.     $isa_structuretag(Currenttag),
  107.     $symtype($mapped_function(_,_,_,_),Type),
  108.     ( ( Type > 0,
  109.         $mapped_function(Atom1,0,Atom,Currenttag) ) -> true ;
  110.       Atom1 = Atom ),
  111.     ( $dismantle_name(Atom1,Atom2,perv) ->
  112.            $dismantle_name(Atom3,Atom2,Currenttag) ;
  113.            Atom3 = Atom1 ),
  114.     $dismantle_name(Atom3,Atom4,_),
  115.     ( $pervasive(Atom4/Arity) ->
  116.          Internal = Atom4 ;
  117.          ( ( Type > 0,
  118.              $mapped_function(Atom3,Arity,Internal,_) ) -> true ;
  119.            Internal = Atom3 ) ),
  120.     $bldstr0(Internal,Arity,Structure).
  121.  
  122. $bldstr0(F,N,T) :- '_$builtin'(84).
  123.  
  124. $arg(I, T, X) :- '_$builtin'( 80 ).
  125.  
  126. $arity(X, A) :- '_$builtin'(69).
  127.  
  128. $real(X) :- '_$builtin'(62).
  129.  
  130. $float(X) :- '_$builtin'(62).
  131.  
  132. $mkstr(X,Y,Z) :- '_$builtin'(85).
  133.  
  134. $is_buffer(X) :- '_$builtin'(72).
  135.  
  136.