Discussions related to Visual Prolog
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Difference of toString(...) and tryConvert(string,...)

Unread post by Ferenc Nagy »

I have defined a

Code: Select all

domain     species = string.
When I wanted to pass a variable from this domain to a procedure having string arguments

Code: Select all

Species="cat",    V_String=toString(Species)
resulted result surrounded by double quotes.

Code: Select all

V_String=""cat"".
The conversion

Code: Select all

Species="cat",    V_String=tryConvert(string,Species)
resulted unchanged string.

Code: Select all

V_String="cat".
The complier warned me sometimes about "superfluous conversion from species to string".
TIA, Regards,
Frank Nagy
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

toString will "write" any term to the string in the serialization format used by toTerm/tryToTerm which is the same format used by save/consult/writeQuoted/read.

tryConvert will convert a value which is convertible to a string to that string. For strings that would mean any subtype of string and symbol; the value will not change only the type will change because such values are already strings.
Regards Thomas Linder Puls
PDC
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Unread post by Ferenc Nagy »

Thomas,
Thank you for the simple and logic explanation.
TIA, Regards,
Frank Nagy
Post Reply