Page 1 of 1

= versus := Differences between unification and assignment operators.

Posted: 9 Jun 2016 1:41
by Carlesius
Hello

At first I want to introduce me in this forum.
I started in Berlin in the 80s to work with Borland Turbo Prolog and then I developed with PDC Prolog at Daimler-Benz an expert system for configuring vehicles.
As assistent for VIP technical support at the Berlin company Logitek, I visited in those years in Copenhagen PDC Prolog and met Leo Jensen.
As a hobby I developed with Visual Prolog a Scheme interpreter as described in "Structure and Interpretation of Computer Programs" which among other features allows arithmetic operations with integers of many digits (up to several thousand) and AutoLISP style draw commands, with which Lisp programs can generate technical drawings.
Until 2000 I worked with Vip 5.0 but stopped programming in Prolog to work with Smalltalk at a Swiss company.
Now, after 15 years, I want to work again (first as hobby) with Visual Prolog. So what I'm studying new aspects of the language with the Personal Edition. I want to buy very soon the Professional Edition.

But first I have some questions (or criticism to documentation):
In Prolog '=' is the operator for term unification. On the other hand, in conventional programming languages ':=' is the operator for assigning values to variables.
In this code extract from Family Tutorial at AncestorDialog.pro

Code: Select all

domains     optionalString = none(); one(string Value).   class facts     name : optionalString := none().   clauses     tryGetName(Parent) = Name :-         name := none(),         _ = ancestorDialog::display(Parent),         one(Name) = name.
both operators are used. :?

I could not find anywhere in the documentation, when one or the other operator has to be used. :-(


Thank very much for a prompt response.
Greetings from South America. :-)

Posted: 9 Jun 2016 6:46
by Peter Muraya
Hello Carlesius. Welcome.
I have not checked to see where this is documented but from my experience in Visual Prolog, this

Code: Select all

name := none(),
assigns the none() value to the name fact

And this

Code: Select all

name = none()
is a unification that would cause the clause to succeed if the name fact is set to none; otherwise it fails.

The assignment is specific to fact variables.

Posted: 9 Jun 2016 11:54
by Paul Cerkez
Welcome back.

See: http://wiki.visual-prolog.com/index.php ... ence/Facts

:= is the assignment operator (for facts)
= is equality test if both are bound variables or assignment if one is free.

Re:

Posted: 9 Jun 2016 14:30
by Carlesius
Thanks Peter

Now I understand how the code works.
If at last line of this code

Code: Select all

domains     optionalString = none(); one(string Value). class facts     name : optionalString := none(). clauses     tryGetName(Parent) = Name :-         name := none(),         _ = ancestorDialog::display(Parent),         one(Name) = name. clauses     display(Parent) = Dialog :-         Dialog = new(Parent),         Dialog:show().   clauses     new(Parent) :-         dialog::new(Parent),         generatedInitialize().   predicates     on_ok_ancestor_clicked : button::clickResponder. clauses     on_ok_ancestor_clicked(_Source) = button::defaultAction :-     Name = idc_ancestordialog_personname:getText(),     name := one(Name).
the name fact become as value one(Name),
then at last line of this

Code: Select all

clauses     tryGetName(Parent) = Name :-         name := none(),         _ = ancestorDialog::display(Parent),         one(Name) = name.
the terms can be unified and the clause succeed.

Re:

Posted: 9 Jun 2016 15:23
by Carlesius
Paul Cerkez wrote:Welcome back.

See: http://wiki.visual-prolog.com/index.php ... ence/Facts

:= is the assignment operator (for facts)
= is equality test if both are bound variables or assignment if one is free.
Thanks Paul Cerkez, the link and clarifications regarding operators have been a good help. :-)
I have to study more closely the Language Reference.