28.01.2015 Views

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

624.3.Variants<br />

thevariantcomponents.Theunitestatementsimultaneously:(1)setsthe assignmentstatementtocopythevalueofanothervariableofthesame youbuildanewvariant,youmustdecidewhichcasetoputthevariant in.Youmaynotdirectlyassigntoacomponentofanuninitializedvariant. Youmustinsteadusetheunitestatementtomoveavalueintooneof typewhichisalreadyinitialized.Oryoucanbuildanewvariant.When Therearetwowaystoinitializeanuninitializedvariant.Youcanusean initialized<strong>and</strong>revealedincase'nil'<br />

caseofthevariant,(2)movesthevalueofitsoper<strong>and</strong>intothevariant component,(3)tellsthecompilerthatthevariantisnowinitialized<strong>and</strong> revealed. 1.HereisanexampleofastatementwhichinitializesLintocase'atom': 2.ThisstatementputsLintocase'nil': 3.ThisstatementputsLintocase'pair': (EmptyvalisavariableoftypeEmpty.Itdoesn'tneedtobeinitialized, uniteL.NilfromEmptyval; uniteL.Printnamefrom"Foo"; sinceinthedenition,componentNilisexpectedtobeuninitialized.)<br />

example,whenvariantLisrevealedincase'atom',theattributecase(L, newPair; unitePair.Car.Printnamefrom"Foo";<br />

atypestateforeachvariantcomponent.Thisisthetypestatethevariant L.PrintName)ispresent.ThismeansthatL.PrintNameisthecomponent whichisknowntoexist. Thetypestateattributecaseispresentwhenthevariantisrevealed.For Whenyouwritethedenitionofthevarianttype,youhavetosupply uniteL.PairfromPair; unitePair.Cdr.NilfromEmptyval;<br />

timeitisrevealed|thatis,itmaybemademoreinitializedbutnotless. allwhenLisincase'nil'.` initializedwhenLisincase'pair',butL.Nilneednotbeinitializedat tively: isrevealed.Itisalsotheminimumtypestatethecomponentcanhaveany ThedenitionofLispObjectillustratedaboveshowsthatL.PrintName componentwillhave(1)justbeforeitbecomeshidden,<strong>and</strong>(2)justafterit mustbefullyinitializedwhenLisincase'atom',L.Pairmustbefully Thetypestateaftereachofthethreeunitestatementsaboveisrespec-<br />

1.finit(L),case(L,L.PrintName),init(L.PrintName)g

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!