Table of Contents

Name

vector - Vector data type for Tcl

Synopsis

vector create vecName ?vecName ...? ?switches ?

vector destroy vecName ?vecName ...?

vector expr expression

vector names ?pattern ...?

Description

The vector command creates a vector of floating point values. The vector's components can be manipulated in three ways: through a Tcl array variable, a Tcl command, or the C API.

Introduction

A vector is simply an ordered set of numbers. The components of a vector are real numbers, indexed by counting numbers.

Vectors are common data structures for many applications. For example, a graph may use two vectors to represent the X-Y coordinates of the data plotted. The graph will automatically be redrawn when the vectors are updated or changed. By using vectors, you can separate data analysis from the graph widget. This makes it easier, for example, to add data transformations, such as splines. It's possible to plot the same data to in multiple graphs, where each graph presents a different view or scale of the data.

You could try to use Tcl's associative arrays as vectors. Tcl arrays are easy to use. You can access individual elements randomly by specifying the index, or the set the entire array by providing a list of index and value pairs for each element. The disadvantages of associative arrays as vectors lie in the fact they are implemented as hash tables.

The vector command tries to overcome these disadvantages while still retaining the ease of use of Tcl arrays. The vector command creates both a new Tcl command and associate array which are linked to the vector components. You can randomly access vector components though the elements of array. Not have all indices are generated for the array, so printing the array (using the parray procedure) does not print out all the component values. You can use the Tcl command to access the array as a whole. You can copy, append, or sort vector using its command. If you need greater performance, or customized behavior, you can write your own C code to manage vectors.

Example

You create vectors using the vector command and its create operation.

# Create a new vector.
vector create y(50)

This creates a new vector named y . It has fifty components, by default, initialized to 0.0 . In addition, both a Tcl command and array variable, both named y , are created. You can use either the command or variable to query or modify components of the vector.

# Set the first value.
set y(0) 9.25
puts "y has [y length] components"

The array y can be used to read or set individual components of the vector. Vector components are indexed from zero. The array index must be a number less than the number of components. For example, it's an error if you try to set the 51st element of y .

# This is an error. The vector only has 50 components.
set y(50) 0.02

You can also specify a range of indices using a colon (:) to separate the first and last indices of the range.

# Set the first six components of y
set y(0:5) 25.2

If you don't include an index, then it will default to the first and/or last component of the vector.

# Print out all the components of y
puts "y = $y(:)"

There are special non-numeric indices. The index end , specifies the last component of the vector. It's an error to use this index if the vector is empty (length is zero). The index ++end can be used to extend the vector by one component and initialize it to a specific value. You can't read from the array using this index, though.

# Extend the vector by one component.
set y(++end) 0.02

The other special indices are min and max . They return the current smallest and largest components of the vector.

# Print the bounds of the vector
puts "min=$y(min) max=$y(max)"

To delete components from a vector, simply unset the corresponding array element. In the following example, the first component of y is deleted. All the remaining components of y will be moved down by one index as the length of the vector is reduced by one.

# Delete the first component
unset y(0)
puts "new first element is $y(0)"

The vector's Tcl command can also be used to query or set the vector.

# Create and set the components of a new vector
vector create x
x set { 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 }

Here we've created a vector x without a initial length specification. In this case, the length is zero. The set operation resets the vector, extending it and setting values for each new component.

There are several operations for vectors. The range operation lists the components of a vector between two indices.

# List the components
puts "x = [x range 0 end]"

You can search for a particular value using the search operation. It returns a list of indices of the components with the same value. If no component has the same value, it returns "" .

# Find the index of the biggest component
set indices [x search $x(max)]

Other operations copy, append, or sort vectors. You can append vectors or new values onto an existing vector with the append operation.

# Append assorted vectors and values to x
x append x2 x3 { 2.3 4.5 } x4

The sort operation sorts the vector. If any additional vectors are specified, they are rearranged in the same order as the vector. For example, you could use it to sort data points represented by x and y vectors.

# Sort the data points
x sort y

The vector x is sorted while the components of y are rearranged so that the original x,y coordinate pairs are retained.

The expr operation lets you perform arithmetic on vectors. The result is stored in the vector.

# Add the two vectors and a scalar
x expr { x + y }
x expr { x * 2 }

When a vector is modified, resized, or deleted, it may trigger call-backs to notify the clients of the vector. For example, when a vector used in the graph widget is updated, the vector automatically notifies the widget that it has changed. The graph can then redrawn itself at the next idle point. By default, the notification occurs when Tk is next idle. This way you can modify the vector many times without incurring the penalty of the graph redrawing itself for each change. You can change this behavior using the notify operation.

# Make vector x notify after every change
x notify always
   ...
# Never notify
x notify never
   ...
# Force notification now
x notify now

To delete a vector, use the vector delete command. Both the vector and its corresponding Tcl command are destroyed.

# Remove vector x
vector destroy x

Syntax

Vectors are created using the vector create operation. Th create operation can be invoked in one of three forms:
vector create vecName
This creates a new vector vecName which initially has no components.
vector create vecName (size )
This second form creates a new vector which will contain size number of components. The components will be indexed starting from zero (0). The default value for the components is 0.0 .
vector create vecName (first :last )
The last form creates a new vector of indexed first through last . First and last can be any integer value so long as first is less than last .

Vector names must start with a letter and consist of letters, digits, or underscores.

# Error: must start with letter
vector create 1abc

You can automatically generate vector names using the "#auto " vector name. The create operation will generate a unique vector name.

set vec [vector create #auto]
puts "$vec has [$vec length] components"

Vector Indices

Vectors are indexed by integers. You can access the indbe a numame tab tearoff index ?newName ?
Reparents the widget embedded into index , placing it inside of newName . NewName is either the name of an new widget that will contain the embedded widget or the name of the tabset widget. It the last case, the embedded widget is put back into the folder.

If no newName argument is provided, then the name of the current parent of the embedded widget is returned.

Default Bindings

BLT automatically generates class bindings that supply tabsets their default behaviors. The following event sequences are set by default for tabsets (via the class bind tag Tabset ):

<ButtonPress-2>
<B2-Motion>
<ButtonRelease-2>
Mouse button 2 may be used for scanning. If it is pressed and dragged over the tabset, the contents of the tabset drag at high speed in the direction the mouse moves.
<KeyPress-Up>
<KeyPress-Down>
The up and down arrow keys move the focus to the tab immediately above or below the current focus tab. The tab with focus is drawn with the a dashed outline around the tab label.
<KeyPress-Left>
<KeyPress-Right>
The left and right arrow keys move the focus to the tab immediately to the left or right of the current focus tab. The tab with focus is drawn with the a dashed outline around the tab label.
<KeyPress-space>
<KeyPress-Return>
The space and return keys select the current tab given focus. When a folder is selected, it's command is invoked and the embedded widget is mapped.

Each tab, by default, also has a set of bindings (via the tag all ). These bindings may be reset using the tabset's bind operation.

<Enter>
<Leave>
When the mouse pointer enters a tab, it is activated (i.e. drawn in its active colors) and when the pointer leaves, it is redrawn in its normal colors.
<ButtonRelease-1>
Clicking with the left mouse button on a tab causes the tab to be selected and its Tcl script (see the -command or -selectcommand options) to be invoked. The folder and any embedded widget (if one is specified) is automatically mapped.
<ButtonRelease-3>
<Control-ButtonRelease-1>
Clicking on the right mouse button (or the left mouse button with the Control key held down) tears off the current page into its own toplevel widget. The embedded widget is re-packed into a new toplevel and an outline of the widget is drawn in the folder. Clicking again (toggling) will reverse this operation and replace the page back in the folder.

Bind Tags

You can bind commands to tabs that are triggered when a particular event sequence occurs in them, much like canvas items in Tk's canvas widget. Not all event sequences are valid. The only binding events that may be specified are those related to the mouse and keyboard (such as Enter , Leave , ButtonPress , Motion , and KeyPress ).

It is possible for multiple bindings to match a particular event. This could occur, for example, if one binding is associated with the tab name and another is associated with the tab's tags (see the -bindtags option). When this occurs, all the matching bindings are invoked. A binding associated with the tab name is invoked first, followed by one binding for each of the tab's bindtags. If there are multiple matching bindings for a single tag, then only the most specific binding is invoked. A continue command in a binding script terminates that script, and a break command terminates that script and skips any remaining scripts for the event, just as for the bind command.

The -bindtags option for tabs controls addition tag names that can be matched. Implicitly the first tag for each tab is its name. Setting the value of the -bindtags option doesn't change this.

Keywords

tabset, widget


Table of Contents

./usr/share/doc/blt8.0-dev/html/vector.html0100644000000000000000000012745607432570471017341 0ustar rootroot 28043(sed) manual page Table of Contents

Name

vector - Vector data type for Tcl

Synopsis

vector create vecName ?vecName ...? ?switches ?

vector destroy vecName ?vecName ...?

vector expr expression

vector names ?pattern ...?

Description

The vector command creates a vector of floating point values. The vector's components can be manipulated in three ways: through a Tcl array variable, a Tcl command, or the C API.

Introduction

A vector is simply an ordered set of numbers. The components of a vector are real numbers, indexed by counting numbers.

Vectors are common data structures for many applications. For example, a graph may use two vectors to represent the X-Y coordinates of the data plotted. The graph will automatically be redrawn when the vectors are updated or changed. By using vectors, you can separate data analysis from the graph widget. This makes it easier, for example, to add data transformations, such as splines. It's possible to plot the same data to in multiple graphs, where each graph presents a different view or scale of the data.

You could try to use Tcl's associative arrays as vectors. Tcl arrays are easy to use. You can access individual elements randomly by specifying the index, or the set the entire array by providing a list of index and value pairs for each element. The disadvantages of associative arrays as vectors lie in the fact they are implemented as hash tables.

The vector command tries to overcome these disadvantages while still retaining the ease of use of Tcl arrays. The vector command creates both a new Tcl command and associate array which are linked to the vector components. You can randomly access vector components though the elements of array. Not have all indices are generated for the array, so printing the array (using the parray procedure) does not print out all the component values. You can use the Tcl command to access the array as a whole. You can copy, append, or sort vector using its command. If you need greater performance, or customized behavior, you can write your own C code to manage vectors.

Example

You create vectors using the vector command and its create operation.

# Create a new vector.
vector create y(50)

This creates a new vector named y . It has fifty components, by default, initialized to 0.0 . In addition, both a Tcl command and array variable, both named y , are created. You can use either the command or variable to query or modify components of the vector.

# Set the first value.
set y(0) 9.25
puts "y has [y length] components"

The array y can be used to read or set individual components of the vector. Vector components are indexed from zero. The array index must be a number less than the number of components. For example, it's an error if you try to set the 51st element of y .

# This is an error. The vector only has 50 components.
set y(50) 0.02

You can also specify a range of indices using a colon (:) to separate the first and last indices of the range.

# Set the first six components of y
set y(0:5) 25.2

If you don't include an index, then it will default to the first and/or last component of the vector.

# Print out all the components of y
puts "y = $y(:)"

There are special non-numeric indices. The index end , specifies the last component of the vector. It's an error to use this index if the vector is empty (length is zero). The index ++end can be used to extend the vector by one component and initialize it to a specific value. You can't read from the array using this index, though.

# Extend the vector by one component.
set y(++end) 0.02

The other special indices are min and max . They return the current smallest and largest components of the vector.

# Print the bounds of the vector
puts "min=$y(min) max=$y(max)"

To delete components from a vector, simply unset the corresponding array element. In the following example, the first component of y is deleted. All the remaining components of y will be moved down by one index as the length of the vector is reduced by one.

# Delete the first component
unset y(0)
puts "new first element is $y(0)"

The vector's Tcl command can also be used to query or set the vector.

# Create and set the components of a new vector
vector create x
x set { 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 }

Here we've created a vector x without a initial length specification. In this case, the length is zero. The set operation resets the vector, extending it and setting values for each new component.

There are several operations for vectors. The range operation lists the components of a vector between two indices.

# List the components
puts "x = [x range 0 end]"

You can search for a particular value using the search operation. It returns a list of indices of the components with the same value. If no component has the same value, it returns "" .

# Find the index of the biggest component
set indices [x search $x(max)]

Other operations copy, append, or sort vectors. You can append vectors or new values onto an existing vector with the append operation.

# Append assorted vectors and values to x
x append x2 x3 { 2.3 4.5 } x4

The sort operation sorts the vector. If any additional vectors are specified, they are rearranged in the same order as the vector. For example, you could use it to sort data points represented by x and y vectors.

# Sort the data points
x sort y

The vector x is sorted while the components of y are rearranged so that the original x,y coordinate pairs are retained.

The expr operation lets you perform arithmetic on vectors. The result is stored in the vector.

# Add the two vectors and a scalar
x expr { x + y }
x expr { x * 2 }

When a vector is modified, resized, or deleted, it may trigger call-backs to notify the clients of the vector. For example, when a vector used in the graph widget is updated, the vector automatically notifies the widget that it has changed. The graph can then redrawn itself at the next idle point. By default, the notification occurs when Tk is next idle. This way you can modify the vector many times without incurring the penalty of the graph redrawing itself for each change. You can change this behavior using the notify operation.

# Make vector x notify after every change
x notify always
   ...
# Never notify
x notify never
   ...
# Force notification now
x notify now

To delete a vector, use the vector delete command. Both the vector and its corresponding Tcl command are destroyed.

# Remove vector x
vector destroy x

Syntax

Vectors are created using the vector create operation. Th create operation can be invoked in one of three forms:
vector create vecName
This creates a new vector vecName which initially has no components.
vector create vecName (size )
This second form creates a new vector which will contain size number of components. The components will be indexed starting from zero (0). The default value for the components is 0.0 .
vector create vecName (first :last )
The last form creates a new vector of indexed first through last . First and last can be any integer value so long as first is less than last .

Vector names must start with a letter and consist of letters, digits, or underscores.

# Error: must start with letter
vector create 1abc

You can automatically generate vector names using the "#auto " vector name. The create operation will generate a unique vector name.

set vec [vector create #auto]
puts "$vec has [$vec length] components"

Vector Indices

Vectors are indexed by integers. You can access the indbe a numame tab tearoff index ?newName ?
Reparents the widget embedded into index , placing it inside of newName . NewName is either the name of an new widget that will contain the embedded widget or the name of the tabset widget. It the last case, the embedded widget is put back into the folder.

If no newName argument is provided, then the name of the current parent of the embedded widget is returned.

Default Bindings

BLT automatically generates class bindings that supply tabsets their default behaviors. The following event sequences are set by default for tabsets (via the class bind tag Tabset ):

<ButtonPress-2>
<B2-Motion>
<ButtonRelease-2>
Mouse button 2 may be used for scanning. If it is pressed and dragged over the tabset, the contents of the tabset drag at high speed in the direction the mouse moves.
<KeyPress-Up>
<KeyPress-Down>
The up and down arrow keys move the focus to the tab immediately above or below the current focus tab. The tab with focus is drawn with the a dashed outline around the tab label.
<KeyPress-Left>
<KeyPress-Right>
The left and right arrow keys move the focus to the tab immediately to the left or right of the current focus tab. The tab with focus is drawn with the a dashed outline around the tab label.
<KeyPress-space>
<KeyPress-Return>
The space and return keys select the current tab given focus. When a folder is selected, it's command is invoked and the embedded widget is mapped.

Each tab, by default, also has a set of bindings (via the tag all ). These bindings may be reset using the tabset's bind operation.

<Enter>
<Leave>
When the mouse pointer enters a tab, it is activated (i.e. drawn in its active colors) and when the pointer leaves, it is redrawn in its normal colors.
<ButtonRelease-1>
Clicking with the left mouse button on a tab causes the tab to be selected and its Tcl script (see the -command or -selectcommand options) to be invoked. The folder and any embedded widget (if one is specified) is automatically mapped.
<ButtonRelease-3>
<Control-ButtonRelease-1>
Clicking on the right mouse button (or the left mouse button with the Control key held down) tears off the current page into its own toplevel widget. The embedded widget is re-packed into a new toplevel and an outline of the widget is drawn in the folder. Clicking again (toggling) will reverse this operation and replace the page back in the folder.

Bind Tags

You can bind commands to tabs that are triggered when a particular event sequence occurs in them, much like canvas items in Tk's canvas widget. Not all event sequences are valid. The only binding events that may be specified are those related to the mouse and keyboard (such as Enter , Leave , ButtonPress , Motion , and KeyPress ).

It is possible for multiple bindings to match a particular event. This could occur, for example, if one binding is associated with the tab name and another is associated with the tab's tags (see the -bindtags option). When this occurs, all the matching bindings are invoked. A binding associated with the tab name is invoked first, followed by one binding for each of the tab's bindtags. If there are multiple matching bindings for a single tag, then only the most specific binding is invoked. A continue command in a binding script terminates that script, and a break command terminates that script and skips any remaining scripts for the event, just as for the bind command.

The -bindtags option for tabs controls addition tag names that can be matched. Implicitly the first tag for each tab is its name. Setting the value of the -bindtags option doesn't change this.

Keywords

tabset, widget


Table of Contents

./usr/share/doc/blt8.0-dev/html/vector.html0100644000000000000000000012745607432570471017341 0ustar rootroot 28043(sed) manual page Table of Contents

Name

vector - Vector data type for Tcl

Synopsis

vector create vecName ?vecName ...? ?switches ?

vector destroy vecName ?vecName ...?

vector expr expression

vector names ?pattern ...?

Description

The vector command creates a vector of floating point values. The vector's components can be manipulated in three ways: through a Tcl array variable, a Tcl command, or the C API.

Introduction

A vector is simply an ordered set of numbers. The components of a vector are real numbers, indexed by counting numbers.

Vectors are common data structures for many applications. For example, a graph may use two vectors to represent the X-Y coordinates of the data plotted. The graph will automatically be redrawn when the vectors are updated or changed. By using vectors, you can separate data analysis from the graph widget. This makes it easier, for example, to add data transformations, such as splines. It's possible to plot the same data to in multiple graphs, where each graph presents a different view or scale of the data.

You could try to use Tcl's associative arrays as vectors. Tcl arrays are easy to use. You can access individual elements randomly by specifying the index, or the set the entire array by providing a list of index and value pairs for each element. The disadvantages of associative arrays as vectors lie in the fact they are implemented as hash tables.

The vector command tries to overcome these disadvantages while still retaining the ease of use of Tcl arrays. The vector command creates both a new Tcl command and associate array which are linked to the vector components. You can randomly access vector components though the elements of array. Not have all indices are generated for the array, so printing the array (using the parray procedure) does not print out all the component values. You can use the Tcl command to access the array as a whole. You can copy, append, or sort vector using its command. If you need greater performance, or customized behavior, you can write your own C code to manage vectors.

Example

You create vectors using the vector command and its create operation.

# Create a new vector.
vector create y(50)

This creates a new vector named y . It has fifty components, by default, initialized to 0.0 . In addition, both a Tcl command and array variable, both named y , are created. You can use either the command or variable to query or modify components of the vector.

# Set the first value.
set y(0) 9.25
puts "y has [y length] components"

The array y can be used to read or set individual components of the vector. Vector components are indexed from zero. The array index must be a number less than the number of components. For example, it's an error if you try to set the 51st element of y .

# This is an error. The vector only has 50 components.
set y(50) 0.02

You can also specify a range of indices using a colon (:) to separate the first and last indices of the range.

# Set the first six components of y
set y(0:5) 25.2

If you don't include an index, then it will default to the first and/or last component of the vector.

# Print out all the components of y
puts "y = $y(:)"

There are special non-numeric indices. The index end , specifies the last component of the vector. It's an error to use this index if the vector is empty (length is zero). The index ++end can be used to extend the vector by one component and initialize it to a specific value. You can't read from the array using this index, though.

# Extend the vector by one component.
set y(++end) 0.02

The other special indices are min and max . They return the current smallest and largest components of the vector.

# Print the bounds of the vector
puts "min=$y(min) max=$y(max)"

To delete components from a vector, simply unset the corresponding array element. In the following example, the first component of y is deleted. All the remaining components of y will be moved down by one index as the length of the vector is reduced by one.

# Delete the first component
unset y(0)
puts "new first element is $y(0)"

The vector's Tcl command can also be used to query or set the vector.

# Create and set the components of a new vector
vector create x
x set { 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 }

Here we've created a vector x without a initial length specification. In this case, the length is zero. The set operation resets the vector, extending it and setting values for each new component.

There are several operations for vectors. The range operation lists the components of a vector between two indices.

# List the components
puts "x = [x range 0 end]"

You can search for a particular value using the search operation. It returns a list of indices of the components with the same value. If no component has the same value, it returns "" .

# Find the index of the biggest component
set indices [x search $x(max)]

Other operations copy, append, or sort vectors. You can append vectors or new values onto an existing vector with the append operation.

# Append assorted vectors and values to x
x append x2 x3 { 2.3 4.5 } x4

The sort operation sorts the vector. If any additional vectors are specified, they are rearranged in the same order as the vector. For example, you could use it to sort data points represented by x and y vectors.

# Sort the data points
x sort y

The vector x is sorted while the components of y are rearranged so that the original x,y coordinate pairs are retained.

The expr operation lets you perform arithmetic on vectors. The result is stored in the vector.

# Add the two vectors and a scalar
x expr { x + y }
x expr { x * 2 }

When a vector is modified, resized, or deleted, it may trigger call-backs to notify the clients of the vector. For example, when a vector used in the graph widget is updated, the vector automatically notifies the widget that it has changed. The graph can then redrawn itself at the next idle point. By default, the notification occurs when Tk is next idle. This way you can modify the vector many times without incurring the penalty of the graph redrawing itself for each change. You can change this behavior using the notify operation.

# Make vector x notify after every change
x notify always
   ...
# Never notify
x notify never
   ...
# Force notification now
x notify now

To delete a vector, use the vector delete command. Both the vector and its corresponding Tcl command are destroyed.

# Remove vector x
vector destroy x

Syntax

Vectors are created using the vector create operation. Th create operation can be invoked in one of three forms:
vector create vecName
This creates a new vector vecName which initially has no components.
vector create vecName (size )
This second form creates a new vector which will contain size number of components. The components will be indexed starting from zero (0). The default value for the components is 0.0 .
vector create vecName (first :last )
The last form creates a new vector of indexed first through last . First and last can be any integer value so long as first is less than last .

Vector names must start with a letter and consist of letters, digits, or underscores.

# Error: must start with letter
vector create 1abc

You can automatically generate vector names using the "#auto " vector name. The create operation will generate a unique vector name.

set vec [vector create #auto]
puts "$vec has [$vec length] components"

Vector Indices

Vectors are indexed by integers. You can access the indbe a numame tab tearoff index ?newName ?
Reparents the widget embedded into index , placing it inside of newName . NewName is either the name of an new widget that will contain the embedded widget or the name of the tabset widget. It the last case, the embedded widget is put back into the folder.

If no newName argument is provided, then the name of the current parent of the embedded widget is returned.

Default Bindings

BLT automatically generates class bindings that supply tabsets their default behaviors. The following event sequences are set by default for tabsets (via the class bind tag Tabset ):

<ButtonPress-2>
<B2-Motion>
<ButtonRelease-2>
Mouse button 2 may be used for scanning. If it is pressed and dragged over the tabset, the contents of the tabset drag at high speed in the direction the mouse moves.
<KeyPress-Up>
<KeyPress-Down>
The up and down arrow keys move the focus to the tab immediately above or below the current focus tab. The tab with focus is drawn with the a dashed outline around the tab label.
<KeyPress-Left>
<KeyPress-Right>
The left and right arrow