|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
read_term and anonymous variablesHello all,
if i ask :- assert(a(1,2)). :- assert(a(3,4)). :-a(_,_). The top level returns true. if i ask :- read_term(T, [variables(V), variable_names(VN)]), call(T). and enter a(_,_). I get false which seems to be logical if i see 6 ?- read_term(T, [variables(V), variable_names(VN)]). |: a(_,_). T = a(_G588, _G588), V = [_G588], VN = ['_'=_G588]. What is the right behavior? How can I read a term to get the top-level behavior and the variablenames? Thanks in advance -- Kind regards Uwe Lesta _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: read_term and anonymous variablesOn 2009/10/26, at 08:32, Uwe Lesta wrote: > Hello all, > > if i ask > :- assert( > :- assert(a(3,4)). > :-a(_,_). > > The top level returns true. > > > if i ask > > :- read_term(T, [variables(V), variable_names(VN)]), call(T). > > and enter a(_,_). I get false which seems to be logical if i see > > 6 ?- read_term(T, [variables(V), variable_names(VN)]). > |: a(_,_). > T = a(_G588, _G588), > V = [_G588], > VN = ['_'=_G588]. > > > What is the right behavior? No. You found a bug. Every occurrence of an anonymous variable works as a distinct variable. Follows the above queries using GNU Prolog: | ?- read_term(T, [variables(V), variable_names(VN)]), call(T). a(_, _). T = a(3,4) V = [3,4] VN = [] ? ; T = a(1,2) V = [1,2] VN = [] (1 ms) yes | ?- read_term(T, [variables(V), variable_names(VN)]). a(_, _). T = a(A,B) V = [A,B] VN = [] yes Cheers, Paulo ----------------------------------------------------------------- Paulo Jorge Lopes de Moura, PhD Assistant Professor Dep. of Computer Science, University of Beira Interior 6201-001 Covilhã, Portugal Office 3.18 Ext. 3276 Phone: +351 275319891 Fax: +351 275319899 Email: <mailto:pmoura@...> Home page: <http://www.di.ubi.pt/~pmoura> Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> ----------------------------------------------------------------- _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: read_term and anonymous variablesOn Monday 26 October 2009 09:54:29 am Paulo Moura wrote:
> On 2009/10/26, at 08:32, Uwe Lesta wrote: > > Hello all, > > > > if i ask > > > > :- assert( > > : > > :- assert(a(3,4)). > > :-a(_,_). > > > > The top level returns true. > > > > > > if i ask > > > > :- read_term(T, [variables(V), variable_names(VN)]), call(T). > > > > and enter a(_,_). I get false which seems to be logical if i see > > > > 6 ?- read_term(T, [variables(V), variable_names(VN)]). > > > > |: a(_,_). > > > > T = a(_G588, _G588), > > V = [_G588], > > VN = ['_'=_G588]. > > > > > > What is the right behavior? > > No. You found a bug. Every occurrence of an anonymous variable works > > as a distinct variable. Follows the above queries using GNU Prolog: > | ?- read_term(T, [variables(V), variable_names(VN)]), call(T). > > a(_, _). > > T = a(3,4) > V = [3,4] > VN = [] ? ; > > T = a(1,2) > V = [1,2] > VN = [] > > (1 ms) yes Yip. Fixed. Using variables and variable_names in combination is appearently not often use. Patch is in development GIT. Should come in 5.9.0. Of course, you can also just use the variable_names option and use term_variables on the term read to find all variables ... I wonder who believed the option variables to read_term makes sense ... --- Jan _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: read_term and anonymous variablesJan Wielemaker schrieb: <snip> > Yip. Fixed. Using variables and variable_names in combination is > appearently not often use. Patch is in development GIT. Should come > in 5.9.0. > > Of course, you can also just use the variable_names option and use > term_variables on the term read to find all variables ... I wonder > who believed the option variables to read_term makes sense ... Hello Jan, Thank you and Paulo for clarification. I'll have changed the call of read_term/2 to read_term(T, [variable_names(VN)]) and build the list of variables in CSharp ( leaving a comment about term_variables/2 ;-) IMO the option variables/1 of read_tern/2 is superfluous. A link to term_variables/2 in the comment about the option variable_names/1 might be useful. Thanks a lot. -- Kind regards Uwe Lesta _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
| Free embeddable forum powered by Nabble | Forum Help |