home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / modprolg / mod-prol.lha / Prolog / modlib / src / $meta.P < prev    next >
Encoding:
Text File  |  1992-05-28  |  3.4 KB  |  99 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. /* $meta.P */
  38.  
  39. $meta_export([$functor/3,$univ/2,$length/2,$univ/3,$functor/4]).
  40.  
  41. % $meta_use : $bmeta
  42.  
  43. % $univ/3 now ensures that functions involved in 'fun X = Y' declarations
  44. % are processed properly.
  45. % At the user level, this is called =../2.
  46.  
  47. $univ(X,Y) :-
  48.     $univ(X,Y,perv).
  49.  
  50. $univ(X, [X], Tag) :- 
  51.     $atomic(X), !,
  52.     $isa_structuretag(Tag).
  53. $univ(X, [H|T], Tag) :- 
  54.     $atom(H), nonvar(X), !,
  55.     $length(T, N), N > 0, 
  56.     $bldstr(H, N, Y, Tag), $arglist(Y, T, N, N),
  57.     X = Y.
  58. $univ(X, [H|T], Tag) :- 
  59.     $atom(H), !,
  60.     $length(T, N), N > 0, 
  61.     $bldstr(H, N, X, Tag), $arglist(X, T, N, N).
  62. $univ(X, [H|T], Tag) :- 
  63.     nonvar(X), $functor(X, H, N, Tag), $arglist(X, T, N, N).
  64.  
  65. $arglist(X, [], 0, N) :- !.
  66. $arglist(X, [Y|Z], I, N) :- K is I - 1,
  67.                 J is N - K,
  68.                 arg(J, X, Y), 
  69.                 $arglist(X, Z, K, N).
  70.  
  71. $length(L,N) :- nonvar(L),$length(L,0,N).
  72.  
  73. $length([],N,N).
  74. $length([_|L],M,N) :- M1 is M+1, $length(L,M1,N).
  75.  
  76. % The original version of $functor/3 is included here for system use.
  77. % Has no equivalent at the user level.
  78.  
  79. $functor(T, F, 0) :- $atomic(T), !, T=F.
  80. $functor(T, F, 0) :- $number(F), !, T=F.
  81. $functor(T, F, N) :- nonvar(T), !, $functor0(T, F), $arity(T, N).
  82. $functor(T, F, N) :- $bldstr(F, N, T).
  83.  
  84. $functor(T, F, 0, Tag) :- 
  85.     $atomic(T), !, 
  86.     $isa_structuretag(Tag),
  87.     T=F.
  88. $functor(T, F, 0, Tag) :- 
  89.     $number(F), !,
  90.     $isa_structuretag(Tag),
  91.     T=F.
  92. $functor(T, F, N, Tag) :- 
  93.     nonvar(T), !, 
  94.     $functor0(T, F, Tag), 
  95.     $arity(T, N).
  96. $functor(T, F, N, Tag) :- 
  97.     $bldstr(F, N, T, Tag).
  98.  
  99.