Context

Context is an internal state in Pnuts runtime environment, which is represented by pnuts.lang.Context class. A context has the following information:

See "Pnuts API Overview" for the overview of the class.

getContext()

getContext() refers to the currently executing context, which is created when an interactive session starts. All other executions refer to the current context.

eval ( String expression {, Context context } )
load ( String scriptFile {, Context context } )
loadFile ( String scriptFile {, Context context } )

When context is specified to the parameter of these functions, a clone of the context is created and the script is executed with the clone.

When context is not specified, a clone of the current context is created and the script is executed with the clone. In this case, the import() state and the current package are reset to the default values.

OutputStream for Messages

For each context the following can be specified.

context . setOutputStream (OutputStream anOutputStream)
context . getOutputStream()
context . setWriter (Writer aWriter )
context . getWriter()
context . setErrorWriter (Writer writer)
context . getErrorWriter()
context . setTerminalWriter (Writer writer)
context . getTerminalWriter()

Context-local Variables

context . symbol

Context-local variables are environment variables assiciated with a context. Context-local variables are used typically when some kind of state should be kept between function calls.

e.g.
function foo(){
  getContext().foo = true
}

function bar(){
  if (getContext().foo != null){
    println("foo has been called")
  }
}
For other attributes of Context, See Pnuts API Overview.