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.

1.2GettingStarted|ASimple<strong>Hermes</strong>Program another.Thereissomecost:youhavetowritemoredeclarations. thoughsomeprogramsmayhavebugs<strong>and</strong>theusersdon'ttrustone 1.Introductionto<strong>Hermes</strong>5<br />

Let'sstartwithourrst<strong>Hermes</strong>program. siblytypedenitions.We'llshowyouinalatersectionhowtowritethem. receiveParmsfromInit;<br />

Pascal Let'sassumefornowthatyouhavealreadywrittenthemorthattheyhave alreadybeensuppliedforyou. doesitdierfromthecorrespondingprograminC,Ada([SYW85]),or Beforeyoucompilethisprogram,youhavetoadddeclarations<strong>and</strong>pos-<br />

ThisprogramcanbeusedtodisplaythemessageHello,World!.How callParms.PutLine("Hello,World!"); returnParms;<br />

PutLine.In<strong>Hermes</strong>,PutLineisaparameter;itscounterpartsintheother languagesareconstants. mesversionofthissimpleprogram<strong>and</strong>alltheothers|thelatebindingof syntax,thereisneverthelessanimportantdistinctionbetweentheHer-<br />

Althoughatrstglancetheprogramsappeartodieronlyinsupercial write("Hello,World!")fAPascalprogramg printf("Hello,World!");/*aCprogramtodotheabove*/<br />

IntheCprogram,printfhasaxedbinding|itdenotesalibraryprogramwhichwritesthecharacterstringtothest<strong>and</strong>ardoutput.Theonly<br />

Ifyoudothis,youwillalsochangethebindingofprintfforallthemod-<br />

([KR78]),functionsarenotvariables.Ifyouwanttocontrolthebindingof ulesofyourprogram.TousetheterminologyoftheCreferencemanual afunctionwithaCprogram,youmustsimulatefunctionvariablesusing pointerstofunctions.(SimilarlyinPascal([Coo83])<strong>and</strong>Ada,functionsare notvariables.Intheselanguagesthereisawaytoachievealimiteddegree ofdynamicbinding.) of<strong>Hermes</strong>:(1)nothingisglobal,<strong>and</strong>(2)everyfunctionorprocedurename referstoavariablewhosevalueisdeterminedatrun-time,notcompiletime.<br />

asParms.PutLine.<strong>Hermes</strong>isdesignedthiswaybecauseitassumesyou receivetheparameterlistParms<strong>and</strong>becausewemustrefertothefunction Soeveninthistiny<strong>Hermes</strong>program,youcanseetwoimportantfeatures<br />

PUT("Hello,World!")--AnADAprogram<br />

waytochangethebindingistolinkyourCprogramtoadierentlibrary.<br />

WhydowedothisAfterall,theprogramislongerbecausewemust

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

Saved successfully!

Ooh no, something went wrong!