home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / prolog / 1654 < prev    next >
Encoding:
Text File  |  1992-09-04  |  2.0 KB  |  69 lines

  1. Newsgroups: comp.lang.prolog
  2. Path: sparky!uunet!mcsun!Germany.EU.net!ecrc!acrab6!micha
  3. From: micha@ecrc.de (Micha Meier)
  4. Subject: Re: Help with C-Prolog, Please.
  5. Message-ID: <1992Sep4.121544.13871@ecrc.de>
  6. Sender: news@ecrc.de
  7. Reply-To: micha@ecrc.de
  8. Organization: European Computer-Industry Research Centre
  9. References: <1992Sep3.164303.8798@iccgcc.decnet.ab.com>
  10. Date: Fri, 4 Sep 1992 12:15:44 GMT
  11. Lines: 56
  12.  
  13. In article 8798@iccgcc.decnet.ab.com, baechtel@iccgcc.decnet.ab.com () writes:
  14. >
  15. >
  16. >    In C-Prolog 1.5, is there anyway to get the name of a variable
  17. >in a term?
  18. >
  19. >    Specifically, If I write:
  20. >
  21. >read(Term, Vars) :-
  22. >    read(Term),
  23. >    functor(Term,F,A),
  24. >    getvars(Term,A,Vars,[]).
  25. >
  26. >getvars(Term,0,Varlist,Varlist).
  27. >
  28. >getvars(Term,A,Vars,Varlist) :-
  29. >    arg(A,Term,Arg),
  30. >    ( var(Arg), Vars1 = [Arg | Varlist]; Vars1 = Varlist),
  31. >    A1 is A-1,
  32. >    getvars(Term,A1,Vars,Vars1).
  33. >
  34. >If I execute read(Term,Vars) and my input is: "X is Y.",
  35. >Term = "X is Y" and Vars = [_15,_16].
  36. >
  37. >Is there anyway to get Vars=[X,Y]?
  38. >I don't understand how to get the name of the Variable instead of its
  39. >reference.
  40.  
  41. Actually, if I execute your code, I get
  42. | ?- read(Term, Vars).
  43. |: "X is Y".
  44.  
  45. Term = [88,32,105,115,32,89]
  46. Vars = []  
  47.  
  48. or, if the quotes were not meant to be there,
  49.  
  50. | ?- read(Term, Vars).
  51. |: X is Y.
  52.  
  53. Term = _6 is _7
  54. Vars = [_6,_7] 
  55.  
  56. Most Prologs do not keep the names of variables in terms being read in.
  57. The only exception is the top level loop, where usually a special predicate is used which returns variables together with their names as atoms. C-Prolog 1.5 has no such
  58. predicate, the top-level answer is hard-wired. If you insist on C-Prolog, use ROK's public domain parser read.pl and rdtok.pl which gives you both the term and a list of
  59. variable/name pairs.
  60.  
  61. --Micha
  62.  
  63. ---
  64. Micha Meier            ------------------------------------------------
  65. ECRC, Arabellastr. 17        The opinions expressed above are private
  66. D-8000 Munich 81        and may not reflect those of my employer.
  67. micha@ecrc.de, Tel. +49-89-92699-108, Fax  +49-89-92699-170
  68.  
  69.