• Nem Talált Eredményt

8. P rogram S pecification s

8.1. Som e E xam p les

Now we are ready to look a t a few exam ples. As a m a tte r o f course, we will m ake gross sim plifications again to avoid com plications. W e will also dro p type su b scrip ts on variables when th ey a re obvious.

8 .3 . E x a m p l e

Ti(rm file) d= (0;

(E X IST C H E C K = 1 file ± _L) A

(W R IT E C H E C K = 1 —> fiIe.write_permission = 1 ) ; file = -L;

{file}).

This definition says th e following. F irst, we assum e no changes for th e local envi­

ronm ent. Second, a m achine s ta te satisfies th e in p u t condition of th is p ro g ram if and on ly if the value of file — i.e., th e first argum ent — is an existing file (if E X ­ IS T C H E C K is set to 1), an d th e u ser h as w rite perm ission to it (if W R IT E C H E C K is set to 1). T he m ax im al change th a t th e pro g ram effects is th a t the file’s value

8.1. Some Examples 23 is th e n o n -ex isten t file in th e o u tp u t s ta te (J_fiie denotes n o n -e x isten t files, a n d file is th e only m em ber of th e environm ent change).

To show how th e m echanism works, we spell out th is fo rm u la in L /ps);

8 .4 . E x a m p l e

!(E X IS T C H E C K = 1 -> -.(file = X))A

(W R IT E C H E C K = 1 —> file.w rite_perm ission = 1))A 3 file [! (file = _L)]

By c alcu latin g th e sem antics of this fo rm u la according to th e rules giv en in def­

in itio n 7 .6 , it is easy to see th a t it expresses exactly th e co n d itio n s o n pairs of m ach in e sta te s spelt ou t above. T h e closure o p erato rs a re vacuous in th is case, b u t th e y will be needed la te r on, w hen LEN V will no t b e em pty, to close off dy­

nam ic effects, as we explained above. As th e m echanism sh ould b e obvious, we do n o t give these tran slatio n s later except w hen we w ant to illu s tra te som e point explicitly.

8 .5 . E x a m p l e

r i ( c a t file) d= f (0;

file ^ 1 A SC R E E N / 1 ;

S C R E E N .content = S C R E E N .content "'fife.content;

{SC R E EN , content});

T his ex am p le works as follows. We assum e no local changes to th e environm ent;

th e file referred to by th e argum ent as well as th e file t h a t th e v ariab le SC R EE N refers to m u st exist; th e content of file m u st be c o n c a te n a te d a t th e e n d of the co n ten t o f th e stream referred to by th e S C R E E N variable (norm ally, th e file asso­

ciated w ith th e u ser’s screen, i.e., t t y ) . Finally, at m ost th e co n ten t o f th is stream will b e different from th e in p u t s ta te to th e o u tp u t s ta te , as th e la st com ponent of th e p ro g ram specification shows. Now, in actu al fact, th e c o m m an d c a t only affects th e s ta te of th e m achine if th e co n ten t of its o u tp u t file is s to re d on disk.

T h e u s e r’s screen is usually no t such a file. N evertheless, fo r th e sake o f uniform ity, we consider it as if it contained the c o n caten atio n of e v ery th in g th a t h a s ap p eared on th e screen before.

8 .6 . E x a m p l e

t i(cc file) = f ({ (O U T P U T F IL E , a . o u t)} ; file ± X;

O U T P U T F IL E .co n ten t = cc(file.content);

{ O U T P U T F IL E .co n ten t} ).

T his is o u r first exam ple containing a non -em p ty LENV c o m p o n en t, w h ich locally assigns th e value a . o u t to th e variable O U T P U T F IL E . As we know, th is is the

24 8.1. Some Examples default n am e o f th e o u tp u t o f th e program c c (the C com piler). (T h e sym bol

‘a . o u t ’ is a c tu a lly m eant to b e a variable th a t evaluates to the file n a m e d th a t way in th e d irecto ry stru c tu re .) So one o f th e uses of LE N V will be to assign d efau lt values to variables in analogous cases. T he preco n d itio n says th a t th e in p u t file has to exist, and th e change effected is to store th e compiled version of th e source p ro g ram to O U T P U T F IL E . N ote th a t cc in th e M C com ponent is th e a c tu a l C com piler, invoked by th e shell. It is n o t to be confused w ith cc, w hich in tro d u ces th e com m and line t h a t th e shell processes. T h e shell looks up cc in its lexicon an d a cts accordingly, w hereas it sim ply passes cc to th e o p eratin g sy stem w ith th e a p p ro p ria te p aram eters. So, in an a c tu a l im plem entation, th e shell will p e rfo rm th e following tran slatio n :

cc file —* cc -o a . o u t file.

As here is th e first case w ith a non-em pty LENV, we will give th e D F O L E tra n s la tio n again:

8 .7 . E x a m p l e

!(3 0 U T P U T F IL E [0 U T P U T F IL E = a .o u t ] A -(file = J_))A 3 0 U T P U T F IL E . c o n ten t

[□ O U T P U T F IL E

[O U T P U T F IL E = a. out j A

O U T P U T F IL E .co n ten t = cc(file.content)]

H ere ag ain we can calculate th e sem antic value of th e D F O L E form ula to verify th a t it coincides w ith the in te n d e d in te rp re ta tio n of our quadruple. F u rth erm o re, we can now see how the closure o p erato r closes off unw anted dynam ic effects.

N o te th a t th e o u tp u t s tre a m SC R EEN in th e exam ple 8 .5 also has a default value (nam ely, t t y ) . The two different tre a tm e n ts of SC R E E N vs. O U T P U T F IL E in exam ples 8 .5 —8 .6 reflect a d istin c tio n t h a t we intend to m ake betw een two types o f default values. The first ty p e , called deictically available defaults (DAD) , are sim ilar to here a n d now in n a tu r a l languages. The d efau lt value of S C R E E N belongs to th is type. Sim ilar default values include KBD (th e u ser’s k ey b o ard is th e d efau lt value for th e c u rre n t input stre a m ), H O M E (defaults to th e u se r’s hom e d irecto ry ) etc. The o th e r type is called non-deictically available defaults ( NAD) , w hich contain all th e o th e r default values (for exam ple, th e d efau lt n am e of th e o u tp u t file produced by th e C com piler in the above exam ple). T h ese are d eterm in ed by com m and n am es lexically. In th is respect (b u t only in th is resp ect) th e y a re sim ilar to lexically d eterm in ed p ro p e rtie s of m issing argum ents in n a tu ra l language. For exam ple, th e d ire c t object o f th e verb eat in I am eating h as th e d efau lt p ro p e rty ‘food’, which can be overridden by an explicit direct o b ject, as in I am eating sand. On the o th e r hand, th e o p tio n al ‘source’ argum ent o f th e verb

8.1. Some Examples 25 leave as in He left defaults to ‘h ere’, a deictically available d efau lt, a n d can also be ov errid d en by an explicit argum ent, as in He left Los Angeles. T h e different tre a tm e n ts o f DAD an d NAD will allow us to m ake a sim ilar d istin c tio n in our shell language.

KAPCSOLÓDÓ DOKUMENTUMOK