Icon+Unicon/Intro: Difference between revisions

m
+ Datatypes framework
m (+ Datatypes framework)
Line 57:
immutable === i2 # succeeds
immutable === i3 # also succeeds</lang>
 
 
Furthermore even though strings are immutable, it is possible to construct the same string in different memory locations. You just can't tell if they are different or not.
 
=== Data Types ===
==== &null ====
&null is unique. It is a data type with only a single value, one instance only. While this may sound odd at first, &null is at the core of Icon/Unicon and contributes to the power and robustness of the language.
 
&null arose to overcome a short coming that any [[SNOBOL4]] programmer will be familiar with. Consider the following SNOBOL code:
 
<lang Snobol> numb1 = 2
numb2 = 3
output = "numb1+numb2=" numb1 + nmub2</lang>
 
In SNOBOL an undefined value defaults to the null string "" and the null string is coerced into a zero 0 if needed for math. Thus the surprise output above is 2 and not 5 as expected. While on close inspection the error is apparent, you can see how this could be missed in a large program predominated by global variables.
 
In Icon/Unicon &null is not coerced and so:
<lang Icon> write( 2 + &null ) # run time error 101
write( "abc" || &null ) # run time error 103
write( "abc", &null) # no error as write ignores &null </lang>
 
The power of &null comes from the simple null/non-null tests of which more anon.
 
==== integer ====
==== real ====
==== string ====
==== cset ====
==== Records ====
==== Sets ====
==== Tables ====
==== co–expression ====
==== procedure ====
==== class (unicon) ====
==== file ====
==== window ====
 
== Operators and Procedures ==
Anonymous user