| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I want to write a program in Prolog that acts like this: ?- fvar(FV),fvar_add(FV,(writeq(FV),nl)),FV=1,FV=2,wr iteq(FV). 1 2 FV=_G234234 ; yes. Is there a shourt example of using attributed vars to define fvar/1 and fvar_add/2 To exhibit this behavour? Thank you in advance! |
|
#2
| |||
| |||
| On Mon, 18 Aug 2008 01:05:13 -0700, logicmoo wrote: > ?- fvar(FV),fvar_add(FV,(writeq(FV),nl)),FV=1,FV=2,wr iteq(FV). 1 > 2 > FV=_G234234 ; > yes. > > Is there a shourt example of using attributed vars to define > > fvar/1 and fvar_add/2 To exhibit this behavour? What Prolog system do you use ? Cheers Bart Demoen |
|
#3
| |||
| |||
| Usually SWI-Prolog, but I have been known to use others. Every time I am reading a manual on attrbuted variables http://gollem.science.uva.nl/SWI-Pro...ng.html#when/2 I start to get confused. whether this is freeze/2 or when/2. (freeze/2 is a one time shot?) But don't worry about being swi specific "Bart Demoen" <bmd@cs.kuleuven.be> wrote in message news:g8bcth$ts9$1@ikaria.belnet.be... > On Mon, 18 Aug 2008 01:05:13 -0700, logicmoo wrote: > >> ?- fvar(FV),fvar_add(FV,(writeq(FV),nl)),FV=1,FV=2,wr iteq(FV). 1 >> 2 >> FV=_G234234 ; >> yes. >> >> Is there a shourt example of using attributed vars to define >> >> fvar/1 and fvar_add/2 To exhibit this behavour? > > > What Prolog system do you use ? > > Cheers > > Bart Demoen |
|
#4
| |||
| |||
| On 2008-08-18, Bart Demoen <bmd@cs.kuleuven.be> wrote: > On Mon, 18 Aug 2008 01:05:13 -0700, logicmoo wrote: > >> ?- fvar(FV),fvar_add(FV,(writeq(FV),nl)),FV=1,FV=2,wr iteq(FV). 1 >> 2 >> FV=_G234234 ; >> yes. >> >> Is there a shourt example of using attributed vars to define >> >> fvar/1 and fvar_add/2 To exhibit this behavour? Having implemented the SWI-Prolog attvars (after specs from Bart Demoen), I can't see a way how the conjunction FV=1,FV=2 will ever succeed. Attvars or not. Maybe you should try to describe your problem at a somewhat higher abstraction level. Cheers --- Jan |
|
#5
| |||
| |||
| On Mon, 18 Aug 2008 02:03:54 -0700, logicmoo wrote: > But don't worry about being swi specific I asked, because I thought it might be possible in XSB. It is definitely not possible in SWI, neither in other reasonable implementations of attributed variables. In XSB, you can (or at least could in some release) "unify" the same attributed variable more than once (in the same forward continuation), without it becoming bound, and in the unification hook you could do a trick that produces the output you want, but why go through all that bother ? You probably want something else. Cheers Bart Demoen |
|
#6
| |||
| |||
| What I am looking for is to create a unification check on writes to a variable. Simular to how domain/2 works in XSB, except ALSO something problably almost impossible to expect that the unification to the variable would leave no side effects. "FV=_G234234 " But yeah, that conjunction is an anoyance that I should leave out: fvar(FV), fvar_add(FV, (writeq(FV),member(FV,[1,2,4]),nl)), (FV=1 ; FV=3 ; FV=2), writeq(here(FV)),nl,fail. 1 here(1) 32 here(2). no. On the higher level it more actually so I understand what attributed variables are best used for. If they are used as a way to load up constraints on prolog predicates like: mother(Child,Mom):-myattr_put(Child,younger(Child,Mom)),myattr_put(Mo m,female(Mom)),parentof(Mom,Child). testing female/1 only on binding of Mom durring execution of proceedure parentof/2. "Jan Wielemaker" <jan@nospam.ct.xs4all.nl> wrote in message news:slrngaif4p.7se.jan@ct.lan... > On 2008-08-18, Bart Demoen <bmd@cs.kuleuven.be> wrote: >> On Mon, 18 Aug 2008 01:05:13 -0700, logicmoo wrote: >> >>> ?- fvar(FV),fvar_add(FV,(writeq(FV),nl)),FV=1,FV=2,wr iteq(FV). 1 >>> 2 >>> FV=_G234234 ; >>> yes. >>> >>> Is there a shourt example of using attributed vars to define >>> >>> fvar/1 and fvar_add/2 To exhibit this behavour? > > Having implemented the SWI-Prolog attvars (after specs from Bart > Demoen), I can't see a way how the conjunction FV=1,FV=2 will ever > succeed. Attvars or not. Maybe you should try to describe your > problem at a somewhat higher abstraction level. > > Cheers --- Jan |
|
#7
| |||
| |||
| "bart demoen" <bmd@cs.kuleuven.be> wrote in message news:g8bfqo$v12$1@ikaria.belnet.be... > On Mon, 18 Aug 2008 02:03:54 -0700, logicmoo wrote: > >> But don't worry about being swi specific > > I asked, because I thought it might be possible in XSB. > It is definitely not possible in SWI, neither in other reasonable > implementations of attributed variables. > > In XSB, you can (or at least could in some release) "unify" the same > attributed variable more than once (in the same forward continuation), > without it becoming bound, and in the unification hook SWI-prolog once had a unify_hook I think taken out becasue it'd be a real slowdown or a terrable thorn to live with. I never got a chance to try it.. but i wondered if one could somehow setarg or something to mess with one side. of unification. > you could do a > trick that produces the output you want, but why go through all that > bother ? Why did XSB allow this at one time? Was there a solver strategy it was going to try that could leverage this? > You probably want something else. Sorry to be annoying, but I am floundering to what I want. . I want is to be able to write this: knows(X,Y):- fvar_add(Y, (has_attr(X,value(fred))->myattr_put(Y,value(bill))), fvar_add(X, (has_attr(Y,value(bill))->myattr_put(X,value(fred))). knows(X,Y):-myattr_put(X,human(X)),myattr_put(Y,human(Y)). ?- X=_,Y=_, findall(_,knows(X,Y),_). X = _G345345 { value(fred),human(X) } Y = _G345346 { value(bill),human(Y) } > > Cheers > > Bart Demoen |
|
#8
| |||
| |||
| On Aug 18, 10:05*am, <logic...@comcast.net> wrote: > I want to write a program in Prolog that acts like this: > > ?- fvar(FV),fvar_add(FV,(writeq(FV),nl)),FV=1,FV=2,wr iteq(FV). > 1 > 2 > FV=_G234234 ; > yes. > > Is there a shourt example of using attributed vars to define > > fvar/1 and fvar_add/2 *To exhibit this behavour? > > Thank you in advance! How about the following: fvar_unify(FV, Val) :- \+ \+ FV = Val. fvar_add(FV, Goal) :- freeze(FV, Goal). test(FV) :- fvar_add(FV, (write(FV), nl)), fvar_add(FV, (X is FV * 2, write(X), nl)), fvar_unify(FV, 1), fvar_unify(FV, 2). Does this work for you? |
|
#9
| |||
| |||
| Actualy it does! good thinking with the \+ \+ FV = Val. About me trying to = was not sane, but fvar_unify/2 might work out. fvar_add(FV, Goal) :- freeze(FV, Goal). Does freeze/2 only fire once by design? Will it unfreeze on redo and freeze again? "void" <martinlaz@gmail.com> wrote in message news:ab089846-7751-429f-b715-2e9000753520@m45g2000hsb.googlegroups.com... On Aug 18, 10:05 am, <logic...@comcast.net> wrote: > I want to write a program in Prolog that acts like this: > > ?- fvar(FV),fvar_add(FV,(writeq(FV),nl)),FV=1,FV=2,wr iteq(FV). > 1 > 2 > FV=_G234234 ; > yes. > > Is there a shourt example of using attributed vars to define > > fvar/1 and fvar_add/2 To exhibit this behavour? > > Thank you in advance! How about the following: fvar_unify(FV, Val) :- \+ \+ FV = Val. fvar_add(FV, Goal) :- freeze(FV, Goal). test(FV) :- fvar_add(FV, (write(FV), nl)), fvar_add(FV, (X is FV * 2, write(X), nl)), fvar_unify(FV, 1), fvar_unify(FV, 2). Does this work for you? |
|
#10
| |||
| |||
| On Aug 19, 3:41*pm, <logic...@comcast.net> wrote: > fvar_add(FV, Goal) :- > * * freeze(FV, Goal). > > Does *freeze/2 *only fire once by design? No. For instance ?- freeze(X, write('(')), freeze(X, write(X)), freeze(X, (write(')'), nl)), member(X, [1, 2, 3]), fail. is supposed to print out (1) (2) (3) |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.