goer@SOPHIST.UCHICAGO.EDU (Richard Goerwitz) (09/11/89)
It is often extremely useful to test whether a variable has the type &null, in much the same way as one might perform boolean operations in other context with other languages. Recently a poster complained that variables of type &null could not be con- verted into other types automatically. Personally, I cannot see using Icon without &null. For instance, if a procedure that is supposed to assign a value to a variable fails, that variable will retain its previous value. In many cases, that value is null, and a simple slash can test whether this is the case or not. Rarely does the lack of any &null -> other types conversions com- plicate a program much. In the program submitted by the above- mentioned poster, it amounts to one extra line (comments are mine): procedure main() words:=table() line_no:=0 while line:=read() do { line_no +:=1 write(left(line_no,6),left(line,40)) line:=map(line) i:=1 while j:=upto(&lcase,line,i) do { i:=many(&lcase,line,j) if *line[i:j] >= 3 # # then {if \words[line[i:j]] #line 14 then insert(words[line[i:j]],line_no) #line 15 else {words[line[i:j]]:=set() #line 16 insert(words[line[i:j]], line_no) #line 17 } # Try instead: # # /words[line[i:j]] := set() # insert(words[line[i:j]],line_no) } } } words:=sort(words) i:=0 while pair:=words[i +:=1] do { writes(left(pair[1],10),":") s:=!pair[2] pair[2]:=delete(pair[2],!pair[2]) every s ||:= ", " ||!pair[2] write(s) } end I might point out that those i:j subscripting operations above are all much more elegantly handled by string scanning operations, such as: while substr := tab(many(&lcase)) do { tab(upto(&lcase)) *substr > 3 | next etc. Oh, and don't forget about sort(x,3)! -Richard L. Goerwitz goer@sophist.uchicago.edu rutgers!oddjob!gide!sophist!goer