Code Comments
Programming Forum and web based access to our favorite programming groups.Hi All, I am trying to assign a variable the value of another variable - so I am looking for something of the form X = Y, where X would have the value of Y rather than checking if X is equal to Y or not. I saw something about using :=, but this does not compile under both Sicstus Prolog and SWI Prolog. I look forward to hearing from you soon. Regards, George
Post Follow-up to this messageOn Apr 2, 1:08 pm, George <m...@me.com> wrote: > Hi All, > > I am trying to assign a variable the value of another variable - so I am > looking for something of the form X = Y, where X would have the value of > Y rather than checking if X is equal to Y or not. I saw something about > using :=, but this does not compile under both Sicstus Prolog and SWI > Prolog. > > I look forward to hearing from you soon. > > Regards, > George Use is/2, for example X is 2+3. regards, chip
Post Follow-up to this messageOn Apr 2, 1:08 pm, George <m...@me.com> wrote: > Hi All, > > I am trying to assign a variable the value of another variable - so I am > looking for something of the form X = Y, where X would have the value of > Y rather than checking if X is equal to Y or not. I saw something about > using :=, but this does not compile under both Sicstus Prolog and SWI > Prolog. > > I look forward to hearing from you soon. > > Regards, > George Actually when you are dealing with variables X and Y, the subgoal X=Y may have your desired effect. Rather than "assignment", the Prolog terminology would be to "unify" these two variables. So X=Y checks to see if these expressions can be unified, and succeeds by effectively treating them as thereafter bound to one another. The "assignment" X=Y can fail only if X and Y are already bound to expressions that cannot be unified. Where you may be frustrated is the fundamental design of Prolog in not allowing reassigning values to a variable. Once we have succeeded in binding X = 2 and Y = 3, we cannot get X = Y to succeed by "changing" the assignment of X. regards, chip
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.