🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.prolog
3 messages
3 total messages Started by baechtel Thu, 03 Sep 1992 21:43
Help with C-Prolog, Please.
#768
Author: baechtel
Date: Thu, 03 Sep 1992 21:43
31 lines
973 bytes

	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.

Can anyone suggest code that will work in C-Prolog?

Thanks in advance.
.
Re: Help with C-Prolog, Please.
#775
Author: Micha Meier
Date: Fri, 04 Sep 1992 12:15
55 lines
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
Re: Help with C-Prolog, Please.
#686
Author: Vasco Pedro
Date: Mon, 07 Sep 1992 12:02
30 lines
1204 bytes
In article <1992Sep4.121544.13871@ecrc.de> micha@ecrc.de (Micha Meier) writes:
> 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?
	.
	.
	.
	.
> [...] 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.

Or get c-prolog 1.6.edai:

	C Prolog version 1.6.edai
	% Restoring file /usr/local/lib/prolog/startup-1.6.edai
	yes
	| ?- read(A,B).
	|: A.
	B = [ 'A' = _0]
	A = _0
	yes

Cheers,
Vasco Pedro
--
.signature illegible
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads