Racket – units – 1

l3Nuovo capitolo, qui: [doc]/guide/units.html.

Units organize a program into separately compilable and reusable components. A unit resembles a procedure in that both are first-class values that are used for abstraction. While procedures abstract over values in expressions, units abstract over names in collections of definitions. Just as a procedure is called to evaluate its expressions given actual arguments for its formal parameters, a unit is invoked to evaluate its definitions given actual references for its imported variables. Unlike a procedure, however, a unit’s imported variables can be partially linked with the exported variables of another unit prior to invocation. Linking merges multiple units together into a single compound unit. The compound unit itself imports variables that will be propagated to unresolved imported variables in the linked units, and re-exports some variables from the linked units for further linking.

Uh, tutto da vedere, provare. Inizio, qui: [doc]/guide/Signatures_and_Units.html.

Signatures e units

The interface of a unit is described in terms of signatures. Each signature is defined (normally within a module) using define-signature. For example, the following signature, placed in a “toy-factory-sig.rkt” file, describes the exports of a component that implements a toy factory:

By convention, signature names end with ^.

u00

Nota per me che sono un pasticcione: usare DrRacket e salvare nella directory corrente altrimenti non trova la path.

An implementation of the toy-factory^ signature is written using define-unit with an export clause that names toy-factory^:

By convention, unit names end with @.

u0

The toy-factory^ signature also could be referenced by a unit that needs a toy factory to implement something else. In that case, toy-factory^ would be named in an import clause. For example, a toy store would get toys from a toy factory. (Suppose, for the sake of an example with interesting features, that the store is willing to sell only toys in a particular color.)

u1

e

u2

Note that “toy-store-unit.rkt” imports “toy-factory-sig.rkt“, but not “simple-factory-unit.rkt“. Consequently, the toy-store@ unit relies only on the specification of a toy factory, not on a specific implementation.

OK, per adesso va bene, ma … continua… :mrgreen:

Posta un commento o usa questo indirizzo per il trackback.

Trackback

  • Racket – units – 2 | Ok, panico su 15 settembre 2015 alle 09:55

    […] Continuo, oggi qui: [doc]/guide/units.html, in particolare qui: [doc]/guide/Invoking_Units.html. […]

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: