= versus := Differences between unification and assignment operators.

Discussions related to Visual Prolog
Carlesius
Posts: 6
Joined: 28 May 2016 19:38

= versus := Differences between unification and assignment operators.

Unread post by Carlesius » 9 Jun 2016 1:41

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. :-)
Attachments
Small Scheme 32 low.jpg
The Scheme interpreter.
Vpi is very powerfull, I like it.
Small Scheme 32 low.jpg (242.92 KiB) Viewed 3852 times
Last edited by Carlesius on 9 Jun 2016 14:33, edited 1 time in total.

Peter Muraya
VIP Member
Posts: 146
Joined: 5 Dec 2012 7:29

Unread post by Peter Muraya » 9 Jun 2016 6:46

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.
Mutall Data Management Technical Support

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 9 Jun 2016 11:54

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.
AI Rules!
P.

Carlesius
Posts: 6
Joined: 28 May 2016 19:38

Re:

Unread post by Carlesius » 9 Jun 2016 14:30

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.

Carlesius
Posts: 6
Joined: 28 May 2016 19:38

Re:

Unread post by Carlesius » 9 Jun 2016 15:23

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.

Post Reply