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.

thetypestate(i.e.addattributes),butyoumaynotloweranyattributes. 644.3.Variants<br />

makesthetypestate ofLispObjectsaidthatincase'pair',componentPairisfull.This again,itwillhaveaknowntypestateregardlessofwhatyoudid.Sointhe aboveexample,Parms.L.Pairwillbefullyinitialized,sincethedenition Furthermore,anyattributesyouaddedwillbecoercedawaybeforethe variantishiddenagain.Thisguaranteesthatwhenthevariantisrevealed init(Parms.L.Pair),init(Parms.L.Pair.Car),init(Parms.L.Pair.Cdr)g finit(Parms.L),case(Parms.L,Parms.L.Pair),<br />

4.4Polymorphs beloweredbackautomaticallyassoonasyoutrytohideParms.L. plebyissuingrevealParms.L.Pair.Car.PrintName,thetypestatewill wouldyieldanimpossibletypestate.Ifyouraisethetypestate,forexam-<br />

wouldgetacompilererrormessagesayingthatattemptingtodropinit(Parms.L.Pair.Car) IfyouwrotediscardParms.L.Pair.Car,thiswouldbeillegal.You<br />

avariant. setofalternatives.Insuchacase,youhavetouseapolymorphinsteadof Avariantisusefulwhenyouknowaheadoftimeaxedsetofalternative types(ortypestates)avaluewillhave.Sometimesthereisanopen-ended<br />

typestateyouareexpectingmatchthetype<strong>and</strong>typestateappearingon mustbeunwrapped<strong>and</strong>itsvaluestoredbackintoavariableoftheappropriatetype.Atthistime,thereisarun-timecheckthatthetype<strong>and</strong><br />

insertedintoatableofpolymorphs,etc.Butnoneoftheoperationsofthe originaltypeareallowed.Inordertoissuetheseoperations,thepolymorph isalwaysstoredtogetherwithitstype<strong>and</strong>typestate.Thinkofthevalue tate.Whenthevalueiswrapped,itcanbestoredinapolymorphvariable, asbeingwrappedinanopaquewrapperlabelledwiththetype<strong>and</strong>types-<br />

Apolymorphisavariablewhichcanholdanytypeofvalue.Thevalue<br />

types.Youmayalsoinspectthewrappertoreadthetype<strong>and</strong>typestateof whichtheownerofaresource(e.g.aportintoaserver)maypostacopy thewrapper.<br />

oftheresource<strong>and</strong>aresourcename,<strong>and</strong>authorizedusersmayretrieve thewrappedvalue. theexceptionUncopyableifthewrappedvalueisoneoftheuncopyable intoatable.Itissyntacticallylegaltocopyapolymorph,butyouwillget <strong>and</strong>unwrappingarethoseoperationsallowedonalltypes,suchasinserting Hereisasimpleapplicationofpolymorphs|aresourcerepositoryinto Theonlyoperationsyoumayperformonapolymorphbesideswrapping<br />

Insteadwerequiretheownertowraptheresourceintoapolymorphbefore types,theinterfacetotherepositorycannotspecifyanyparticulartype. acopyofthatresourcebyname.Sincedierentresourcesareofdierent

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

Saved successfully!

Ooh no, something went wrong!