corre@csd4.milw.wisc.edu (Alan D Corre) (08/08/89)
I wanted to write an Icon procedure to check if a string has precisely
22 characters (the size of the Hebrew alphabet) and no duplicate
characters, so I wrote the following:
procedure checkstring(abc)
local cs, current
if *abc ~= 22 then fail #check length
cs := '' #initialize cset
abc ? every 1 to 22 do {
current := move(1) #select a char
if cs ** current ~=== '' then fail #char is already a member
cs ++:= current } #char is ok
return
end
The procedure worked fine, but I said: "That isn't an Icon procedure.
It's a thinly disguised Pascal function. Now write an Icon procedure."
So I forsook "IF mouse IN hole" and wrote:
procedure checkstring2(abc)
local t, current
if *abc ~= 22 then fail
t := table(22)
abc ? every 1 to 22 do {
current := move(1)
\t[current] | fail
t[current] := 1 }
return
end
More Icon constructs, but no better really.
Then I wrote:
procedure checkstring3(abc)
return *abc = *cset(abc) = 22
end
Now that's an Icon procedure.
--
Alan D. Corre
Department of Hebrew Studies
University of Wisconsin-Milwaukee (414) 229-4245
PO Box 413, Milwaukee, WI 53201 corre@csd4.milw.wisc.edu