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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

11611.7.VariantOperations sexpression:variantoflisptype( );'pair'->pair:conscellffullg conscell:record( 'atom'->atom:idfinitg, 'nil'->null:emptyfg,<br />

sexpressioncontaincomponentsoftypeconscell,whichinturncontaincomponentsoftypesexpression.<br />

beenrevealedtobeincase'pair',thenthetypestatewillbe );cdr:sexpression Notethatthesetypedenitionsaremutuallyrecursive|variablesoftype Inthisexample,ifVisavariableoftypesexpression,<strong>and</strong>ithasjust car:sexpression,<br />

Unite untiltheyarerevealedinturn.ItisnotlegaltodiscardV.Pair.Car,leavingapartiallyinitializedpair.Itis,however,legaltoreplacethevalueof<br />

init(V),case(V,V.Pair),init(V.Pair),init(V.Pair.Car),init(V.Pair.Cdr) Innercomponents,suchasV.Pair.Car.Pair.Cdr,willnotbeaccessible<br />

Theunitestatementinitializesavarianttoaparticularoneofitscases. Itstwooper<strong>and</strong>sareavariablenamedesignatingavariantcomponent, component.Thetypestateoftheexpressionmustbeatleastashighasthe <strong>and</strong>anexpressionevaluatingtoavalueofthesametypeasthatvariant casetypestateofthevariantcomponent.Ifitishigher,itiscoerceduntil itisexactlyequaltothecasetypestate. simple{statement<br />

Ifthevarianthadavalue,thatvalueisdiscarded.Thevalueofthe ::=unitevariant{componentfromsource{expression<br />

thevariantwillberevealed<strong>and</strong>thevariantcomponentwillbeaccessible. Thedissolvestatementreversestheeectoftheunitestatement.The Dissolve expressionisthenmovedintothevariantcomponent.Aftertheoperation,<br />

rstvariablenamedesignatesavariantcomponent.Thesecondvariable namedesignatesavariableofthesametypewhichwillreceivethevalueof thatvariantcomponent. destinationvariableisdiscarded.Thevalueofthevariantcomponentis Thevariantcomponentmustberevealed.Anypreviousvalueofthe simple{statement ::=dissolvevariant{componentintoresult{variable

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

Saved successfully!

Ooh no, something went wrong!