Article View: comp.lang.prolog
Article #775Re: Help with C-Prolog, Please.
From: Micha Meier
Date: Fri, 04 Sep 1992 12:15
Date: Fri, 04 Sep 1992 12:15
55 lines
2112 bytes
2112 bytes
In article 8798@iccgcc.decnet.ab.com, baechtel@iccgcc.decnet.ab.com () writes: > > > In C-Prolog 1.5, is there anyway to get the name of a variable >in a term? > > Specifically, If I write: > >read(Term, Vars) :- > read(Term), > functor(Term,F,A), > getvars(Term,A,Vars,[]). > >getvars(Term,0,Varlist,Varlist). > >getvars(Term,A,Vars,Varlist) :- > arg(A,Term,Arg), > ( var(Arg), Vars1 = [Arg | Varlist]; Vars1 = Varlist), > A1 is A-1, > getvars(Term,A1,Vars,Vars1). > >If I execute read(Term,Vars) and my input is: "X is Y.", >Term = "X is Y" and Vars = [_15,_16]. > >Is there anyway to get Vars=[X,Y]? >I don't understand how to get the name of the Variable instead of its >reference. Actually, if I execute your code, I get | ?- read(Term, Vars). |: "X is Y". Term = [88,32,105,115,32,89] Vars = [] or, if the quotes were not meant to be there, | ?- read(Term, Vars). |: X is Y. Term = _6 is _7 Vars = [_6,_7] Most Prologs do not keep the names of variables in terms being read in. 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 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 variable/name pairs. --Micha --- Micha Meier ------------------------------------------------ ECRC, Arabellastr. 17 The opinions expressed above are private D-8000 Munich 81 and may not reflect those of my employer. micha@ecrc.de, Tel. +49-89-92699-108, Fax +49-89-92699-170
Technical Details
Message-ID:
<1992Sep4.121544.13871@ecrc.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!ecrc!acrab6!michaReferences:
<1992Sep3.164303.8798@iccgcc.decnet.ab.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.prolog Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!ecrc!acrab6!micha From: micha@ecrc.de (Micha Meier) Subject: Re: Help with C-Prolog, Please. Message-ID: <1992Sep4.121544.13871@ecrc.de> Sender: news@ecrc.de Reply-To: micha@ecrc.de Organization: European Computer-Industry Research Centre References: <1992Sep3.164303.8798@iccgcc.decnet.ab.com> Date: Fri, 4 Sep 1992 12:15:44 GMT Lines: 56