23.11.2014 Views

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

· ; · ; · :: Store × Frame Stack × Expression −→ Store × Frame Stack × Expression<br />

µ ; Φ ; E[((λ (x 1 . . . x n) e) v 1 . . . v n)] −→ µ ; Φ ; E[e[x 1/v 1, . . . , x n/v n]]<br />

µ ; Φ ; E[(call/cc e)] −→ µ ; Φ ; E[(e (λ (x) (abort Φ E[x])))]<br />

µ ; Φ ; E[(abort Φ ′ e)] −→ µ ; Φ ′ ; e<br />

µ ; Φ ; E[(push-frame!)] −→ µ ; (∅, Φ) ; E[(λ (x) x)]<br />

µ ; (φ, Φ) ; E[(make-cell v)] −→ µ[l ↦→ v] ; (φ[n ↦→ l], Φ) ; E[(cell n)]<br />

where n <strong>and</strong> l are fresh<br />

µ ; Φ ; E[(cell-ref (cell n))] −→ µ ; Φ ; E[l(µ, Φ, n)]<br />

µ ; (φ, Φ) ; E[(cell-shadow (cell n) v)] −→ µ[l ↦→ v] ; (φ[n ↦→ l], Φ) ; E[(cell n)]<br />

where l is fresh<br />

Figure 11. The reduction steps <strong>of</strong> λ F S<br />

v ::= (λ (x . . . ) e)<br />

(abstractions)<br />

| c<br />

c ::= (cell n)<br />

(cells)<br />

where n is an integer<br />

e ::= v (values)<br />

| x (identifiers)<br />

| (e e . . . ) (applications)<br />

| (call/cc e) (continuation captures)<br />

| (abort Φ e) (program abortion)<br />

where Φ is a frame stack (Fig. 9)<br />

| (push-frame!) (frame creation)<br />

| (make-cell e) (cell creation)<br />

| (cell-ref e e) (cell reference)<br />

| (cell-shadow e e) (cell shadowing)<br />

Stores<br />

µ :: Store<br />

µ ::= ∅ (empty store)<br />

| µ[l ↦→ v] (location binding)<br />

Frames<br />

φ :: Frame<br />

φ ::= ∅ (empty frame)<br />

| φ[x ↦→ l] (cell identifier binding)<br />

Frame Stack<br />

Φ :: Frame Stack<br />

Φ ::= ∅ (empty frame stack)<br />

| φ, Φ (frame entry)<br />

Figure 9. The semantic domains <strong>of</strong> λ F S<br />

Figure 8. Syntax <strong>of</strong> λ F S<br />

is created, it is placed in the store with its parent as the old frame<br />

stack top.<br />

The semantics is relatively simple. The cell <strong>and</strong> frame operations<br />

are quite transparent. We have included call/cc/frame (in<br />

Fig. 10) as an abbreviation, rather than a reduction step, to keep the<br />

semantics uncluttered. If we were to encode it as a reduction step,<br />

that step would be:<br />

µ ; Φ ; E[(call/cc/frame e)] −→<br />

µ ; Φ ; E[e (λ (x) (abort Φ E[(seqn (push-frame!) x)]))]<br />

The order <strong>of</strong> frame creation in call/cc/frame is important. The<br />

implementation must ensure that each invocation <strong>of</strong> a continuation<br />

has a unique frame, <strong>and</strong> therefore a Refresh does not share the same<br />

frame as the initial request. The following faulty reduction step fails<br />

to ensure that each invocation has a unique frame:<br />

µ ; Φ ; E[(call/cc/frame e)] −→<br />

µ ; Φ ; E[e (λ (x) (abort (, Φ) E[x]))]<br />

where is a frame constructed at capture time.<br />

In this erroneous reduction, the new frame is created when the<br />

continuation is created, rather than each time it is invoked. Observe<br />

that the correct reduction preserves the invariant that each frame has<br />

a unique incoming edge in the interaction tree, which this reduction<br />

violates.<br />

6. Applications<br />

Web cells answer a pressing need <strong>of</strong> stateful Web components: they<br />

enable (a) defining stateful objects that (b) behave safely in the face<br />

<strong>of</strong> Web interactions while (c) not dem<strong>and</strong>ing a strong invariant <strong>of</strong><br />

global program structure. Other techniques fail one or more <strong>of</strong> these<br />

criteria: most traditional scoping mechanisms fail (b) (as we have<br />

discussed in Sec. 4), while store-passing clearly violates (c).<br />

Before we created Web cells, numerous PLT <strong>Scheme</strong> Web server<br />

applications—including ones written by the present authors—used<br />

to employ fluid-let; based on the analysis described in this paper,<br />

we have been able to demonstrate genuine errors in these applications.<br />

As a result, PLT <strong>Scheme</strong> Web server users have adopted Web<br />

cells in numerous applications, e.g., a server for managing faculty<br />

job applications, a homework turn-in application, a BibTeX frontend,<br />

a personal weblog manager, <strong>and</strong>, <strong>of</strong> course, CONTINUE itself.<br />

We present three more uses <strong>of</strong> Web cells below.<br />

142 <strong>Scheme</strong> <strong>and</strong> <strong>Functional</strong> <strong>Programming</strong>, <strong>2006</strong>

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

Saved successfully!

Ooh no, something went wrong!