eMacintosh,MS-DOS,manyUNIXsystems,andVAX\/VMS.TheremainderofthisreportbrieflydescribesthehighlightsofIcon.Foracompletedescription,seeReferences1and2.
2.ExpressionEvaluation
2.1ConditionalExpressions
InIconthereareconditionalexpressionsthatmaysucceedandproducearesult,ormayfailandnotproduceanyresult.Anexampleisthecomparisonoperation
i>j
whichsucceeds(andproducesthevalueofj)providedthatthevalueofiisgreaterthanthevalueofj,butfailsotherwise.Similarly,
i>j>k
succeedsifthevalueofjisbetweeniandk.
【𝗼𝗼𝗽.𝘁𝘄 無錯章節】
ThesuccessorfailureofconditionaloperationsisusedinsteadofBooleanvaluestodrivecontrolstructuresinIcon.Anexampleis
ifi>jthenk:=ielsek:=j
whichassignsthevalueofitokifthevalueofiisgreaterthanthevalueofj,butassignsthevalueofjtokotherwise.
Theusefulnessoftheconceptsofsuccessandfailureisillustratedbyfind(s1,s2),whichfailsifs1doesnotoccurasasubstringofs2.Thus
ifi:=find(\"or\",line)thenwrite(i)
writesthepositionatwhich\"or\"occursinline,ifitoccurs,butdoesnotwriteavalueifitdoesnotoccur.
ManyexpressionsinIconareconditional.Anexampleisread(),whichproducesthenextlinefromtheinputfile,butfailswhentheendofthefileisreached.ThefollowingexpressionistypicalofprogramminginIconandillustratestheintegrationofconditionalexpressionsandconventionalcontrolstructures:
whileline:=read()do
write(line)
Thisexpressioncopiestheinputfiletotheoutputfile.
Ifanargumentofafunctionfails,thefunctionisnotcalled,andthefunctioncallfailsaswell.This\"inheritance\"offailureallowstheconciseformulationofmanyprogrammingtasks.Omittingtheoptionaldoclauseinwhile-do,thepreviousexpressioncanberewrittenas
))(daer(etirwelihw
srotareneG2.2
redisnoC.tluserenonahteromgnicudorpfoelbapacebyamnoisserpxena,snoitautisemosnI
"\robrahgnirobhgienehtnitierotS"\=:ecnetnes
)ecnetnes,"\ro"\(dnif
.snoitisopeerhtllagnicudorpfoelbapacsidnarotarenegasinoisserpxenahcus,nocInI.noisserpxeehtfotluserehtsa,tsrifehtsahcus,snoitisopehtfoenognitcelesybnoitautissihttaertsegaugnalgnimmargorptsoM.33dna,32,3snoitisoptaecnetnesnisrucco"\ro"\ereH
nisa,decudorpsitsrifeht,dedeensitluserenoylnoerehwnoitautisanI.txetnocnodnepedsecudorprotarenegatahtstluserehT
)ecnetnes,"\ro"\(dnif=:i
.iot3eulavehtsngissahcihw
xenA.eulavrehtonaecudorpotdemusersirotarenegeht,revewoh,noisserpxegnisolcnenafosseccusehtotdaeltonseodrotarenegaybdecudorptluserehtfI