Page 1 of 1

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

Posted: 24 Apr 2016 7:01
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".

Posted: 24 Apr 2016 21:16
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.

Posted: 25 Apr 2016 6:27
by Ferenc Nagy
Thomas,
Thank you for the simple and logic explanation.