25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>VDM</strong>-<strong>10</strong> <strong>Language</strong> <strong>Manual</strong><br />

In this example the threadid expression is used in two places:<br />

• In the Wait operation for threads to register interest in this object.<br />

• In the permission predicate for Awake. An interested thread should call Awake following<br />

registration using Wait. It will then be blocked until its threadid is removed<br />

from the waitset following another thread’s call to notify.<br />

Note also that one needs to be careful about the use of the wait-notify mechanism when<br />

having periodic threads (because they change their threadid for each new period).<br />

6.16 The Lambda Expression<br />

Syntax: expression = . . .<br />

| lambda expression<br />

| . . . ;<br />

lambda expression = ‘lambda’, type bind list, ‘&’, expression ;<br />

type bind list = type bind, { ‘,’, type bind } ;<br />

type bind = pattern, ‘:’, type ;<br />

Semantics: A lambda expression is of the form:<br />

✞<br />

lambda pat1 : T1, ..., patn : Tn & e<br />

✡✝<br />

✆<br />

where the pati are patterns, the Ti are type expressions, and e is the body expression.<br />

The scope of the pattern identifiers in the patterns pati is the body expression. A lambda<br />

expression cannot be polymorphic, but apart from that, it corresponds semantically to an<br />

explicit function definition as explained in section 5. A function defined by a lambda expression<br />

can be Curried by using a new lambda expression in the body of it in a nested way.<br />

When lambda expressions are bound to an identifier they can also define a recursive function.<br />

Examples: An increment function can be defined by means of a lambda expression like:<br />

✞<br />

Inc = lambda n : nat & n + 1<br />

✡✝<br />

and an addition function can be Curried by:<br />

✞<br />

Add = lambda a : nat & lambda b : nat & a + b<br />

✡✝<br />

✆<br />

✆<br />

62

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

Saved successfully!

Ooh no, something went wrong!