Icon+Unicon/Intro: Difference between revisions

Line 163:
 
=== Strong Typing through Operators ===
 
Icon/Unicon has variously been described as an untyped or strongly typed langauge depending upon the perspective of the observer. Consider the following examples:
* The lack of declaration and reassignment of x to different types of data suggest the language is untyped or loosely typed.
<lang Icon> x := 1
x := "Abc123"
x := table()</lang>
* Having specific operators for ambiguous operations, such as comparisons, means the intent of the program should be clear. While this can sometimes be annoying (see [[Sorting algorithms/Bubble sort]] it is necessary because in the case of mixed type comparisons the intent of a generalized comparison can't be determined.
<lang Icon> a := "11"
b := 2
if a << b then write("a is lexically less than b.")
if a > b the write("a is numerically greater than b.")</lang>
Additional, the strong typing is supported by safe data types.
 
=== Coercion: Implicit Type Conversions ===
Anonymous user