Podobne
- Strona startowa
- Peter Charles Hoffer The Brave New World, A History of Early America Second Edition (2006)
- Hamilton Peter F. Swit nocy 2.2 Widmo Alchemika Konflikt
- Peter J. Thuesen Predestination, The American Ca
- Peter Marchand The Yoga of the Nine Emotions (2)
- Jadro dziwnosci Peter Pomerantsev
- Peter Zarrow China in War
- Bednarz Andrzej Medytacja teoria i praktyka (2)
- Nowakowski Sawomir Uroda i Zdrowie
- Conan Doyle A. Przygody Sherlocka Holmesa
- Collins Suzanne Igrzyska Âśmierci 01 Igrzyska Âśmierci
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- mrowkodzik.xlx.pl
Cytat
Do celu tam się wysiada. Lec Stanisław Jerzy (pierw. de Tusch-Letz, 1909-1966)
A bogowie grają w kości i nie pytają wcale czy chcesz przyłączyć się do gry (. . . ) Bogowie kpią sobie z twojego poukładanego życia (. . . ) nie przejmują się zbytnio ani naszymi planami na przyszłość ani oczekiwaniami. Gdzieś we wszechświecie rzucają kości i przypadkiem wypada twoja kolej. I odtąd zwyciężyć lub przegrać - to tylko kwestia szczęścia. Borys Pasternak
Idąc po kurzych jajach nie podskakuj. Przysłowie szkockie
I Herkules nie poradzi przeciwko wielu.
Dialog półinteligentów równa się monologowi ćwierćinteligenta. Stanisław Jerzy Lec (pierw. de Tusch - Letz, 1909-1966)
[ Pobierz całość w formacie PDF ]
.Again the programmer is not made aware of the error s existence.The third and fourth cases are reasonable in certain situations.In the third,a program with a use error will signal this fact, instead of silently continuing.This is reasonable in a sequential system, since there really is an error.It isunreasonable in a concurrent system, since the result becomes nondeterministic:depending on the timing, sometimes an error is signaled and sometimes not.Inthe fourth, the program will wait until the variable is bound, and then continue.This is unreasonable in a sequential system, since the program will wait forever.Copyright © 2001-3 by P.Van Roy and S.Haridi.All rights reserved.50 Declarative Computation Models ::=skip Empty statement| s 1 s 2 Statement sequence| local x in s end Variable creation| x 1= x 2 Variable-variable binding| x = v Value creation| if x then s 1 else s 2 end Conditional| case x of pattern then s 1 else s 2 end Pattern matching| { x y 1.y n} Procedure applicationTable 2.1: The declarative kernel languageIt is reasonable in a concurrent system, where it could be part of normal operationthat some other thread binds the variable.5 The computation models of this bookuse the fourth case.Declarative variables that cause the program to wait until they are bound arecalled dataflow variables.The declarative model uses dataflow variables becausethey are tremendously useful in concurrent programming, i.e., for programs withactivities that run independently.If we do two concurrent operations, say A=23and B=A+1, then with the fourth solution this will always run correctly and givethe answer B=24.It doesn t matter whether A=23 is tried first or whether B=A+1is tried first.With the other solutions, there is no guarantee of this.This propertyof order-independence makes possible the declarative concurrency of Chapter 4.It is at the heart of why dataflow variables are a good idea.2.3 Kernel languageThe declarative model defines a simple kernel language.All programs in themodel can be expressed in this language.We first define the kernel languagesyntax and semantics.Then we explain how to build a full language on top ofthe kernel language.2.3.1 SyntaxThe kernel syntax is given in Tables 2.1 and 2.2.It is carefully designed to be asubset of the full language syntax, i.e., all statements in the kernel language arevalid statements in the full language.5Still, during development, a good debugger should capture undesirable suspensions if thereare no other running threads.Copyright © 2001-3 by P.Van Roy and S.Haridi.All rights reserved.2.3 Kernel language 51v ::= number | record | procedurenumber ::= int | floatrecord , pattern ::= literal| literal ( feature 1: x 1.feature n: x n)procedure ::= proc { $ x 1.x n} s endliteral ::= atom | boolfeature ::= atom | bool | intbool ::= true | falseTable 2.2: Value expressions in the declarative kernel languageStatement syntaxTable 2.1 defines the syntax of s , which denotes a statement.There are eightstatements in all, which we will explain later.Value syntaxTable 2.2 defines the syntax of v , which denotes a value.There are three kindsof value expressions, denoting numbers, records, and procedures.For records andpatterns, the arguments x 1,., x n must all be distinct identifiers.This ensuresthat all variable-variable bindings are written as explicit kernel operations.Variable identifier syntaxTable 2.1 uses the nonterminals x and y to denote a variable identifier.Wewill also use z to denote identifiers.There are two ways to write a variableidentifier:" An uppercase letter followed by zero or more alphanumeric characters (let-ters or digits or underscores), for exampleX,X1, orThisIsALongVariable_IsntIt." Any sequence of printable characters enclosed within (back-quote) char-acters, e.g., `this is a 25$\variable!`.A precise definition of identifier syntax is given in Appendix C.All newly-declaredvariables are unbound before any statement is executed.All variable identifiersmust be declared explicitly.2.3.2 Values and typesA type or data type is a set of values together with a set of operations on thosevalues.A value is of a type if it is in the type s set.The declarative modelis typed in the sense that it has a well-defined set of types, called basic types.For example, programs can calculate with integers or with records, which are allCopyright © 2001-3 by P.Van Roy and S.Haridi.All rights reserved.52 Declarative Computation Modelof integer type or record type, respectively.Any attempt to use an operationwith values of the wrong type is detected by the system and will raise an errorcondition (see Section 2.6).The model imposes no other restrictions on the useof types.Because all uses of types are checked, it is not possible for a program to behaveoutside of the model, e.g., to crash because of undefined operations on its internaldata structures.It is still possible for a program to raise an error condition, forexample by dividing by zero.In the declarative model, a program that raisesan error condition will terminate immediately.There is nothing in the model tohandle errors.In Section 2.6 we extend the declarative model with a new concept,exceptions, to handle errors.In the extended model, type errors can be handledwithin the model.In addition to basic types, programs can define their own types, which arecalled abstract data types, ADT for short.Chapter 3 and later chapters showhow to define ADTs.Basic typesThe basic types of the declarative model are numbers (integers and floats), records(including atoms, booleans, tuples, lists, and strings), and procedures.Table 2.2gives their syntax.The nonterminal v denotes a partially constructed value.Later in the book we will see other basic types, including chunks, functors, cells,dictionaries, arrays, ports, classes, and objects.Some of these are explained inAppendix B.Dynamic typingThere are two basic approaches to typing, namely dynamic and static typing.Instatic typing, all variable types are known at compile time.In dynamic typing,the variable type is known only when the variable is bound.The declarativemodel is dynamically typed.The compiler tries to verify that all operations usevalues of the correct type.But because of dynamic typing, some type checks arenecessarily left for run time.The type hierarchyThe basic types of the declarative model can be classified into a hierarchy.Fig-ure 2.16 shows this hierarchy, where each node denotes a type.The hierarchyis ordered by set inclusion, i.e., all values of a node s type are also values of theparent node s type.For example, all tuples are records and all lists are tuples.This implies that all operations of a type are also legal for a subtype, e.g., alllist operations work also for strings.Later on in the book we will extend thishierarchy
[ Pobierz całość w formacie PDF ]