KRASCHE
&
BYRNE
         ELZED  HOME       NEWS       DOCS       DOWNLOADS       LICENSING       SUPPORT       FAQ       ABOUT  US

What's An Elzed?
Features
Licensing
Downloads
Documentation
Elzed News
    ELZED 
 Documentation 
 Core Concepts 

Contexts

Almost everything we do occurs in and derives meaning from its context. For example, if someone were to ask you to "pass the pineapple", whether you gave them a piece of tropical fruit or a hand grenade would depend, in part, on context.

Within Elzed, a context is a workspace in which operators and variables are defined, settings are applied, and in which expressions are evaluated. A given expression may evaluate differently, or not at all, in different contexts.

A context is either public or private. Public contexts are available to all process threads, while private contexts are available only to the thread in which they were created. The roster of public contexts and each thread's roster of private contexts are all maintained separately. It's possible (and quite acceptable) for each process thread to have a context named "My Context"; there can also be a public context with the same name. Call lzCreatePublicContext to create a public context. To create a private context for a given thread, call lzCreatePrivateContext from within that thread.

Each process thread has a "current" context. A context is made current in a given thread with a call to lzSetContext from within that thread. In the case in which a public context and one of the calling thread's private contexts have the same name, lzSetContext will make the private context current, effectively making the public context invisible to the thread in question.

Call lzClearContext to keep all contexts intact, but leave the calling process thread with no current context. Use this call to "clear the decks" before setting context attributes and creating a new context.

Call lzDestroyPublicContext to delete a public context you no longer need. To destroy a private context within a given thread, call lzDestroyPrivateContext from within that thread.

Contexts and the idea of scope are related, but are not the same. Operators and variables defined in a particular context are considered to be at global scope, available everywhere within that context. Operators and variables can also be at cosmic scope, available in all contexts. Note, however, that there is no explicit "cosmic context" in which these objects exist.

Is a context the same as a thread? Not exactly. If your application is multi-threaded, Elzed will remember which context each thread is using, and will ensure that the correct context is used in a given thread. While contexts may be shared across threads, thread-safe operation is assured by giving each thread its own context.

You may avoid dealing with contexts altogether by not declaring any of your own. All your expressions, variables, and operators will exist in the primary context, named "Elzed". This is perfectly fine if you don't need multiple contexts, particularly in single-threaded applications. The primary context is different from those you create, however, in that it cannot be destroyed.



  Copyright  ©  MMXXIV  by  R R Le Cropane   •   All Rights Reserved   •   Terms of Use   •   Privacy Policy