... general text, maybe partly from slides/paper .... TODO: Maybe we should not refer to ::nsf here and import instead the "needed" commands into ::nx namespace.
In general, the Next Scripting Language differs from XOTcl in the following respects:
The encapsulation of Next Scripting is weak; a programmer can still access e.g. other variables via some idioms, but this makes these accesses implicit and is more typing effort. Through the weak encapsulation a programmer should be encouraged to implement methods to provide access to instance variables.
Class create Stack { :method init {} { set :things "" } :method push {thing} { set :things [linsert ${:things} 0 $thing] return $thing } :method pop {} { set top [lindex ${:things} 0] set :things [lrange ${:things} 1 end] return $top } }
Class Stack Stack instproc init {} { my instvar things set things "" } Stack instproc push {thing} { my instvar things set things [linsert $things 0 $thing] return $thing } Stack instproc pop {} { my instvar things set top [lindex $things 0] set things [lrange $things 1 end] return $top }
In general, the Next Scripting Framework supports multiple object systems concurrently. Effectively, every object system has different base classes for creating objects and classes. Therefore, these object systems can have different different interfaces and names of built-in methods. Currently, the Next Scripting Framework supports primarily XOTcl 2.0 (highly compatible with XOTcl 1.*) and the Next Scripting Language (XOTcl provides about twice as many predefined built-in methods compared to the Next Scripting Language).
A single Tcl interpreter can host both, XOTcl and the Next Scripting Language at the same time. This makes migration from XOTcl to Next easier. The following example script shows to use in a single script XOTcl and Next:
namespace eval mypackage { package require XOTcl 2.0 # Import XOTcl into the current namespace namespace import -force ::xotcl::* # Define a class using XOTcl Class C1 C1 instproc foo {} {puts "hello world"} # Import Next into the current namespace namespace import -force ::nx::* # Define a class using Next Class create C2 { :method foo {} {puts "hello world"} } }
"Switching" between XOTcl and Next effectively means the load some
packages (if needed) and to import either the base classes
(Object
and Class
) of XOTcl or Next
into the current namespace.
XOTcl | Next Scripting Language |
---|---|
Class ClassName |
Class create ClassName |
Object ObjectName |
Object create ObjectName |
::xotcl::Class ClassName |
::nx::Class create ClassName |
::xotcl::Object ObjectName |
::nx::Object create ObjectName |
XOTcl | Next Scripting Language |
---|---|
Class C |
# Define method and class-object method # in the init-block of a class Class create C { # Define method and class-object method with separate calls Class create C |
Object o |
# Define class-object method and set instance variable # in the init-block of an object Object create o { # Define class-object method and set instance variable # with separate commands Object create o |
XOTcl | Next Scripting Language |
---|---|
# Methods for defining methods: # # proc # instproc # forward # instforward # parametercmd # instparametercmd # # All these methods return empty. |
# Methods for defining methods: # # method # forward # setter # alias # attribute # # All these methods return method-handles. |
Class C |
# Define scripted methodsClass create C { |
Class C |
# Define forwarderClass create C { |
Class C |
# Define setter and getter methodsClass create C { |
# Method "alias" not available |
# Define method aliases # (to scripted or non-scripted methods) Class create C { |
# Parameters only available at class levelClass C \
|
# Define object attributes # (parameters for initializing objects) Class create C { |
XOTcl | Next Scripting Language |
---|---|
# Method modifiers # # "object", # "public", and # "protected" # # are not available. |
# Method modifiers orthogonal over all kinds of methods # # Method-definition-methods: # method, forward, setter, alias, attribute Class create C { |
Note that the Next resolvers can be used in the XOTcl 2.* environment as well.
XOTcl | Next Scripting Language |
---|---|
Class C |
Class create C { |
In general, the Next Scripting Language favors the access to an objects's own instance variables over variable accesses of other objects. On the contrary, in XOTcl, the variable access to own and other variables are completely symmetric.
In Next Scripting, access to local variables are performed via
primarily via name resolvers, but using the standard tcl commands
(like e.g. set
, incr
, append
,
info exists
, etc.). In XOTcl, it is common to provide
same-named methods registered on ::xotcl::Object
for such
purposes. This is one of the reasons, why the Next Scripting Language
has a much smaller interface (less predefined methods). It is possible
for an application program to register XOTcl-like methods in the Next
Scripting Language via the primitives of the Next Scripting Framework.
XOTcl | Next Scripting Language |
---|---|
Class C |
Class create C { |
... instproc ... { |
# Set own instance variable to a value via
resolver # (prefered and fastest way)
... method ... {
|
... instproc ... { |
# Set own instance variable via variable import
... method ... {
|
... instproc ... { |
# Read own instance variable
... method ... {
... method ... {
|
... instproc ... { |
# Test existence of own instance variable
... method ... {
... method ... {
|
XOTcl | Next Scripting Language |
---|---|
obj set varname value |
# Set instance variable of object obj to a value via # resolver (prefered way: define setter method on obj) obj eval [list set :varname value] |
set newVar [obj set otherVar] |
# Read instance variable of object obj via resolverset newVar [obj eval {set :otherVar}] |
... instproc ... {
|
# Read instance variable of object obj via import
... method ... {
|
obj exists varname |
# Test existence of instance variable of
object objobj eval {info exists :varname}
::nx::var exists obj varname
|
XOTcl | Next Scripting Language |
---|---|
Class Foo -parameter {a {b 1}}
|
Class create Foo -parameter {a {b 1}}
|
Class Person -slots {
|
Class create Person {
|
# Predefined value constraints for parameter not available |
# Predefined value constraints: object, class,
alnum, alpha,
|
# Required parameter not available |
# Required parameter
|
# Multivalued parameter not available |
# Required parameter
|
XOTcl | Next Scripting Language |
---|---|
cls instmixin ... cls instmixinguard mixin condition
|
# Register per-class mixin and guard for a classcls mixin ... cls mixin guard mixin condition
|
cls mixin ... cls mixin guard mixin condition
|
# Register per-object mixin and guard for a classcls class-object mixin ... cls class-object mixin guard mixin condition |
obj mixin ... obj mixinguard mixin condition
|
# Register per-object mixin and guard for an objectobj mixin ... obj mixin guard mixin condition
|
XOTcl | Next Scripting Language |
---|---|
cls instfilter ... cls instfilterguard filter condition
|
# Register per-class filter and guard for a classcls filter ... cls filter guard filter condition
|
cls filter ... cls filterguard ...
|
# Register per-object filter and guard for a classcls class-object filter ... cls class-object filter guard filter condition |
obj filter ... obj filterguard filter condition
|
# Register per-object filter and guard for an
objectobj filter ... obj filter guard filter condition
|
XOTcl | Next Scripting Language |
---|---|
obj info commands ?pattern? |
obj info methods ?pattern? |
obj info parametercmd ?pattern? |
obj info methods -methodtype setter ?pattern? |
obj info procs ?pattern? |
obj info methods -methodtype scripted ?pattern? |
n.a. | obj info methods -methodtype alias ?pattern? |
n.a. | obj info methods -methodtype forwarder ?pattern? |
n.a. | obj info methods -methodtype object ?pattern? |
n.a. | obj info methods -callprotection public|protected ... |
cls info instcommands ?pattern? |
cls info methods ?pattern? |
cls info instparametercmd ?pattern? |
cls info methods -methodtype setter ?pattern? |
cls info instprocs ?pattern? |
cls info methods -methodtype scripted ?pattern? |
n.a. | cls info methods -methodtype alias ?pattern? |
n.a. | cls info methods -methodtype forwarder ?pattern? |
n.a. | cls info methods -methodtype object ?pattern? |
n.a. | cls info methods -callprotection public|protected ... |
cls info commands ?pattern? |
cls class-object info methods ?pattern? |
cls info parametercmd ?pattern? |
cls class-object info methods -methodtype setter ?pattern? |
cls info procs ?pattern? |
cls class-object info methods -methodtype scripted ?pattern? |
n.a. | cls class-object info methods -methodtype alias ?pattern? |
n.a. | cls class-object info methods -methodtype forwarder ?pattern? |
n.a. | cls class-object info methods -methodtype object ?pattern? |
n.a. | cls class-object info methods -callprotection public|protected ... |
XOTcl | Next Scripting Language |
---|---|
obj info methods ?pattern? |
obj info lookup methods ... ?pattern? |
n.a. | # List only application specific methods obj info lookup methods -application ... ?pattern? |
# Options for 'info methods' |
# Options for 'info lookup
methods' |
n.a. | # List slot objects defined for obj obj info lookup slots |
XOTcl | Next Scripting Language |
---|---|
obj procsearch methodName |
obj info lookup method methodName |
obj filtersearch methodName |
obj info lookup filter methodName |
XOTcl | Next Scripting Language |
---|---|
cls info instbody methodName |
cls info method body methodName |
cls info instargs methodName |
cls info method args methodName |
cls info instnonposargs methodName |
cls info method parameter methodName |
cls info instdefault methodName |
cls info method parameter methodName |
cls info instpre methodName |
cls info method precondition methodName |
cls info instpost methodName |
cls info method postcondition methodName |
n.a. | cls info method definition methodName |
XOTcl | Next Scripting Language |
---|---|
obj info body methodName |
obj info method body methodName |
obj info args methodName |
obj info method args methodName |
obj info nonposargs methodName |
obj info method parameter methodName |
obj info default methodName |
obj info method parameter methodName |
obj info pre methodName |
obj info method precondition methodName |
obj info post methodName |
obj info method postcondition methodName |
n.a. | obj info method definition methodName |
For definition of class object specific methods, use modifier
object
as shown in examples above.
XOTcl | Next Scripting Language |
---|---|
obj info filter ?-guards? ?-order? ?pattern? |
# ... info filter methods -order ... returns method-handles # instead of triples (applies to all three variants) obj info filter methods ?-guards? ?-order? ?pattern? |
obj info filterguard name |
obj info filter guard name
|
cls info filter ?-guards? ?-order? ?pattern? |
cls class-object info filter methods ?-guards? ?-order? ?pattern? |
cls info filterguard name |
cls class-object info filter guard name |
cls info instfilter ?-guards? ?-order? ?pattern? |
cls info filter methods ?-guards? ?-order? ?pattern? |
cls info instfilterguard name |
cls info filter guard name |
obj info mixin ?-guards? ?-order? ?pattern? |
obj info mixin classes ?-guards? ?-order? ?pattern? |
obj info mixinguard name |
obj info mixin guard name |
cls info mixin ?-guards? ?-order? ?pattern? |
cls class-object info mixin classes ?-guards? ?-order? ?pattern? |
cls info mixinguard name |
cls class-object info mixin guard name |
cls info instmixin ?-guards? ?-order? ?pattern? |
cls info mixin classes ?-guards? ?-order? ?pattern? |
cls info instmixinguard name |
cls info mixin guard name |
XOTcl | Next Scripting Language |
---|---|
n.a. | obj info method definition methodName |
n.a. | cls info method definition methodName |
XOTcl | Next Scripting Language |
---|---|
n.a. | obj info method handle methodName |
n.a. | cls ?object? info method handle methodName |
XOTcl | Next Scripting Language |
---|---|
n.a. | obj info method type methodName |
n.a. | cls ?object? info method type methodName |
XOTcl | Next Scripting Language |
---|---|
cls info mixinof ?-closure? ?pattern? |
# List objects, where cls is a per-object mixincls info mixinof -scope object ?-closure?
?pattern?
|
cls info instmixinof ?-closure? ?pattern? |
# List classes, where cls is a per-class mixincls info mixinof -scope class ?-closure?
?pattern?
|
n.a. |
# List objects and classes, where cls is # either a per-object or a per-class mixin cls info mixinof -scope all ?-closure?
?pattern?
cls info mixinof ?-closure? ?pattern?
|
XOTcl | Next Scripting Language |
---|---|
obj istype sometype |
obj info has type sometype
|
obj ismixin cls |
obj info has mixin cls
|
obj isclass ?cls? |
obj info is class
|
obj ismetaclass cls |
obj info is metaclass
|
n.a. |
obj info is baseclass
|
obj isobject obj2 |
::nsf::isobject obj
|
XOTcl | Next Scripting Language |
---|---|
self |
current current object
|
self class |
current class |
self proc |
current method |
self callingclass |
current currentclass |
self callingobject |
current callingobject |
self callingproc |
current callingmethod |
self calledclass |
current calledclass |
self calledproc |
current calledmethod |
self isnextcall |
current isnextcall |
self next |
# Returns method-handlecurrent next |
self filterreg |
# Returns method-handlecurrent filterreg |
self callinglevel |
current callinglevel |
self activelevel |
current activelevel |
XOTcl | Next Scripting Language |
---|---|
obj requireNamespace |
obj require namespace |
XOTcl | Next Scripting Language |
---|---|
obj check checkoptions |
::nsf::assertion obj check checkptions |
obj info check |
::nsf::assertion obj check |
obj invar conditions |
::nsf::assertion obj object-invar conditions |
obj info invar |
::nsf::assertion obj object-invar |
cls instinvar conditions |
::nsf::assertion cls class-invar conditions |
cls info instinvar |
::nsf::assertion cls class-invar |
cls invar conditions |
::nsf::assertion cls object-invar conditions |
cls info invar |
::nsf::assertion cls object-invar |
The resolvers (variable resolvers, function resolvers) of the Next Scripting Framework are used as well within XOTcl 2.0. When names starting with single colons are used in XOTcl 1.* scripts, conflicts will arise.
Since the next framework uses a different handling of objects
registered as methods (so called ensemble objects), sub-objects can't
be called in the same way as before. In XOTcl 1.*, it was possible to
call e.g. a method foo
of the slot object
Foo::slot::ints
via
Foo::slot::ints foo ...
or via
Foo slot ints foo ...
self
of foo
is now the calling object Foo
.
All slot objects (also those in XOTcl) are now always next-scripting objects of baseclass ::nx::Slot
Parameterclasses were rarely used and have been replaced by the more
general object parameterization. Therefore, cl info
parameterclass
has been removed.
The Next Scripting Framework performs stronger checking than XOTcl 1.*. For example, the requiredness of slots in XOTcl was just a comment, while Next enforces it.
The exit hander interface changed from a method of
::xotcl::Object
into three Tcl procs in the ::nsf
namespace. Next provides now:
::nsf::setExitHandler script ::nsf::getExitHandler ::nsf::unsetExitHandler