Conversion operators

Q includes several conversion operators. The syntax of these operators is the same as that of function application. There are four conversion operators, string, integer, real, and boolean, that support the conversion of values from any basic type to any other basic type, where the basic types are string, integer, real, and boolean. Most of these conversions are obvious. The following is a list of the non-obvious conversions (b, s, i, and r are boolean, string, integer, and real expressions):

   integer b ≡ if b then 1 else 0
   real b ≡ if b then 1.0 else 0.0
   boolean s ≡ if s = "true" then true else false
   boolean i ≡ if i = 0 then false else true
   boolean r ≡ if r = 0.0 then false else true

Here are some examples of applying the conversion operators:

   integer "77" ⇒ 77
   string true ⇒ true
   integer true ⇒ 1
   boolean "true" ⇒ true
   boolean "foo" ⇒ false
   boolean 25 ⇒ true
   integer string 5 ≡ integer (string (5)) ⇒ 5
   integer string 5 + 7 ≡ (integer (string (5))) + 7 ⇒ 12
   integer boolean 5 + 7 ⇒ 8

Feedback