Guide
Console
Tour
Words
Stack
Word-types
Data-types
Structures
Scopes
GUI-Toolkit-Tk
Tcl-Literature
Engine
Objecttypes
Compiler
Applications
Postfix

TclForth Datatypes

Each data type has a private set of commands. (see [objecttypes](./Objecttypes)). If used without a command the data element delivers its value.

#### constant
Definition: *number* constant *name*

``` 88 constant cc
ok
cc .
88 ok
````

#### variable

Definition: *number* variable *name*

Commands: set add incr decr @ !

``` 33 variable V
ok
V .
33 ok
44 V set V .
44 ok
V incr V .
45 ok
7 V add V .
52 ok
\ and also
77 V ! V @ .
77 ok

```

#### array

Tcl provides associative arrays as collections of elements. Each element is a variable with a name and value. The element names may be arbitrary strings that are stored in a hash table. The values are any data type.

Definition: {*name/value pairs*} array *name*

Commands: set incr add print names

``` {1 11 2 22} array A
ok
1 A 2 A + .
33 ok
7 "seven" A set
ok
"seven" A 1 A * .
77 ok
A names
({seven 1 2}) ok
```

#### string

Definition: *text* string *name*

Commands: set index length tolower append print hexdump first range

``` "Hello Forth" string S
ok
S print
Hello Forth
ok
S .
Hello Forth ok
", how are you?" S append S .
Hello Forth, how are you? ok
"," S first
(11) ok
2 + "end" S range .
how are you? ok

``` Tcl provides 16 more string commands. Add what you need to the [objecttype](./Objecttypes).

#### list

Definition: *{list}* list *name*

Commands: index set ! getlist setlist append push pop length clear revert sort join print search last

``` {11 22 33} list L
ok
0 L .
11 ok
44 0 L ! L print
{44 22 33}
ok
55 L append L print
{44 22 33 55}
ok
L sort L print
{22 33 44 55}
ok
{aa bb} 2 L ! L print
{22 33 {aa bb} 55}
ok
L join L print
{22 33 aa bb 55}
ok
L revert L print
{55 bb aa 33 22}
ok
ok
"aa" L search .
2 ok
L last .
22 ok
L length .
5 ok
100 L push L print
{55 bb aa 33 22 100}
ok
L pop .
100 ok
L getlist
({55 bb aa 33 22}) ok
.
55 bb aa 33 22 ok
{a b c} L setlist L getlist .
a b c ok

```
#### file
Definition: *filename* file *handle*

Commands: open open-w close put get eof

``` "forth.fth" file f
f open begin f get .cr f eof until f close
```