Jim Tcl
Check-in [da3b52d11c]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:docs: Formatting cleanups, consistency

Signed-off-by: Steve Bennett <steveb@workware.net.au>

Timelines: family | ancestors | descendants | both | trunk |
Files: files | file ages | folders
SHA1: da3b52d11cb8f115ca554a999c444a2f4dedc67f
User & Date: steveb@workware.net.au 2019-11-06 07:39:45
Context
2019-11-06
07:42
build: improve build for shared objects

Rather than listing the build rules for each shared object (loadable module) in the Makefile template, generate the build rules in configure.

Also, if an extension is configured as a module, any automatic dependencies required by the extension are configured as modules by default.

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: b5c6f1bdf0 user: steveb@workware.net.au tags: trunk,

07:39
docs: Formatting cleanups, consistency

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: da3b52d11c user: steveb@workware.net.au tags: trunk,

07:04
docs: Remove docs for the case command

This command no longer exists in Jim Tcl, so remove it from the documentation.

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: e328b9ce5b user: steveb@workware.net.au tags: trunk,

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to jim_tcl.txt.

305
306
307
308
309
310
311

312

313
314
315
316
317
318
319
...
358
359
360
361
362
363
364

365

366
367
368
369
370
371
372
...
381
382
383
384
385
386
387

388

389
390
391
392
393
394
395
396
397
398
399

400
401
402
403

404
405
406
407
408
409
410
...
413
414
415
416
417
418
419

420

421
422
423
424
425
426

427

428
429
430
431
432

433

434
435
436

437
438

439
440
441
442
443

444
445

446
447
448

449
450

451
452
453
454
455
456
457
...
460
461
462
463
464
465
466

467

468
469
470

471

472
473
474
475
476
477
478
479
480
481
482
483
484

485

486
487
488

489

490
491
492

493

494
495
496

497

498
499
500
501
502
503
504
505
506
507
508

509

510
511
512

513

514
515
516
517
518
519
520
...
600
601
602
603
604
605
606

607

608
609
610
611
612
613
614
615
616

617

618
619
620
621
622
623
624
...
625
626
627
628
629
630
631

632

633
634
635
636
637
638
639
...
704
705
706
707
708
709
710

711

712
713
714
715
716
717
718
...
776
777
778
779
780
781
782

783
784
785
786

787
788
789
790
791
792
793
...
868
869
870
871
872
873
874

875

876
877
878
879
880
881
882

883

884
885
886
887
888
889
890
...
900
901
902
903
904
905
906

907

908
909
910

911
912

913
914
915
916
917
918
919
920
921
922
923
924

925
926

927
928
929
930
931
932
933
934
935
936

937

938
939
940
941
942
943
944
945
946
947
948
949
950

951

952
953
954
955
956
957
958
959
960
961
962
963

964

965
966
967
968
969
970
971
972
973
974
975
976

977

978
979
980
981
982
983
984
985

986

987
988
989
990
991
992
993
994

995

996
997
998
999
1000
1001
1002
....
1011
1012
1013
1014
1015
1016
1017

1018
1019

1020
1021
1022
1023
1024

1025

1026
1027
1028
1029
1030
1031
1032
....
1194
1195
1196
1197
1198
1199
1200

1201

1202
1203
1204
1205
1206
1207
1208
....
1224
1225
1226
1227
1228
1229
1230

1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242

1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
....
1266
1267
1268
1269
1270
1271
1272

1273

1274
1275
1276
1277
1278
1279
1280
1281

1282
1283

1284
1285
1286
1287
1288
1289
1290
....
1307
1308
1309
1310
1311
1312
1313

1314
1315
1316
1317
1318
1319
1320
1321
1322

1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335

1336
1337

1338
1339
1340

1341

1342
1343
1344
1345
1346
1347
1348

1349
1350

1351
1352
1353

1354

1355
1356
1357
1358
1359
1360
1361
....
1386
1387
1388
1389
1390
1391
1392

1393
1394
1395
1396
1397
1398
1399
1400
1401
1402

1403
1404
1405
1406
1407
1408
1409
....
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432
1433

1434
1435
1436
1437
1438
1439
1440

1441
1442
1443
1444

1445
1446
1447
1448
1449
1450
1451
....
1455
1456
1457
1458
1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1469
1470

1471
1472
1473
1474
1475
1476
1477

1478
1479
1480
1481

1482
1483
1484
1485
1486
1487

1488
1489
1490
1491
1492
1493

1494
1495
1496
1497
1498
1499
1500
1501
1502

1503

1504
1505
1506
1507
1508
1509
1510
....
1523
1524
1525
1526
1527
1528
1529

1530

1531
1532
1533
1534
1535
1536

1537

1538
1539
1540
1541

1542

1543
1544
1545
1546

1547

1548
1549
1550
1551
1552
1553
1554
1555

1556

1557
1558
1559
1560
1561
1562
1563
....
1575
1576
1577
1578
1579
1580
1581

1582

1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
....
1628
1629
1630
1631
1632
1633
1634

1635
1636
1637
1638

1639
1640
1641
1642
1643
1644
1645
....
1770
1771
1772
1773
1774
1775
1776

1777
1778
1779
1780
1781

1782
1783
1784
1785
1786
1787
1788

1789

1790
1791
1792
1793
1794
1795
1796
....
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861

1862

1863
1864
1865

1866

1867
1868
1869
1870
1871
1872
1873
....
1881
1882
1883
1884
1885
1886
1887

1888
1889
1890
1891

1892
1893
1894
1895
1896
1897
1898
....
2020
2021
2022
2023
2024
2025
2026

2027
2028
2029

2030
2031
2032
2033
2034
2035
2036
2037
2038
2039

2040
2041
2042
2043

2044
2045
2046
2047
2048
2049
2050
....
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234

2235
2236

2237
2238
2239
2240
2241
2242
2243
....
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
....
2395
2396
2397
2398
2399
2400
2401

2402
2403
2404
2405
2406

2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
....
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
....
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
....
2832
2833
2834
2835
2836
2837
2838

2839

2840
2841
2842

2843

2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855

2856
2857
2858

2859
2860
2861
2862
2863
2864
2865
....
2871
2872
2873
2874
2875
2876
2877

2878
2879
2880
2881
2882
2883
2884
2885
2886

2887
2888
2889
2890

2891
2892
2893
2894
2895
2896
2897
2898
2899
2900

2901
2902
2903
2904
2905
2906
2907
2908

2909

2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
....
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
....
2959
2960
2961
2962
2963
2964
2965

2966

2967
2968
2969

2970

2971
2972
2973

2974

2975
2976
2977
2978
2979
2980
2981
....
2988
2989
2990
2991
2992
2993
2994

2995

2996
2997
2998
2999
3000
3001
3002
....
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020

3021

3022
3023
3024
3025
3026
3027
3028
....
3035
3036
3037
3038
3039
3040
3041

3042
3043
3044
3045

3046
3047
3048
3049
3050
3051
3052
....
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
....
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
....
3109
3110
3111
3112
3113
3114
3115

3116
3117

3118
3119
3120
3121
3122
3123
3124

3125
3126

3127
3128
3129
3130
3131
3132
3133
....
3212
3213
3214
3215
3216
3217
3218

3219
3220
3221
3222

3223
3224
3225
3226
3227
3228
3229
....
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
....
3367
3368
3369
3370
3371
3372
3373

3374
3375
3376
3377
3378
3379
3380

3381
3382
3383
3384
3385
3386
3387
....
3397
3398
3399
3400
3401
3402
3403

3404
3405
3406
3407
3408
3409
3410
3411

3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
....
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
....
3588
3589
3590
3591
3592
3593
3594

3595

3596
3597

3598
3599
3600
3601
3602
3603
3604
....
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
....
3762
3763
3764
3765
3766
3767
3768

3769

3770
3771
3772
3773
3774
3775
3776
3777
3778

3779
3780
3781
3782
3783
3784
3785
3786

3787
3788
3789

3790
3791
3792
3793
3794
3795
3796
3797

3798
3799
3800
3801
3802
3803
3804
....
3838
3839
3840
3841
3842
3843
3844

3845

3846
3847
3848

3849

3850
3851
3852
3853
3854
3855
3856
....
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
....
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
....
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978

3979

3980
3981
3982
3983
3984
3985
3986

3987

3988
3989
3990
3991
3992
3993
3994
....
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
....
4099
4100
4101
4102
4103
4104
4105

4106
4107

4108
4109
4110
4111
4112
4113
4114
....
4165
4166
4167
4168
4169
4170
4171

4172

4173
4174
4175

4176
4177
4178
4179
4180
4181

4182
4183
4184

4185
4186
4187
4188
4189
4190

4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202

4203

4204

4205

4206
4207
4208

4209
4210
4211
4212
4213

4214
4215
4216
4217
4218
4219
4220
....
4239
4240
4241
4242
4243
4244
4245

4246

4247
4248
4249
4250
4251
4252
4253
....
4274
4275
4276
4277
4278
4279
4280

4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293

4294
4295
4296
4297
4298
4299
4300
....
4379
4380
4381
4382
4383
4384
4385

4386

4387
4388
4389
4390
4391
4392

4393

4394
4395
4396
4397
4398
4399
4400
....
4428
4429
4430
4431
4432
4433
4434

4435
4436
4437
4438

4439
4440
4441
4442
4443
4444
4445
....
4506
4507
4508
4509
4510
4511
4512

4513
4514

4515
4516
4517
4518
4519
4520
4521
....
4784
4785
4786
4787
4788
4789
4790

4791
4792
4793
4794
4795
4796

4797
4798
4799
4800

4801
4802
4803
4804
4805
4806
4807
4808
4809

4810
4811
4812
4813
4814
4815
4816
....
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
....
5166
5167
5168
5169
5170
5171
5172

5173
5174
5175
5176
5177
5178
5179
5180

5181
5182
5183
5184
5185
5186
5187
by newline characters or semi-colons.
Each command consists of a collection of fields separated by
white space (spaces or tabs).
The first field must be the name of a command, and the
additional fields, if any, are arguments that will be passed to
that command.  For example, the command:


    set a 22


has three fields:  the first, `set`, is the name of a Tcl command, and
the last two, 'a' and '22', will be passed as arguments to
the `set` command.  The command name may refer either to a built-in
Tcl command, an application-specific command bound in with the library
procedure 'Jim_CreateCommand', or a command procedure defined with the
`proc` built-in command.
................................................................................

If an argument field begins with a double-quote, then the argument isn't
terminated by white space (including newlines) or a semi-colon (see below
for information on semi-colons); instead it ends at the next double-quote
character.  The double-quotes are not included in the resulting argument.
For example, the command


    set a "This is a single argument"


will pass two arguments to `set`:  'a' and 'This is a single argument'.

Within double-quotes, command substitutions, variable substitutions,
and backslash substitutions still occur, as described below.  If the
first character of a command field is not a quote, then quotes receive
no special interpretation in the parsing of that field.
................................................................................
can be used to prevent substitutions where they are undesirable.

If an argument field begins with a left brace, then the argument ends
at the matching right brace.  Tcl will strip off the outermost layer
of braces and pass the information between the braces to the command
without any further modification.  For example, in the command


    set a {xyz a {b c d}}


the `set` command will receive two arguments: 'a'
and 'xyz a {b c d}'.

When braces or quotes are in effect, the matching brace or quote need
not be on the same line as the starting quote or brace; in this case
the newline will be included in the argument field along with any other
characters up to the matching brace or quote.  For example, the `eval`
command takes one argument, which is a command string; `eval` invokes
the Tcl interpreter to execute the command string.  The command


    eval {
      set a 22
      set b 33
    }


will assign the value '22' to 'a' and '33' to 'b'.

If the first character of a command field is not a left
brace, then neither left nor right
braces in the field will be treated specially (except as part of
variable substitution; see below).
................................................................................
----------------------------------
If an open bracket occurs in a field of a command, then command
substitution occurs (except for fields enclosed in braces).  All of the
text up to the matching close bracket is treated as a Tcl command and
executed immediately.  Then the result of that command is substituted
for the bracketed text.  For example, consider the command


    set a [set b]


When the `set` command has only a single argument, it is the name of a
variable and `set` returns the contents of that variable.  In this case,
if variable 'b' has the value 'foo', then the command above is equivalent
to the command


    set a foo


Brackets can be used in more complex ways.  For example, if the variable
'b' has the value 'foo' and the variable 'c' has the value 'gorp',
then the command


    set a xyz[set b].[set c]


is equivalent to the command


    set a xyzfoo.gorp



A bracketed command may contain multiple commands separated by newlines
or semi-colons in the usual fashion.  In this case the value of the last
command is used for substitution.  For example, the command


    set a x[set b 22
    expr $b+2]x


is equivalent to the command


    set a x24x



If a field is enclosed in braces then the brackets and the characters
between them are not interpreted specially; they are passed through to
the argument verbatim.

VARIABLE SUBSTITUTION WITH $
----------------------------
................................................................................
enclosed in braces then variable substitution will occur.  The characters
after the +$+, up to the first character that isn't a number, letter,
or underscore, are taken as a variable name and the string value of that
variable is substituted for the name.

For example, if variable 'foo' has the value 'test', then the command


    set a $foo.c


is equivalent to the command


    set a test.c


There are two special forms for variable substitution.  If the next
character after the name of the variable is an open parenthesis, then
the variable is assumed to be an array name, and all of the characters
between the open parenthesis and the next close parenthesis are taken as
an index into the array.  Command substitutions and variable substitutions
are performed on the information between the parentheses before it is
used as an index.

For example, if the variable 'x' is an array with one element named
'first' and value '87' and another element named '14' and value 'more',
then the command


    set a xyz$x(first)zyx


is equivalent to the command


    set a xyz87zyx


If the variable 'index' has the value '14', then the command


    set a xyz$x($index)zyx


is equivalent to the command


    set a xyzmorezyx


For more information on arrays, see VARIABLES AND ARRAYS below.

The second special form for variables occurs when the dollar sign is
followed by an open curly brace.  In this case the variable name consists
of all the characters up to the next curly brace.

Array references are not possible in this form:  the name between braces
is assumed to refer to a scalar variable.  For example, if variable
'foo' has the value 'test', then the command


    set a abc${foo}bar


is equivalent to the command


    set a abctestbar



Variable substitution does not occur in arguments that are enclosed in
braces:  the dollar sign and variable name are passed through to the
argument verbatim.

The dollar sign abbreviation is simply a shorthand form.  +$a+ is
................................................................................
    The 'u' form allows for one to four hex digits.
    The 'U' form allows for one to eight hex digits.
    The 'u\{nnn\}' form allows for one to eight hex digits, but makes it easier to insert
    characters UTF-8 characters which are followed by a hex digit.

For example, in the command


    set a \{x\[\ yz\141


the second argument to `set` will be +{x[ yza+.

If a backslash is followed by something other than one of the options
described above, then the backslash is transmitted to the argument
field without any special processing, and the Tcl scanner continues
normal processing with the next character.  For example, in the
command


    set \*a \\\{foo


The first argument to `set` will be +{backslash}*a+ and the second
argument will be +{backslash}{foo+.

If an argument is enclosed in braces, then backslash sequences inside
the argument are parsed but no substitution occurs (except for
backslash-newline):  the backslash
................................................................................
sequence is passed through to the argument as is, without making
any special interpretation of the characters in the backslash sequence.
In particular, backslashed braces are not counted in locating the
matching right brace that terminates the argument.
For example, in the
command


    set a {\{abc}


the second argument to `set` will be +{backslash}{abc+.

This backslash mechanism is not sufficient to generate absolutely
any argument structure; it only covers the
most common cases.  To produce particularly complicated arguments
it is probably easiest to use the `format` command along with
................................................................................
The operators permitted in Tcl expressions are a subset of
the operators permitted in C expressions, and they have the
same meaning and precedence as the corresponding C operators.
Expressions almost always yield numeric results
(integer or floating-point values).
For example, the expression


    8.2 + 6


evaluates to 14.2.

Tcl expressions differ from C expressions in the way that
operands are specified, and in that Tcl expressions support
non-numeric operands and string comparisons.

................................................................................
on the contents.

For some examples of simple expressions, suppose the variable 'a' has
the value 3 and the variable 'b' has the value 6.  Then the expression
on the left side of each of the lines below will evaluate to the value
on the right side of the line:


    $a + 3.1                6.1
    2 + "$a.$b"             5.6
    4*[llength "6 2"]       8
    {word one} < "word $a"  0


The valid operators are listed below, grouped in decreasing order
of precedence:
[[OperatorPrecedence]]
+int() double() round() abs(), rand(), srand()+::
    Unary functions (except rand() which takes no arguments)
    * +'int()'+ converts the numeric argument to an integer by truncating down.
................................................................................
    be of any type.

See the C manual for more details on the results
produced by each operator.
All of the binary operators group left-to-right within the same
precedence level.  For example, the expression


    4*2 < 7


evaluates to 0.

The +&&+, +||+, and +?:+ operators have 'lazy evaluation', just as
in C, which means that operands are not evaluated if they are not
needed to determine the outcome.  For example, in


    $v ? [a] : [b]


only one of +[a]+ or +[b]+ will actually be evaluated,
depending on the value of +$v+.

All internal computations involving integers are done with the C
type 'long long' if available, or 'long' otherwise, and all internal
computations involving floating-point are done with the C type
................................................................................

Conversion among internal representations for integer, floating-point,
string operands is done automatically as needed.
For arithmetic computations, integers are used until some
floating-point number is introduced, after which floating-point is used.
For example,


    5 / 4


yields the result 1, while


    5 / 4.0
    5 / ( [string length "abcd"] + 0.0 )


both yield the result 1.25.

String values may be used as operands of the comparison operators,
although the expression evaluator tries to do comparisons as integer
or floating-point when it can.
If one of the operands of a comparison is a string and the other
has a numeric value, the numeric operand is converted back to
a string using the C 'sprintf' format specifier
'%d' for integers and '%g' for floating-point values.
For example, the expressions


    "0x03" > "2"
    "0y" < "0x12"


both evaluate to 1.  The first comparison is done using integer
comparison, and the second is done using string comparison after
the second operand is converted to the string '18'.

In general it is safest to enclose an expression in braces when
entering it in a command:  otherwise, if the expression contains
any white space then the Tcl interpreter will split it
among several arguments.  For example, the command


    expr $a + $b


results in three arguments being passed to `expr`:  +$a+,
\+, and +$b+.  In addition, if the expression isn't in braces
then the Tcl interpreter will perform variable and command substitution
immediately (it will happen in the command parser rather than in
the expression parser).  In many cases the expression is being
passed to a command that will evaluate the expression later (or
even many times if, for example, the expression is to be used to
decide when to exit a loop).  Usually the desired goal is to re-do
the variable or command substitutions each time the expression is
evaluated, rather than once and for all at the beginning.  For example,
the command


    for {set i 1} $i<=10 {incr i} {...}        ** WRONG **


is probably intended to iterate over all values of +i+ from 1 to 10.
After each iteration of the body of the loop, `for` will pass
its second argument to the expression evaluator to see whether or not
to continue processing.  Unfortunately, in this case the value of +i+
in the second argument will be substituted once and for all when the
`for` command is parsed.  If +i+ was 0 before the `for`
command was invoked then the second argument of `for` will be +0\<=10+
which will always evaluate to 1, even though +i+ eventually
becomes greater than 10.  In the above case the loop will never
terminate.  Instead, the expression should be placed in braces:


    for {set i 1} {$i<=10} {incr i} {...}      ** RIGHT **


This causes the substitution of 'i'
to be delayed; it will be re-done each time the expression is
evaluated, which is the desired result.

LISTS
-----
The third major way that strings are interpreted in Tcl is as lists.
A list is just a string with a list-like structure
consisting of fields separated by white space.  For example, the
string


    Al Sue Anne John


is a list with four elements or fields.
Lists have the same basic structure as command strings, except
that a newline character in a list is treated as a field separator
just like space or tab.  Conventions for braces and quotes
and backslashes are the same for lists as for commands.  For example,
the string


    a b\ c {d e {f g h}}


is a list with three elements:  +a+, +b c+, and +d e {f g h}+.

Whenever an element is extracted from a list, the same rules about
braces and quotes and backslashes are applied as for commands.  Thus in
the example above when the third element is extracted from the list,
the result is


    d e {f g h}


(when the field was extracted, all that happened was to strip off
the outermost layer of braces).  Command substitution and
variable substitution are never
made on a list (at least, not by the list-processing commands; the
list can always be passed to the Tcl interpreter for evaluation).

................................................................................
--------------

A new addition to Tcl 8.5 is the ability to expand a list into separate
arguments. Support for this feature is also available in Jim.

Consider the following attempt to exec a list:


    set cmd {ls -l}
    exec $cmd


This will attempt to exec a command named "ls -l", which will clearly not
work. Typically eval and concat are required to solve this problem, however
it can be solved much more easily with +\{*\}+.


    exec {*}$cmd


This will expand the following argument into individual elements and then evaluate
the resulting command.

Note that the official Tcl syntax is +\{*\}+, however +\{expand\}+ is retained
for backward compatibility with experimental versions of this feature.

................................................................................

1. Required Arguments (including Reference Arguments)
2. Optional Arguments
3. Variable Argument

The following example illustrates precedence. Assume a procedure declaration:


    proc p {{a A} args b {c C} d} {...}


This procedure requires at least two arguments, but can accept an unlimited number.
The following table shows how various numbers of arguments are assigned.
Values marked as +-+ are assigned the default value.

[width="40%",frame="topbot",options="header"]
|==============
................................................................................
~~~~~~~~~~
In addition to procedure arguments, Jim procedures may declare static variables.
These variables scoped to the procedure and initialised at procedure definition.
Either from the static variable definition, or from the enclosing scope.

Consider the following example:


    jim> set a 1
    jim> proc a {} {a {b 2}} {
        set c 1
        puts "$a $b $c"
        incr a
        incr b
        incr c
    }
    jim> a
    1 2 1
    jim> a
    2 3 1


The static variable +'a'+ has no initialiser, so it is initialised from
the enclosing scope with the value 1. (Note that it is an error if there
is no variable with the same name in the enclosing scope). However +'b'+
has an initialiser, so it is initialised to 2.

Unlike a local variable, the value of a static variable is retained across
invocations of the procedure.

See the `proc` command for information on how to define procedures
and what happens when they are invoked. See also NAMESPACES.

VARIABLES - SCALARS AND ARRAYS
------------------------------
Tcl allows the definition of variables and the use of their values
either through '$'-style variable substitution, the `set`
command, or a few other mechanisms.

................................................................................
can have any number of elements, each with a name (called
its 'index') and a value.

Array indexes may be arbitrary strings; they need not be numeric.
Parentheses are used refer to array elements in Tcl commands.
For example, the command


    set x(first) 44


will modify the element of 'x' whose index is 'first'
so that its new value is '44'.

Two-dimensional arrays can be simulated in Tcl by using indexes
that contain multiple concatenated values.
For example, the commands


    set a(2,3) 1
    set a(3,6) 2


set the elements of 'a' whose indexes are '2,3' and '3,6'.

In general, array elements may be used anywhere in Tcl that scalar
variables may be used.

If an array is defined with a particular name, then there may
................................................................................
within a procedure normally refer to local variables associated with that
invocation of the procedure.  Local variables are deleted whenever
a procedure exits.  Either `global` command may be used to request
that a name refer to a global variable for the duration of the current
procedure (this is somewhat analogous to 'extern' in C), or the variable
may be explicitly scoped with the +::+ prefix. For example


    set a 1
    set b 2
    proc p {} {
        set c 3
        global a

        puts "$a $::b $c"
    }
    p


will output:

    1 2 3

ARRAYS AS LISTS IN JIM
----------------------
Unlike Tcl, Jim can automatically convert between a list (with an even
number of elements) and an array value. This is similar to the way Tcl
can convert between a string and a list.

For example:


  set a {1 one 2 two}
  puts $a(2)


will output:


  two


Thus `array set` is equivalent to `set` when the variable does not
exist or is empty.

The reverse is also true where an array will be converted into
a list.


  set a(1) one; set a(2) two
  puts $a


will output:


  1 one 2 two


DICTIONARY VALUES
-----------------
Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
of this command. Dictionaries provide efficient access to key-value
pairs, just like arrays, but dictionaries are pure values. This
means that you can pass them to a procedure just as a list or a
................................................................................
banana" are equivalent dictionaries (with different string
representations).

Note that in Jim, arrays are implemented as dictionaries.
Thus automatic conversion between lists and dictionaries applies
as it does for arrays.


  jim> dict set a 1 one
  1 one
  jim> dict set a 2 two
  1 one 2 two
  jim> puts $a
  1 one 2 two
  jim> puts $a(2)
  two
  jim> dict set a 3 T three
  1 one 2 two 3 {T three}


See the `dict` command for more details.

NAMESPACES
----------
Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
including a number of 3rd party components. While there is less need for namespaces
................................................................................

References
~~~~~~~~~~
A reference can be thought of as holding a value with one level of indirection,
where the value may be garbage collected when unreferenced.
Consider the following example:


    jim> set r [ref "One String" test]
    <reference.<test___>.00000000000000000000>
    jim> getref $r
    One String


The operation `ref` creates a references to the value specified by the
first argument. (The second argument is a "type" used for documentation purposes).

The operation `getref` is the dereferencing operation which retrieves the value
stored in the reference.


    jim> setref $r "New String"
    New String
    jim> getref $r
    New String


The operation `setref` replaces the value stored by the reference. If the old value
is no longer accessible by any reference, it will eventually be automatically be garbage
collected.

Garbage Collection
~~~~~~~~~~~~~~~~~~
................................................................................
With the introduction of references, it is possible to create values whose lifetime
transcend their scope. To support this, case, the Jim system will periodically identify
and discard objects which are no longer accessible by any reference.

The `collect` command may be used to force garbage collection.  Consider a reference created
with a finalizer:


    jim> proc f {ref value} { puts "Finaliser called for $ref,$value" }
    jim> set r [ref "One String" test f]
    <reference.<test___>.00000000000
    jim> collect
    0
    jim> set r ""
    jim> collect
    Finaliser called for <reference.<test___>.00000000000,One String
    1


Note that once the reference, 'r', was modified so that it no longer
contained a reference to the value, the garbage collector discarded
the value (after calling the finalizer).

The finalizer for a reference may be examined or changed with the `finalize` command


    jim> finalize $r
    f
    jim> finalize $r newf
    newf


Lambda Function
~~~~~~~~~~~~~~~
Jim provides a garbage collected `lambda` function. This is a procedure
which is able to create an anonymous procedure.  Consider:


    jim> set f [lambda {a} {{x 0}} { incr x $a }]
    jim> $f 1
    1
    jim> $f 2
    3
    jim> set f ""


This create an anonymous procedure (with the name stored in 'f'), with a static variable
which is incremented by the supplied value and the result returned.

Once the procedure name is no longer accessible, it will automatically be deleted
when the garbage collector runs.

The procedure may also be delete immediately by renaming it "". e.g.


    jim> rename $f ""


UTF-8 AND UNICODE
-----------------
If Jim is built with UTF-8 support enabled (configure --enable-utf),
then most string-related commands become UTF-8 aware.  These include,
but are not limited to, `string match`, `split`, `glob`, `scan` and
`format`.
................................................................................
Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +'U+1FFFFF'.

String Matching
~~~~~~~~~~~~~~~
Commands such as `string match`, `lsearch -glob`, `array names` and others use string
pattern matching rules. These commands support UTF-8. For example:


  string match a\[\ua0-\ubf\]b "a\u00a3b"


format and scan
~~~~~~~~~~~~~~~
+format %c+ allows a unicode codepoint to be be encoded. For example, the following will return
a string with two bytes and one character. The same as +{backslash}ub5+


  format %c 0xb5


`format` respects widths as character widths, not byte widths. For example, the following will
return a string with three characters, not three bytes.


  format %.3s \ub5\ub6\ub7\ub8


Similarly, +scan ... %c+ allows a UTF-8 to be decoded to a unicode codepoint. The following will set
+'a'+ to 181 (0xb5) and +'b'+ to 65 (0x41).


  scan \u00b5A %c%c a b


`scan %s` will also accept a character class, including unicode ranges.

String Classes
~~~~~~~~~~~~~~
`string is` has *not* been extended to classify UTF-8 characters. Therefore, the following
will return 0, even though the string may be considered to be alphabetic.


  string is alpha \ub5Test


This does not affect the string classes 'ascii', 'control', 'digit', 'double', 'integer' or 'xdigit'.

Case Mapping and Conversion
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jim provides a simplified unicode case mapping. This means that case conversion
and comparison will not increase or decrease the number of characters in a string.
................................................................................
Some UTF-8 character sequences are invalid, such as those beginning with '0xff',
those which represent character sequences longer than 3 bytes (greater than U+FFFF),
and those which end prematurely, such as a lone '0xc2'.

In these situations, the offending bytes are treated as single characters. For example,
the following returns 2.


  string bytelength \xff\xff


Regular Expressions
~~~~~~~~~~~~~~~~~~~
If UTF-8 support is enabled, the built-in regular expression engine will be
selected which supports UTF-8 strings and patterns.

See REGULAR EXPRESSIONS

BUILT-IN COMMANDS
-----------------
The Tcl library provides the following built-in commands, which will
be available in any application using Tcl.  In addition to these
built-in commands, there may be additional commands defined by each
application, plus commands defined as Tcl procedures.
................................................................................
alias
~~~~~
+*alias* 'name args\...'+

Creates a single word alias (command) for one or more words. For example,
the following creates an alias for the command `info exists`.


    alias e info exists
    if {[e var]} {
      ...
    }


`alias` returns +'name'+, allowing it to be used with `local`.

See also `proc`, `curry`, `lambda`, `local`, `info alias`, `exists -alias`

append
~~~~~~
................................................................................
for the return code +JIM_ERR+, the value of the key +-errorinfo+
will contain the current stack trace (the same result as `info stacktrace`),
the value of the key +-errorcode+ will contain the
same value as the global variable $::errorCode, and the value of
the key +-level+ will be the current return level (see `return -level`).
This can be useful to rethrow an error:


    if {[catch {...} msg opts]} {
        ...maybe do something with the error...
        incr opts(-level)
        return {*}$opts $msg
    }


Normally `catch` will +'not'+ catch any of the codes +JIM_EXIT+, +JIM_EVAL+ or +JIM_SIGNAL+.
The set of codes which will be caught may be modified by specifying the one more codes before
+'command'+.

e.g. To catch +JIM_EXIT+ but not +JIM_BREAK+ or +JIM_CONTINUE+


    catch -exit -nobreak -nocontinue -- { ... }


The use of +--+ is optional. It signifies that no more return code options follow.

Note that if a signal marked as `signal handle` is caught with `catch -signal`, the return value
(stored in +'resultVarName'+) is name of the signal caught.

cd
................................................................................
collect
~~~~~~~
+*collect*+

Normally reference garbage collection is automatically performed periodically.
However it may be run immediately with the `collect` command.

See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.

concat
~~~~~~
+*concat* 'arg ?arg \...?'+

This command treats each argument as a list and concatenates them
into a single list.  It permits any number of arguments.  For example,
the command


    concat a b {c d e} {f {g h}}


will return


    a b c d e f {g h}


as its result.

continue
~~~~~~~~
+*continue*+

................................................................................
+*alias* 'args\...'+

Similar to `alias` except it creates an anonymous procedure (lambda) instead of
a named procedure.

the following creates a local, unnamed alias for the command `info exists`.


    set e [local curry info exists]
    if {[$e var]} {
      ...
    }


`curry` returns the name of the procedure.

See also `proc`, `alias`, `lambda`, `local`.

dict
~~~~
................................................................................
it is used to initialize the stacktrace.

This feature is most useful in conjunction with the `catch` command:
if a caught error cannot be handled successfully, +'stacktrace'+ can be used
to return a stack trace reflecting the original point of occurrence
of the error:


    catch {...} errMsg
    ...
    error $errMsg [info stacktrace]


See also `errorInfo`, `info stacktrace`, `catch` and `return`

errorInfo
~~~~~~~~~
+*errorInfo* 'error ?stacktrace?'+

Returns a human-readable representation of the given error message and stack trace.
Typical usage is:


    if {[catch {...} error]} {
        puts stderr [errorInfo $error [info stacktrace]]
        exit 1
    }


See also `error`.

eval
~~~~
+*eval* 'arg ?arg\...?'+

................................................................................
Note that exit can be caught with `catch`.

expr
~~~~
+*expr* 'arg'+

Calls the expression processor to evaluate +'arg'+, and returns
the result as a string.  See the section EXPRESSIONS above.

Note that Jim supports a shorthand syntax for `expr` as +$(\...)+
The following two are identical.


  set x [expr {3 * 2 + 1}]
  set x $(3 * 2 + 1)


file
~~~~
+*file* 'option name ?arg\...?'+

Operate on a file or a file name.  +'name'+ is the name of a file.

................................................................................
    fashion as seconds from a fixed starting time (often January 1, 1970).
    If the file doesn't exist or its modified time cannot be queried then an
    error is generated. If +'time'+ is given, sets the modification time
    of the file to the given value.

+*file mtimeus* 'name ?time_us?'+::
    As for `file mtime` except the time value is in microseconds
	since the epoch (see also `clock microseconds`).
	Note that some platforms and some filesystems don't support high
	resolution timestamps for files.

+*file normalize* 'name'+::
    Return the normalized path of +'name'+. See 'realpath(3)'.

+*file owned* 'name'+::
    Return '1' if file +'name'+ is owned by the current user,
    '0' otherwise.
................................................................................
+*file writable* 'name'+::
    Return '1' if file +'name'+ is writable by
    the current user, '0' otherwise.

The `file` commands that return 0/1 results are often used in
conditional or looping commands, for example:


    if {![file exists foo]} {
        error {bad file name}
    } else {
        ...
    }


finalize
~~~~~~~~
+*finalize* 'reference ?command?'+

If +'command'+ is omitted, returns the finalizer command for the given reference.

Otherwise, sets a new finalizer command for the given reference. +'command'+ may be
the empty string to remove the current finalizer.

The reference must be a valid reference create with the `ref`
command.

See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.

flush
~~~~~
+*flush* 'fileId'+

+'fileId' *flush*+

................................................................................
getref
~~~~~~
+*getref* 'reference'+

Returns the string associated with +'reference'+. The reference must
be a valid reference create with the `ref` command.

See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.

gets
~~~~
+*gets* 'fileId ?varName?'+

+'fileId' *gets* '?varName?'+

................................................................................
~~~~~~
+*lambda* 'args ?statics? body'+

The `lambda` command is identical to `proc`, except rather than
creating a named procedure, it creates an anonymous procedure and returns
the name of the procedure.

See `proc` and GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.

lappend
~~~~~~~
+*lappend* 'varName value ?value value \...?'+

Treat the variable given by +'varName'+ as a list and append each of
the +'value'+ arguments to that list as a separate element, with spaces
................................................................................
If +'varName'+ doesn't exist, it is created as a list with elements given
by the +'value'+ arguments. `lappend` is similar to `append` except that
each +'value'+ is appended as a list element rather than raw text.

This command provides a relatively efficient way to build up large lists.
For example,


    lappend a $b


is much more efficient than


    set a [concat $a [list $b]]


when +$a+ is long.

lassign
~~~~~~~
+*lassign* 'list varName ?varName \...?'+

This command treats the value +'list'+ as a list and assigns successive elements from that list to
the variables given by the +'varName'+ arguments in order. If there are more variable names than
list elements, the remaining variables are set to the empty string. If there are more list elements
than variables, a list of unassigned elements is returned.


    jim> lassign {1 2 3} a b; puts a=$a,b=$b
    3
    a=1,b=2


local
~~~~~
+*local* 'cmd ?arg\...?'+

First, `local` evaluates +'cmd'+ with the given arguments. The return value must
be the name of an existing command, which is marked as having local scope.
................................................................................
the existing command will be kept rather than deleted, and may be called
via `upcall`. The previous command will be restored when the current
procedure exits. See `upcall` for more details.

In this example, a local procedure is created. Note that the procedure
continues to have global scope while it is active.


    proc outer {} {
      # proc ... returns "inner" which is marked local
      local proc inner {} {
        # will be deleted when 'outer' exits
      }

      inner
      ...
    }


In this example, the lambda is deleted at the end of the procedure rather
than waiting until garbage collection.


    proc outer {} {
      set x [lambda inner {args} {
        # will be deleted when 'outer' exits
      }]
      # Use 'function' here which simply returns $x
      local function $x

      $x ...
      ...
    }


loop
~~~~
+*loop* 'var first limit ?incr? body'+

Similar to `for` except simpler and possibly more efficient.
With a positive increment, equivalent to:


  for {set var $first} {$var < $limit} {incr var $incr} $body


If +'incr'+ is not specified, 1 is used.
Note that setting the loop variable inside the loop does not
affect the loop count.

lindex
~~~~~~
+*lindex* 'list ?index ...?'+

Treats +'list'+ as a Tcl list and returns element +'index'+ from it
(0 refers to the first element of the list).
See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.

In extracting the element, +'lindex'+ observes the same rules concerning
braces and quotes and backslashes as the Tcl command interpreter; however,
variable substitution and command substitution do not occur.

If no index values are given, simply returns +'list'+

................................................................................
of +'list'+. Each +'element'+ argument will become
a separate element of the new list. If +'index'+ is less than
or equal to zero, then the new elements are inserted at the
beginning of the list. If +'index'+ is greater than or equal
to the number of elements in the list, then the new elements are
appended to the list.

See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.

list
~~~~

+*list* 'arg ?arg \...?'+

This command returns a list comprised of all the arguments, +'arg'+. Braces
................................................................................
so that `eval` may be used to execute the resulting list, with
+'arg1'+ comprising the command's name and the other args comprising
its arguments. `list` produces slightly different results than
`concat`:  `concat` removes one level of grouping before forming
the list, while `list` works directly from the original arguments.
For example, the command


    list a b {c d e} {f {g h}}


will return


    a b {c d e} {f {g h}}


while `concat` with the same arguments will return


    a b c d e f {g h}


llength
~~~~~~~
+*llength* 'list'+

Treats +'list'+ as a list and returns a decimal string giving
the number of elements in it.
................................................................................

The `lset` command accepts a parameter, +'varName'+, which it interprets
as the name of a variable containing a Tcl list. It also accepts
zero or more indices into the list. Finally, it accepts a new value
for an element of varName. If no indices are presented, the command
takes the form:


    lset varName newValue


In this case, newValue replaces the old value of the variable
varName.

When presented with a single index, the `lset` command
treats the content of the varName variable as a Tcl list. It addresses
the index'th element in it (0 refers to the first element of the
................................................................................
designated element is replaced with newValue. This new list is
stored in the variable varName, and is also the return value from
the `lset` command.

If index is negative or greater than or equal to the number of
elements in $varName, then an error occurs.

See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.

If additional index arguments are supplied, then each argument is
used in turn to address an element within a sublist designated by
the previous indexing operation, allowing the script to alter
elements in sublists. The command,


    lset a 1 2 newValue


replaces element 2 of sublist 1 with +'newValue'+.

The integer appearing in each index argument must be greater than
or equal to zero. The integer appearing in each index argument must
be strictly less than the length of the corresponding list. In other
words, the `lset` command cannot change the size of a list. If an
................................................................................

+*lmap* 'varList list ?varList2 list2 \...? body'+

`lmap` is a "collecting" `foreach` which returns a list of its results.

For example:


    jim> lmap i {1 2 3 4 5} {expr $i*$i}
    1 4 9 16 25
    jim> lmap a {1 2 3} b {A B C} {list $a $b}
    {1 A} {2 B} {3 C}


If the body invokes `continue`, no value is added for this iteration.
If the body invokes `break`, the loop ends and no more values are added.

load
~~~~
+*load* 'filename'+
................................................................................
lrange
~~~~~~
+*lrange* 'list first last'+

+'list'+ must be a valid Tcl list. This command will return a new
list consisting of elements +'first'+ through +'last'+, inclusive.

See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.

If +'last'+ is greater than or equal to the number of elements
in the list, then it is treated as if it were +end+.

If +'first'+ is greater than +'last'+ then an empty string
is returned.

................................................................................
If +'first'+ is less than zero then it refers to the first
element of +'list'+;  the element indicated by +'first'+
must exist in the list.

+'last'+ gives the index in +'list'+ of the last element
to be replaced;  it must be greater than or equal to +'first'+.

See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.

The +'element'+ arguments specify zero or more new arguments to
be added to the list in place of those that were deleted.

Each +'element'+ argument will become a separate element of
the list.

................................................................................
lrepeat
~~~~~~~~
+*lrepeat* 'number element1 ?element2 \...?'+

Build a list by repeating elements +'number'+ times (which must be
a positive integer).


    jim> lrepeat 3 a b
    a b a b a b


lreverse
~~~~~~~~
+*lreverse* 'list'+

Returns the list in reverse order.


    jim> lreverse {1 2 3}
    3 2 1


lsearch
~~~~~~~
+*lsearch* '?options? list pattern'+

This command searches the elements +'list'+ to see if one of them matches +'pattern'+. If so, the
command returns the index of the first matching element (unless the options +-all+, +-inline+ or +-bool+ are
................................................................................
defer
~~~~~
+*defer* 'script'+

This command is a simple helper command to add a script to the '+$jim::defer+' variable
that will run when the current proc or interpreter exits. For example:


    jim> proc a {} { defer {puts "Leaving a"}; puts "Exit" }
    jim> a
    Exit
    Leaving a


If the '+$jim::defer+' variable exists, it is treated as a list of scripts to run
when the proc or interpreter exits.

open
~~~~
+*open* 'fileName ?access?'+
................................................................................

The `proc` command creates a new Tcl command procedure, +'name'+.
When the new command is invoked, the contents of +'body'+ will be executed.
Tcl interpreter. +'args'+ specifies the formal arguments to the procedure.
If specified, +'statics'+, declares static variables which are bound to the
procedure.

See PROCEDURES for detailed information about Tcl procedures.

The `proc` command returns +'name'+ (which is useful with `local`).

When a procedure is invoked, the procedure's return value is the
value specified in a `return` command.  If the procedure doesn't
execute an explicit `return`, then its return value is the value
of the last command executed in the procedure's body.
................................................................................
Output to files is buffered internally by Tcl; the `flush`
command may be used to force buffered characters to be output.

pipe
~~~~
Creates a pair of `aio` channels and returns the handles as a list: +{read write}+


    lassign [pipe] r w

    # Must close $w after exec
    exec ps >@$w &
    $w close

    $r readable ...


pwd
~~~
+*pwd*+

Returns the path name of the current working directory.

................................................................................
range
~~~~
+*range* '?start? end ?step?'+

Returns a list of integers starting at +'start'+ (defaults to 0)
and ranging up to but not including +'end'+ in steps of +'step'+ defaults to 1).


    jim> range 5
    0 1 2 3 4
    jim> range 2 5
    2 3 4
    jim> range 2 10 4
    2 6
    jim> range 7 4 -2
    7 5


read
~~~~
+*read* ?*-nonewline*? 'fileId'+

+'fileId' *read* ?*-nonewline*?+

+*read* 'fileId numBytes'+

+'fileId' *read* 'numBytes'+


In the first form, all of the remaining bytes are read from the file
given by +'fileId'+; they are returned as the result of the command.
If the +-nonewline+ switch is specified then the last
character of the file is discarded if it is a newline.

In the second form, the extra argument specifies how many bytes to read;
................................................................................
regexp
~~~~~~
+*regexp ?-nocase? ?-line? ?-indices? ?-start* 'offset'? *?-all? ?-inline? ?--?* 'exp string ?matchVar? ?subMatchVar subMatchVar \...?'+

Determines whether the regular expression +'exp'+ matches part or
all of +'string'+ and returns 1 if it does, 0 if it doesn't.

See REGULAR EXPRESSIONS above for complete information on the
syntax of +'exp'+ and how it is matched against +'string'+.

If additional arguments are specified after +'string'+ then they
are treated as the names of variables to use to return
information about which part(s) of +'string'+ matched +'exp'+.
+'matchVar'+ will be set to the range of +'string'+ that
matched all of +'exp'+. The first +'subMatchVar'+ will contain
................................................................................
Create a new reference containing +'string'+ of type +'tag'+.
If +'finalizer'+ is specified, it is a command which will be invoked
when the a garbage collection cycle runs and this reference is
no longer accessible.

The finalizer is invoked as:


  finalizer reference string


See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.


rename
~~~~~~
+*rename* 'oldName newName'+

Rename the command that used to be called +'oldName'+ so that it
is now called +'newName'+.  If +'newName'+ is an empty string
................................................................................
~~~~~~
+*setref* 'reference string'+

Store a new string in +'reference'+, replacing the existing string.
The reference must be a valid reference create with the `ref`
command.

See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.

signal
~~~~~~
Command for signal handling.

See `kill` for the different forms which may be used to specify signals.

................................................................................
    If +-clear+ is specified, any signals returned are removed and will not be
    returned by subsequent calls to `signal check` unless delivered again.

+*signal throw* ?'signal'?+::
    Raises the given signal, which defaults to +SIGINT+ if not specified.
    The behaviour is identical to:


        kill signal [pid]


Note that `signal handle` and `signal ignore` represent two forms of signal
handling. `signal handle` is used in conjunction with `catch -signal` or `try -signal`
to immediately abort execution when the signal is delivered. Alternatively, `signal ignore`
is used in conjunction with `signal check` to handle signal synchronously. Consider the
two examples below.

Prevent a processing from taking too long


    signal handle SIGALRM
    alarm 20
    try -signal {
        .. possibly long running process ..
        alarm 0
    } on signal {sig} {
        puts stderr "Process took too long"
    }


Handle SIGHUP to reconfigure:


    signal ignore SIGHUP
    while {1} {
        ... handle configuration/reconfiguration ...
        while {[signal check -clear SIGHUP] eq ""} {
            ... do processing ..
        }
        # Received SIGHUP, so reconfigure
    }


Note: signal handling is currently not supported in child interpreters.
In these interpreters, the signal command does not exist.

sleep
~~~~~
+*sleep* 'seconds'+
................................................................................

If +'splitChars'+ is an empty string then each character of
+'string'+ becomes a separate element of the result list.

+'splitChars'+ defaults to the standard white-space characters.
For example,


    split "comp.unix.misc" .


returns +'"comp unix misc"'+ and


    split "Hello world" {}


returns +'"H e l l o { } w o r l d"'+.

stackdump
~~~~~~~~~

+*stackdump* 'stacktrace'+
................................................................................
Perform one of several string operations, depending on +'option'+.
The legal options (which may be abbreviated) are:

+*string bytelength* 'string'+::
    Returns the length of the string in bytes. This will return
    the same value as `string length` if UTF-8 support is not enabled,
    or if the string is composed entirely of ASCII characters.
    See UTF-8 AND UNICODE.

+*string byterange* 'string first last'+::
    Like `string range` except works on bytes rather than characters.
    These commands are identical if UTF-8 support is not enabled.

+*string cat* '?string1 string2 \...?'+::
    Concatenates the given strings into a single string.
................................................................................
+*string first* 'string1 string2 ?firstIndex?'+::
    Search +'string2'+ for a sequence of characters that exactly match
    the characters in +'string1'+.  If found, return the index of the
    first character in the first such match within +'string2'+.  If not
    found, return -1. If +'firstIndex'+ is specified, matching will start
    from +'firstIndex'+ of +'string1'+.
 ::
    See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'firstIndex'+.

+*string index* 'string charIndex'+::
    Returns the +'charIndex'+'th character of the +'string'+
    argument.  A +'charIndex'+ of 0 corresponds to the first
    character of the string.
    If +'charIndex'+ is less than 0 or greater than
    or equal to the length of the string then an empty string is
    returned.
 ::
    See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'charIndex'+.

+*string is* 'class' ?*-strict*? 'string'+::
    Returns 1 if +'string'+ is a valid member of the specified character
    class, otherwise returns 0. If +-strict+ is specified, then an
    empty string returns 0, otherwise an empty string will return 1
    on any class. The following character classes are recognized
    (the class name can be abbreviated):
................................................................................
  +lower+;;  Any lower case alphabet character.
  +print+;;  Any printing character, including space.
  +punct+;;  Any punctuation character.
  +space+;;  Any space character.
  +upper+;;  Any upper case alphabet character.
  +xdigit+;; Any hexadecimal digit character ([0-9A-Fa-f]).
 ::
    Note that string classification does +'not'+ respect UTF-8. See UTF-8 AND UNICODE
 ::
    Note that only +'lowercase'+ boolean values are recognized (Tcl accepts any case).

+*string last* 'string1 string2 ?lastIndex?'+::
    Search +'string2'+ for a sequence of characters that exactly match
    the characters in +'string1'+.  If found, return the index of the
    first character in the last such match within +'string2'+.  If there
    is no match, then return -1. If +'lastIndex'+ is specified, only characters
    up to +'lastIndex'+ of +'string2'+ will be considered in the match.
 ::
    See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'lastIndex'+.

+*string length* 'string'+::
    Returns a decimal string giving the number of characters in +'string'+.
    If UTF-8 support is enabled, this may be different than the number of bytes.
    See UTF-8 AND UNICODE

+*string map ?-nocase?* 'mapping string'+::
    Replaces substrings in +'string'+ based on the key-value pairs in
    +'mapping'+, which is a list of +key value key value \...+ as in the form
    returned by `array get`. Each instance of a key in the string will be
    replaced with its corresponding value.  If +-nocase+ is specified, then
    matching is done without regard to case differences. Both key and value may
    be multiple characters.  Replacement is done in an ordered manner, so the
    key appearing first in the list will be checked first, and so on. +'string'+ is
    only iterated over once, so earlier key replacements will have no affect for
    later key matches. For example,


      string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc


 ::
    will return the string +01321221+.
 ::
    Note that if an earlier key is a prefix of a later one, it will completely mask the later
    one.  So if the previous example is reordered like this,


      string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc


 ::
    it will return the string +02c322c222c+.

+*string match ?-nocase?* 'pattern string'+::
    See if +'pattern'+ matches +'string'+; return 1 if it does, 0
    if it doesn't.  Matching is done in a fashion similar to that
................................................................................

+*string range* 'string first last'+::
    Returns a range of consecutive characters from +'string'+, starting
    with the character whose index is +'first'+ and ending with the
    character whose index is +'last'+.  An index of 0 refers to the
    first character of the string.
 ::
    See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
 ::
    If +'first'+ is less than zero then it is treated as if it were zero, and
    if +'last'+ is greater than or equal to the length of the string then
    it is treated as if it were +end+.  If +'first'+ is greater than
    +'last'+ then an empty string is returned.

+*string repeat* 'string count'+::
................................................................................
is performed: open and close brackets are treated as ordinary
characters with no special interpretation.

*Note*: when it performs its substitutions, subst does not give any
special treatment to double quotes or curly braces. For example,
the following script returns +xyz \{44\}+, not +xyz \{$a\}+.


    set a 44
    subst {xyz {$a}}



switch
~~~~~~
+*switch* '?options? string pattern body ?pattern body \...?'+

+*switch* '?options? string {pattern body ?pattern body \...?}'+
................................................................................
pattern should also be used as the body for this pattern (if the
next pattern also has a body of +-+ then the body after that is
used, and so on). This feature makes it possible to share a single
body among several patterns.

Below are some examples of `switch` commands:


    switch abc a - b {format 1} abc {format 2} default {format 3}


will return 2,


    switch -regexp aaab {
           ^a.*b$ -
           b {format 1}
           a* {format 2}
           default {format 3}
    }


will return 1, and


    switch xyz {
           a -
           b {format 1}
           a* {format 2}
           default {format 3}
    }


will return 3.

tailcall
~~~~~~~~
+*tailcall* 'cmd ?arg\...?'+

The `tailcall` command provides an optimised way of invoking a command whilst replacing
the current call frame. This is similar to 'exec' in Bourne Shell.

The following are identical except the first immediately replaces the current call frame.


  tailcall a b c



  return [uplevel 1 [list a b c]]


`tailcall` is useful as a dispatch mechanism:


  proc a {cmd args} {
    tailcall sub_$cmd {*}$args
  }
  proc sub_cmd1 ...
  proc sub_cmd2 ...


tell
~~~~
+*tell* 'fileId'+

+'fileId' *tell*+

................................................................................
~~~~
+*time* 'command ?count?'+

This command will call the Tcl interpreter +'count'+
times to execute +'command'+ (or once if +'count'+ isn't
specified).  It will then return a string of the form


    503 microseconds per iteration


which indicates the average amount of time required per iteration,
in microseconds.

Time is measured in elapsed time, not CPU time.

try
................................................................................
or as integers.

If +'resultvar'+ and +'optsvar'+ are specified, they are set as for `catch` before evaluating
the matching handler.

For example:


    set f [open input]
    try -signal {
        process $f
    } on {continue break} {} {
        error "Unexpected break/continue"
    } on error {msg opts} {
        puts "Dealing with error"
        return {*}$opts $msg
    } on signal sig {
        puts "Got signal: $sig"
    } finally {
        $f close
    }


If break, continue or error are raised, they are dealt with by the matching
handler.

In any case, the file will be closed via the 'finally' clause.

See also `throw`, `catch`, `return`, `error`.
................................................................................

If +'level'+ is '3' or +#0+ then the command will be executed
at top-level (only global variables will be visible).
The `uplevel` command causes the invoking procedure to disappear
from the procedure calling stack while the command is being executed.
In the above example, suppose 'c' invokes the command


    uplevel 1 {set x 43; d}


where 'd' is another Tcl procedure.  The `set` command will
modify the variable 'x' in 'b's context, and 'd' will execute
at level 3, as if called from 'b'.  If it in turn executes
the command


    uplevel {set x 42}


then the `set` command will modify the same variable 'x' in 'b's
context:  the procedure 'c' does not appear to be on the call stack
when 'd' is executing.  The command `info level` may
be used to obtain the level of the current procedure.

`uplevel` makes it possible to implement new control
................................................................................
`upvar` returns an empty string.

The `upvar` command simplifies the implementation of call-by-name
procedure calling and also makes it easier to build new control constructs
as Tcl procedures.
For example, consider the following procedure:


    proc add2 name {
        upvar $name x
        set x [expr $x+2]
    }


'add2' is invoked with an argument giving the name of a variable,
and it adds two to the value of that variable.
Although 'add2' could have been implemented using `uplevel`
instead of `upvar`, `upvar` makes it simpler for 'add2'
to access the variable in the caller's procedure frame.

................................................................................

+*os.gethostname*+::
    Invokes 'gethostname(3)' and returns the result.

+*os.getids*+::
    Returns the various user/group ids for the current process.


    jim> os.getids
    uid 1000 euid 1000 gid 100 egid 100


+*os.uptime*+::
    Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.

ANSI I/O (aio) and EVENTLOOP API
--------------------------------
Jim provides an alternative object-based API for I/O.
................................................................................

This command creates a socket connected (client) or bound (server) to the given
address.

The returned value is channel and may generally be used with the various file I/O
commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.


    . set f [socket stream www.google.com:80]
    aio.sockstream1
    . $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
    . $f gets
    HTTP/1.0 302 Found
    . $f close


Server sockets, however support only 'accept', which is most useful in conjunction with
the EVENTLOOP API.


    set f [socket stream.server 80]
    $f readable {
        set client [$f accept]
        $client gets $buf
        ...
        $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
        $client close
    }
    vwait done


The address, +'addr'+, can be given in one of the following forms:

1. For IPv4 socket types, an IPv4 address such as 192.168.1.1
2. For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
3. A hostname

................................................................................
~~~~~~
The optional, pure-Tcl 'binary' extension provides the Tcl-compatible `binary scan` and `binary format`
commands based on the low-level `pack` and `unpack` commands.

See the Tcl documentation at: http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm

Note that 'binary format' with f/r/R specifiers (single-precision float) uses the value of Infinity
 in case of overflow.

oo: class, super
~~~~~~~~~~~~~~~~
The optional, pure-Tcl 'oo' extension provides object-oriented (OO) support for Jim Tcl.

See the online documentation (http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/) for more details.

................................................................................
    or 0 otherwise.

+*tcl_platform*+::
    This variable is set by Jim as an array containing information
    about the platform upon which Jim was built. The following is an
    example of the contents of this array.


    tcl_platform(byteOrder)     = littleEndian
    tcl_platform(engine)        = Jim
    tcl_platform(os)            = Darwin
    tcl_platform(platform)      = unix
    tcl_platform(pointerSize)   = 8
    tcl_platform(threaded)      = 0
    tcl_platform(wordSize)      = 8
    tcl_platform(pathSeparator) = :


+*argv0*+::
    If jimsh is invoked to run a script, this variable contains the name
    of the script.

+*argv*+::
    If jimsh is invoked to run a script, this variable contains a list







>

>







 







>

>







 







>

>











>




>







 







>

>






>

>





>

>



>

<
>





>


>



>

<
>







 







>

>



>

>













>

>



>

>



>

>



>

>

|









>

>



>

>







 







>

>









>

>







 







>

>







 







>

>







 







>




>







 







>

>







>

>







 







>

>



>


>












>


>










>

>













>

>












>

>












>

>








>

>








>

>







 







>


>





>

>







 







>

>







 







>
|
|






|

|

>










|







 







>

>








>


>







 







>
|
|
|





|
>













>


>



>

>







>


>



>

>







 







>
|

|

|

|

|

>







 







>
|

|

>







>
|

|

>







 







>
|
|

|

|
|


>







>
|

|

>






>
|
|

|

|
>









>
|
>







 







>

>






>

>




>

>




>

>








>

>







 







>

>






|







 







>




>







 







>





>







>

>







 







|









>

>



>

>







 







>




>







 







>



>










>




>







 







|




>


>







 







|
|
|







 







>





>













|







 







|







 







|







 







>

>



>

>












>
|


>







 







>









>




>










>








>
|
>











|







 







|







 







>

>



>

>



>

>







 







>

>







 







|






>

>







 







>
|

|

>







 







|







 







|







 







>
|

>







>
|

>







 







>
|
|


>







 







|







 







>







>







 







>
|

|

|

|

>










<







 







|







 







>
|
>

<
>







 







|







 







>
|
>









>








>



>








>







 







>

>



>

>







 







|







 







|









|







 







|










|




|












>

>







>

>







 







|







 







>


>







 







>

>



>






>



>






>












>

>

>

>



>





>







 







>

>







 







>













>







 







>

>






>

>







 







>




>







 







>
|

>







 







>






>




>









>







 







|







 







>








>







305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
...
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
...
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
...
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
460
461
462
463
464
465
466
467

468
469
470
471
472
473
474
475
...
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
...
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
...
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
...
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
...
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
...
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
...
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
....
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
....
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
....
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
....
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
....
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
....
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
....
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
....
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
....
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
....
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
....
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
....
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
....
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
....
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
....
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
....
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
....
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
....
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
....
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
....
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
....
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
....
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
....
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
....
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
....
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
....
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
....
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
....
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
....
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
....
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
....
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
....
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
....
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
....
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589

3590
3591
3592
3593
3594
3595
3596
....
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
....
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765

3766
3767
3768
3769
3770
3771
3772
3773
....
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
....
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
....
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
....
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
....
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
....
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
....
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
....
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
....
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
....
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
....
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
....
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
....
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
....
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
....
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
....
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
....
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
by newline characters or semi-colons.
Each command consists of a collection of fields separated by
white space (spaces or tabs).
The first field must be the name of a command, and the
additional fields, if any, are arguments that will be passed to
that command.  For example, the command:

----
    set a 22
----

has three fields:  the first, `set`, is the name of a Tcl command, and
the last two, 'a' and '22', will be passed as arguments to
the `set` command.  The command name may refer either to a built-in
Tcl command, an application-specific command bound in with the library
procedure 'Jim_CreateCommand', or a command procedure defined with the
`proc` built-in command.
................................................................................

If an argument field begins with a double-quote, then the argument isn't
terminated by white space (including newlines) or a semi-colon (see below
for information on semi-colons); instead it ends at the next double-quote
character.  The double-quotes are not included in the resulting argument.
For example, the command

----
    set a "This is a single argument"
----

will pass two arguments to `set`:  'a' and 'This is a single argument'.

Within double-quotes, command substitutions, variable substitutions,
and backslash substitutions still occur, as described below.  If the
first character of a command field is not a quote, then quotes receive
no special interpretation in the parsing of that field.
................................................................................
can be used to prevent substitutions where they are undesirable.

If an argument field begins with a left brace, then the argument ends
at the matching right brace.  Tcl will strip off the outermost layer
of braces and pass the information between the braces to the command
without any further modification.  For example, in the command

----
    set a {xyz a {b c d}}
----

the `set` command will receive two arguments: 'a'
and 'xyz a {b c d}'.

When braces or quotes are in effect, the matching brace or quote need
not be on the same line as the starting quote or brace; in this case
the newline will be included in the argument field along with any other
characters up to the matching brace or quote.  For example, the `eval`
command takes one argument, which is a command string; `eval` invokes
the Tcl interpreter to execute the command string.  The command

----
    eval {
      set a 22
      set b 33
    }
----

will assign the value '22' to 'a' and '33' to 'b'.

If the first character of a command field is not a left
brace, then neither left nor right
braces in the field will be treated specially (except as part of
variable substitution; see below).
................................................................................
----------------------------------
If an open bracket occurs in a field of a command, then command
substitution occurs (except for fields enclosed in braces).  All of the
text up to the matching close bracket is treated as a Tcl command and
executed immediately.  Then the result of that command is substituted
for the bracketed text.  For example, consider the command

----
    set a [set b]
----

When the `set` command has only a single argument, it is the name of a
variable and `set` returns the contents of that variable.  In this case,
if variable 'b' has the value 'foo', then the command above is equivalent
to the command

----
    set a foo
----

Brackets can be used in more complex ways.  For example, if the variable
'b' has the value 'foo' and the variable 'c' has the value 'gorp',
then the command

----
    set a xyz[set b].[set c]
----

is equivalent to the command

----
    set a xyzfoo.gorp

----

A bracketed command may contain multiple commands separated by newlines
or semi-colons in the usual fashion.  In this case the value of the last
command is used for substitution.  For example, the command

----
    set a x[set b 22
    expr $b+2]x
----

is equivalent to the command

----
    set a x24x

----

If a field is enclosed in braces then the brackets and the characters
between them are not interpreted specially; they are passed through to
the argument verbatim.

VARIABLE SUBSTITUTION WITH $
----------------------------
................................................................................
enclosed in braces then variable substitution will occur.  The characters
after the +$+, up to the first character that isn't a number, letter,
or underscore, are taken as a variable name and the string value of that
variable is substituted for the name.

For example, if variable 'foo' has the value 'test', then the command

----
    set a $foo.c
----

is equivalent to the command

----
    set a test.c
----

There are two special forms for variable substitution.  If the next
character after the name of the variable is an open parenthesis, then
the variable is assumed to be an array name, and all of the characters
between the open parenthesis and the next close parenthesis are taken as
an index into the array.  Command substitutions and variable substitutions
are performed on the information between the parentheses before it is
used as an index.

For example, if the variable 'x' is an array with one element named
'first' and value '87' and another element named '14' and value 'more',
then the command

----
    set a xyz$x(first)zyx
----

is equivalent to the command

----
    set a xyz87zyx
----

If the variable 'index' has the value '14', then the command

----
    set a xyz$x($index)zyx
----

is equivalent to the command

----
    set a xyzmorezyx
----

For more information on arrays, see <<_variables_scalars_and_arrays,VARIABLES - SCALARS AND ARRAYS>> below.

The second special form for variables occurs when the dollar sign is
followed by an open curly brace.  In this case the variable name consists
of all the characters up to the next curly brace.

Array references are not possible in this form:  the name between braces
is assumed to refer to a scalar variable.  For example, if variable
'foo' has the value 'test', then the command

----
    set a abc${foo}bar
----

is equivalent to the command

----
    set a abctestbar
----


Variable substitution does not occur in arguments that are enclosed in
braces:  the dollar sign and variable name are passed through to the
argument verbatim.

The dollar sign abbreviation is simply a shorthand form.  +$a+ is
................................................................................
    The 'u' form allows for one to four hex digits.
    The 'U' form allows for one to eight hex digits.
    The 'u\{nnn\}' form allows for one to eight hex digits, but makes it easier to insert
    characters UTF-8 characters which are followed by a hex digit.

For example, in the command

----
    set a \{x\[\ yz\141
----

the second argument to `set` will be +{x[ yza+.

If a backslash is followed by something other than one of the options
described above, then the backslash is transmitted to the argument
field without any special processing, and the Tcl scanner continues
normal processing with the next character.  For example, in the
command

----
    set \*a \\\{foo
----

The first argument to `set` will be +{backslash}*a+ and the second
argument will be +{backslash}{foo+.

If an argument is enclosed in braces, then backslash sequences inside
the argument are parsed but no substitution occurs (except for
backslash-newline):  the backslash
................................................................................
sequence is passed through to the argument as is, without making
any special interpretation of the characters in the backslash sequence.
In particular, backslashed braces are not counted in locating the
matching right brace that terminates the argument.
For example, in the
command

----
    set a {\{abc}
----

the second argument to `set` will be +{backslash}{abc+.

This backslash mechanism is not sufficient to generate absolutely
any argument structure; it only covers the
most common cases.  To produce particularly complicated arguments
it is probably easiest to use the `format` command along with
................................................................................
The operators permitted in Tcl expressions are a subset of
the operators permitted in C expressions, and they have the
same meaning and precedence as the corresponding C operators.
Expressions almost always yield numeric results
(integer or floating-point values).
For example, the expression

----
    8.2 + 6
----

evaluates to 14.2.

Tcl expressions differ from C expressions in the way that
operands are specified, and in that Tcl expressions support
non-numeric operands and string comparisons.

................................................................................
on the contents.

For some examples of simple expressions, suppose the variable 'a' has
the value 3 and the variable 'b' has the value 6.  Then the expression
on the left side of each of the lines below will evaluate to the value
on the right side of the line:

----
    $a + 3.1                6.1
    2 + "$a.$b"             5.6
    4*[llength "6 2"]       8
    {word one} < "word $a"  0
----

The valid operators are listed below, grouped in decreasing order
of precedence:
[[OperatorPrecedence]]
+int() double() round() abs(), rand(), srand()+::
    Unary functions (except rand() which takes no arguments)
    * +'int()'+ converts the numeric argument to an integer by truncating down.
................................................................................
    be of any type.

See the C manual for more details on the results
produced by each operator.
All of the binary operators group left-to-right within the same
precedence level.  For example, the expression

----
    4*2 < 7
----

evaluates to 0.

The +&&+, +||+, and +?:+ operators have 'lazy evaluation', just as
in C, which means that operands are not evaluated if they are not
needed to determine the outcome.  For example, in

----
    $v ? [a] : [b]
----

only one of +[a]+ or +[b]+ will actually be evaluated,
depending on the value of +$v+.

All internal computations involving integers are done with the C
type 'long long' if available, or 'long' otherwise, and all internal
computations involving floating-point are done with the C type
................................................................................

Conversion among internal representations for integer, floating-point,
string operands is done automatically as needed.
For arithmetic computations, integers are used until some
floating-point number is introduced, after which floating-point is used.
For example,

----
    5 / 4
----

yields the result 1, while

----
    5 / 4.0
    5 / ( [string length "abcd"] + 0.0 )
----

both yield the result 1.25.

String values may be used as operands of the comparison operators,
although the expression evaluator tries to do comparisons as integer
or floating-point when it can.
If one of the operands of a comparison is a string and the other
has a numeric value, the numeric operand is converted back to
a string using the C 'sprintf' format specifier
'%d' for integers and '%g' for floating-point values.
For example, the expressions

----
    "0x03" > "2"
    "0y" < "0x12"
----

both evaluate to 1.  The first comparison is done using integer
comparison, and the second is done using string comparison after
the second operand is converted to the string '18'.

In general it is safest to enclose an expression in braces when
entering it in a command:  otherwise, if the expression contains
any white space then the Tcl interpreter will split it
among several arguments.  For example, the command

----
    expr $a + $b
----

results in three arguments being passed to `expr`:  +$a+,
\+, and +$b+.  In addition, if the expression isn't in braces
then the Tcl interpreter will perform variable and command substitution
immediately (it will happen in the command parser rather than in
the expression parser).  In many cases the expression is being
passed to a command that will evaluate the expression later (or
even many times if, for example, the expression is to be used to
decide when to exit a loop).  Usually the desired goal is to re-do
the variable or command substitutions each time the expression is
evaluated, rather than once and for all at the beginning.  For example,
the command

----
    for {set i 1} $i<=10 {incr i} {...}        ** WRONG **
----

is probably intended to iterate over all values of +i+ from 1 to 10.
After each iteration of the body of the loop, `for` will pass
its second argument to the expression evaluator to see whether or not
to continue processing.  Unfortunately, in this case the value of +i+
in the second argument will be substituted once and for all when the
`for` command is parsed.  If +i+ was 0 before the `for`
command was invoked then the second argument of `for` will be +0\<=10+
which will always evaluate to 1, even though +i+ eventually
becomes greater than 10.  In the above case the loop will never
terminate.  Instead, the expression should be placed in braces:

----
    for {set i 1} {$i<=10} {incr i} {...}      ** RIGHT **
----

This causes the substitution of 'i'
to be delayed; it will be re-done each time the expression is
evaluated, which is the desired result.

LISTS
-----
The third major way that strings are interpreted in Tcl is as lists.
A list is just a string with a list-like structure
consisting of fields separated by white space.  For example, the
string

----
    Al Sue Anne John
----

is a list with four elements or fields.
Lists have the same basic structure as command strings, except
that a newline character in a list is treated as a field separator
just like space or tab.  Conventions for braces and quotes
and backslashes are the same for lists as for commands.  For example,
the string

----
    a b\ c {d e {f g h}}
----

is a list with three elements:  +a+, +b c+, and +d e {f g h}+.

Whenever an element is extracted from a list, the same rules about
braces and quotes and backslashes are applied as for commands.  Thus in
the example above when the third element is extracted from the list,
the result is

----
    d e {f g h}
----

(when the field was extracted, all that happened was to strip off
the outermost layer of braces).  Command substitution and
variable substitution are never
made on a list (at least, not by the list-processing commands; the
list can always be passed to the Tcl interpreter for evaluation).

................................................................................
--------------

A new addition to Tcl 8.5 is the ability to expand a list into separate
arguments. Support for this feature is also available in Jim.

Consider the following attempt to exec a list:

----
    set cmd {ls -l}
    exec $cmd
----

This will attempt to exec a command named "ls -l", which will clearly not
work. Typically eval and concat are required to solve this problem, however
it can be solved much more easily with +\{*\}+.

----
    exec {*}$cmd
----

This will expand the following argument into individual elements and then evaluate
the resulting command.

Note that the official Tcl syntax is +\{*\}+, however +\{expand\}+ is retained
for backward compatibility with experimental versions of this feature.

................................................................................

1. Required Arguments (including Reference Arguments)
2. Optional Arguments
3. Variable Argument

The following example illustrates precedence. Assume a procedure declaration:

----
    proc p {{a A} args b {c C} d} {...}
----

This procedure requires at least two arguments, but can accept an unlimited number.
The following table shows how various numbers of arguments are assigned.
Values marked as +-+ are assigned the default value.

[width="40%",frame="topbot",options="header"]
|==============
................................................................................
~~~~~~~~~~
In addition to procedure arguments, Jim procedures may declare static variables.
These variables scoped to the procedure and initialised at procedure definition.
Either from the static variable definition, or from the enclosing scope.

Consider the following example:

----
    . set a 1
    . proc a {} {a {b 2}} {
        set c 1
        puts "$a $b $c"
        incr a
        incr b
        incr c
    }
    . a
    1 2 1
    . a
    2 3 1
----

The static variable +'a'+ has no initialiser, so it is initialised from
the enclosing scope with the value 1. (Note that it is an error if there
is no variable with the same name in the enclosing scope). However +'b'+
has an initialiser, so it is initialised to 2.

Unlike a local variable, the value of a static variable is retained across
invocations of the procedure.

See the `proc` command for information on how to define procedures
and what happens when they are invoked. See also <<_namespaces,NAMESPACES>>.

VARIABLES - SCALARS AND ARRAYS
------------------------------
Tcl allows the definition of variables and the use of their values
either through '$'-style variable substitution, the `set`
command, or a few other mechanisms.

................................................................................
can have any number of elements, each with a name (called
its 'index') and a value.

Array indexes may be arbitrary strings; they need not be numeric.
Parentheses are used refer to array elements in Tcl commands.
For example, the command

----
    set x(first) 44
----

will modify the element of 'x' whose index is 'first'
so that its new value is '44'.

Two-dimensional arrays can be simulated in Tcl by using indexes
that contain multiple concatenated values.
For example, the commands

----
    set a(2,3) 1
    set a(3,6) 2
----

set the elements of 'a' whose indexes are '2,3' and '3,6'.

In general, array elements may be used anywhere in Tcl that scalar
variables may be used.

If an array is defined with a particular name, then there may
................................................................................
within a procedure normally refer to local variables associated with that
invocation of the procedure.  Local variables are deleted whenever
a procedure exits.  Either `global` command may be used to request
that a name refer to a global variable for the duration of the current
procedure (this is somewhat analogous to 'extern' in C), or the variable
may be explicitly scoped with the +::+ prefix. For example

----
    . set a 1
    . set b 2
    . proc p {} {
        set c 3
        global a

        puts "$a $::b $c"
    }
    . p
----

will output:

    1 2 3

ARRAYS AS LISTS IN JIM
----------------------
Unlike Tcl, Jim can automatically convert between a list (with an even
number of elements) and an array value. This is similar to the way Tcl
can convert between a string and a list.

For example:

----
  set a {1 one 2 two}
  puts $a(2)
----

will output:

----
  two
----

Thus `array set` is equivalent to `set` when the variable does not
exist or is empty.

The reverse is also true where an array will be converted into
a list.

----
  set a(1) one; set a(2) two
  puts $a
----

will output:

----
  1 one 2 two
----

DICTIONARY VALUES
-----------------
Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
of this command. Dictionaries provide efficient access to key-value
pairs, just like arrays, but dictionaries are pure values. This
means that you can pass them to a procedure just as a list or a
................................................................................
banana" are equivalent dictionaries (with different string
representations).

Note that in Jim, arrays are implemented as dictionaries.
Thus automatic conversion between lists and dictionaries applies
as it does for arrays.

----
  . dict set a 1 one
  1 one
  . dict set a 2 two
  1 one 2 two
  . puts $a
  1 one 2 two
  . puts $a(2)
  two
  . dict set a 3 T three
  1 one 2 two 3 {T three}
----

See the `dict` command for more details.

NAMESPACES
----------
Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
including a number of 3rd party components. While there is less need for namespaces
................................................................................

References
~~~~~~~~~~
A reference can be thought of as holding a value with one level of indirection,
where the value may be garbage collected when unreferenced.
Consider the following example:

----
    . set r [ref "One String" test]
    <reference.<test___>.00000000000000000000>
    . getref $r
    One String
----

The operation `ref` creates a references to the value specified by the
first argument. (The second argument is a "type" used for documentation purposes).

The operation `getref` is the dereferencing operation which retrieves the value
stored in the reference.

----
    . setref $r "New String"
    New String
    . getref $r
    New String
----

The operation `setref` replaces the value stored by the reference. If the old value
is no longer accessible by any reference, it will eventually be automatically be garbage
collected.

Garbage Collection
~~~~~~~~~~~~~~~~~~
................................................................................
With the introduction of references, it is possible to create values whose lifetime
transcend their scope. To support this, case, the Jim system will periodically identify
and discard objects which are no longer accessible by any reference.

The `collect` command may be used to force garbage collection.  Consider a reference created
with a finalizer:

----
    . proc f {ref value} { puts "Finaliser called for $ref,$value" }
    . set r [ref "One String" test f]
    <reference.<test___>.00000000000
    . collect
    0
    . set r ""
    . collect
    Finaliser called for <reference.<test___>.00000000000,One String
    1
----

Note that once the reference, 'r', was modified so that it no longer
contained a reference to the value, the garbage collector discarded
the value (after calling the finalizer).

The finalizer for a reference may be examined or changed with the `finalize` command

----
    . finalize $r
    f
    . finalize $r newf
    newf
----

Lambda Function
~~~~~~~~~~~~~~~
Jim provides a garbage collected `lambda` function. This is a procedure
which is able to create an anonymous procedure.  Consider:

----
    . set f [lambda {a} {{x 0}} { incr x $a }]
    . $f 1
    1
    . $f 2
    3
    . set f ""
----

This create an anonymous procedure (with the name stored in 'f'), with a static variable
which is incremented by the supplied value and the result returned.

Once the procedure name is no longer accessible, it will automatically be deleted
when the garbage collector runs.

The procedure may also be delete immediately by renaming it "". e.g.

----
    . rename $f ""
----

UTF-8 AND UNICODE
-----------------
If Jim is built with UTF-8 support enabled (configure --enable-utf),
then most string-related commands become UTF-8 aware.  These include,
but are not limited to, `string match`, `split`, `glob`, `scan` and
`format`.
................................................................................
Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +'U+1FFFFF'.

String Matching
~~~~~~~~~~~~~~~
Commands such as `string match`, `lsearch -glob`, `array names` and others use string
pattern matching rules. These commands support UTF-8. For example:

----
  string match a\[\ua0-\ubf\]b "a\u00a3b"
----

format and scan
~~~~~~~~~~~~~~~
+format %c+ allows a unicode codepoint to be be encoded. For example, the following will return
a string with two bytes and one character. The same as +{backslash}ub5+

----
  format %c 0xb5
----

`format` respects widths as character widths, not byte widths. For example, the following will
return a string with three characters, not three bytes.

----
  format %.3s \ub5\ub6\ub7\ub8
----

Similarly, +scan ... %c+ allows a UTF-8 to be decoded to a unicode codepoint. The following will set
+'a'+ to 181 (0xb5) and +'b'+ to 65 (0x41).

----
  scan \u00b5A %c%c a b
----

`scan %s` will also accept a character class, including unicode ranges.

String Classes
~~~~~~~~~~~~~~
`string is` has *not* been extended to classify UTF-8 characters. Therefore, the following
will return 0, even though the string may be considered to be alphabetic.

----
  string is alpha \ub5Test
----

This does not affect the string classes 'ascii', 'control', 'digit', 'double', 'integer' or 'xdigit'.

Case Mapping and Conversion
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jim provides a simplified unicode case mapping. This means that case conversion
and comparison will not increase or decrease the number of characters in a string.
................................................................................
Some UTF-8 character sequences are invalid, such as those beginning with '0xff',
those which represent character sequences longer than 3 bytes (greater than U+FFFF),
and those which end prematurely, such as a lone '0xc2'.

In these situations, the offending bytes are treated as single characters. For example,
the following returns 2.

----
  string bytelength \xff\xff
----

Regular Expressions
~~~~~~~~~~~~~~~~~~~
If UTF-8 support is enabled, the built-in regular expression engine will be
selected which supports UTF-8 strings and patterns.

See <<_regular_expressions,REGULAR EXPRESSIONS>>

BUILT-IN COMMANDS
-----------------
The Tcl library provides the following built-in commands, which will
be available in any application using Tcl.  In addition to these
built-in commands, there may be additional commands defined by each
application, plus commands defined as Tcl procedures.
................................................................................
alias
~~~~~
+*alias* 'name args\...'+

Creates a single word alias (command) for one or more words. For example,
the following creates an alias for the command `info exists`.

----
    alias e info exists
    if {[e var]} {
      ...
    }
----

`alias` returns +'name'+, allowing it to be used with `local`.

See also `proc`, `curry`, `lambda`, `local`, `info alias`, `exists -alias`

append
~~~~~~
................................................................................
for the return code +JIM_ERR+, the value of the key +-errorinfo+
will contain the current stack trace (the same result as `info stacktrace`),
the value of the key +-errorcode+ will contain the
same value as the global variable $::errorCode, and the value of
the key +-level+ will be the current return level (see `return -level`).
This can be useful to rethrow an error:

----
    if {[catch {...} msg opts]} {
        ...maybe do something with the error...
        incr opts(-level)
        return {*}$opts $msg
    }
----

Normally `catch` will +'not'+ catch any of the codes +JIM_EXIT+, +JIM_EVAL+ or +JIM_SIGNAL+.
The set of codes which will be caught may be modified by specifying the one more codes before
+'command'+.

e.g. To catch +JIM_EXIT+ but not +JIM_BREAK+ or +JIM_CONTINUE+

----
    catch -exit -nobreak -nocontinue -- { ... }
----

The use of +--+ is optional. It signifies that no more return code options follow.

Note that if a signal marked as `signal handle` is caught with `catch -signal`, the return value
(stored in +'resultVarName'+) is name of the signal caught.

cd
................................................................................
collect
~~~~~~~
+*collect*+

Normally reference garbage collection is automatically performed periodically.
However it may be run immediately with the `collect` command.

See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.

concat
~~~~~~
+*concat* 'arg ?arg \...?'+

This command treats each argument as a list and concatenates them
into a single list.  It permits any number of arguments.  For example,
the command

----
    concat a b {c d e} {f {g h}}
----

will return

----
    a b c d e f {g h}
----

as its result.

continue
~~~~~~~~
+*continue*+

................................................................................
+*alias* 'args\...'+

Similar to `alias` except it creates an anonymous procedure (lambda) instead of
a named procedure.

the following creates a local, unnamed alias for the command `info exists`.

----
    set e [local curry info exists]
    if {[$e var]} {
      ...
    }
----

`curry` returns the name of the procedure.

See also `proc`, `alias`, `lambda`, `local`.

dict
~~~~
................................................................................
it is used to initialize the stacktrace.

This feature is most useful in conjunction with the `catch` command:
if a caught error cannot be handled successfully, +'stacktrace'+ can be used
to return a stack trace reflecting the original point of occurrence
of the error:

----
    catch {...} errMsg
    ...
    error $errMsg [info stacktrace]
----

See also `errorInfo`, `info stacktrace`, `catch` and `return`

errorInfo
~~~~~~~~~
+*errorInfo* 'error ?stacktrace?'+

Returns a human-readable representation of the given error message and stack trace.
Typical usage is:

----
    if {[catch {...} error]} {
        puts stderr [errorInfo $error [info stacktrace]]
        exit 1
    }
----

See also `error`.

eval
~~~~
+*eval* 'arg ?arg\...?'+

................................................................................
Note that exit can be caught with `catch`.

expr
~~~~
+*expr* 'arg'+

Calls the expression processor to evaluate +'arg'+, and returns
the result as a string.  See the section <<_expressions,EXPRESSIONS>> above.

Note that Jim supports a shorthand syntax for `expr` as +$(\...)+
The following two are identical.

----
  set x [expr {3 * 2 + 1}]
  set x $(3 * 2 + 1)
----

file
~~~~
+*file* 'option name ?arg\...?'+

Operate on a file or a file name.  +'name'+ is the name of a file.

................................................................................
    fashion as seconds from a fixed starting time (often January 1, 1970).
    If the file doesn't exist or its modified time cannot be queried then an
    error is generated. If +'time'+ is given, sets the modification time
    of the file to the given value.

+*file mtimeus* 'name ?time_us?'+::
    As for `file mtime` except the time value is in microseconds
    since the epoch (see also `clock microseconds`).
    Note that some platforms and some filesystems don't support high
    resolution timestamps for files.

+*file normalize* 'name'+::
    Return the normalized path of +'name'+. See 'realpath(3)'.

+*file owned* 'name'+::
    Return '1' if file +'name'+ is owned by the current user,
    '0' otherwise.
................................................................................
+*file writable* 'name'+::
    Return '1' if file +'name'+ is writable by
    the current user, '0' otherwise.

The `file` commands that return 0/1 results are often used in
conditional or looping commands, for example:

----
    if {![file exists foo]} {
        error {bad file name}
    } else {
        ...
    }
----

finalize
~~~~~~~~
+*finalize* 'reference ?command?'+

If +'command'+ is omitted, returns the finalizer command for the given reference.

Otherwise, sets a new finalizer command for the given reference. +'command'+ may be
the empty string to remove the current finalizer.

The reference must be a valid reference create with the `ref`
command.

See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.

flush
~~~~~
+*flush* 'fileId'+

+'fileId' *flush*+

................................................................................
getref
~~~~~~
+*getref* 'reference'+

Returns the string associated with +'reference'+. The reference must
be a valid reference create with the `ref` command.

See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.

gets
~~~~
+*gets* 'fileId ?varName?'+

+'fileId' *gets* '?varName?'+

................................................................................
~~~~~~
+*lambda* 'args ?statics? body'+

The `lambda` command is identical to `proc`, except rather than
creating a named procedure, it creates an anonymous procedure and returns
the name of the procedure.

See `proc` and <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.

lappend
~~~~~~~
+*lappend* 'varName value ?value value \...?'+

Treat the variable given by +'varName'+ as a list and append each of
the +'value'+ arguments to that list as a separate element, with spaces
................................................................................
If +'varName'+ doesn't exist, it is created as a list with elements given
by the +'value'+ arguments. `lappend` is similar to `append` except that
each +'value'+ is appended as a list element rather than raw text.

This command provides a relatively efficient way to build up large lists.
For example,

----
    lappend a $b
----

is much more efficient than

----
    set a [concat $a [list $b]]
----

when +$a+ is long.

lassign
~~~~~~~
+*lassign* 'list varName ?varName \...?'+

This command treats the value +'list'+ as a list and assigns successive elements from that list to
the variables given by the +'varName'+ arguments in order. If there are more variable names than
list elements, the remaining variables are set to the empty string. If there are more list elements
than variables, a list of unassigned elements is returned.

----
    . lassign {1 2 3} a b; puts a=$a,b=$b
    3
    a=1,b=2
----

local
~~~~~
+*local* 'cmd ?arg\...?'+

First, `local` evaluates +'cmd'+ with the given arguments. The return value must
be the name of an existing command, which is marked as having local scope.
................................................................................
the existing command will be kept rather than deleted, and may be called
via `upcall`. The previous command will be restored when the current
procedure exits. See `upcall` for more details.

In this example, a local procedure is created. Note that the procedure
continues to have global scope while it is active.

----
    proc outer {} {
      # proc ... returns "inner" which is marked local
      local proc inner {} {
        # will be deleted when 'outer' exits
      }

      inner
      ...
    }
----

In this example, the lambda is deleted at the end of the procedure rather
than waiting until garbage collection.

----
    proc outer {} {
      set x [lambda inner {args} {
        # will be deleted when 'outer' exits
      }]
      # Use 'function' here which simply returns $x
      local function $x

      $x ...
      ...
    }
----

loop
~~~~
+*loop* 'var first limit ?incr? body'+

Similar to `for` except simpler and possibly more efficient.
With a positive increment, equivalent to:

----
    for {set var $first} {$var < $limit} {incr var $incr} $body
----

If +'incr'+ is not specified, 1 is used.
Note that setting the loop variable inside the loop does not
affect the loop count.

lindex
~~~~~~
+*lindex* 'list ?index ...?'+

Treats +'list'+ as a Tcl list and returns element +'index'+ from it
(0 refers to the first element of the list).
See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'index'+.

In extracting the element, +'lindex'+ observes the same rules concerning
braces and quotes and backslashes as the Tcl command interpreter; however,
variable substitution and command substitution do not occur.

If no index values are given, simply returns +'list'+

................................................................................
of +'list'+. Each +'element'+ argument will become
a separate element of the new list. If +'index'+ is less than
or equal to zero, then the new elements are inserted at the
beginning of the list. If +'index'+ is greater than or equal
to the number of elements in the list, then the new elements are
appended to the list.

See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'index'+.

list
~~~~

+*list* 'arg ?arg \...?'+

This command returns a list comprised of all the arguments, +'arg'+. Braces
................................................................................
so that `eval` may be used to execute the resulting list, with
+'arg1'+ comprising the command's name and the other args comprising
its arguments. `list` produces slightly different results than
`concat`:  `concat` removes one level of grouping before forming
the list, while `list` works directly from the original arguments.
For example, the command

----
    list a b {c d e} {f {g h}}
----

will return

----
    a b {c d e} {f {g h}}
----

while `concat` with the same arguments will return

----
    a b c d e f {g h}
----

llength
~~~~~~~
+*llength* 'list'+

Treats +'list'+ as a list and returns a decimal string giving
the number of elements in it.
................................................................................

The `lset` command accepts a parameter, +'varName'+, which it interprets
as the name of a variable containing a Tcl list. It also accepts
zero or more indices into the list. Finally, it accepts a new value
for an element of varName. If no indices are presented, the command
takes the form:

----
    lset varName newValue
----

In this case, newValue replaces the old value of the variable
varName.

When presented with a single index, the `lset` command
treats the content of the varName variable as a Tcl list. It addresses
the index'th element in it (0 refers to the first element of the
................................................................................
designated element is replaced with newValue. This new list is
stored in the variable varName, and is also the return value from
the `lset` command.

If index is negative or greater than or equal to the number of
elements in $varName, then an error occurs.

See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'index'+.

If additional index arguments are supplied, then each argument is
used in turn to address an element within a sublist designated by
the previous indexing operation, allowing the script to alter
elements in sublists. The command,

----
    lset a 1 2 newValue
----

replaces element 2 of sublist 1 with +'newValue'+.

The integer appearing in each index argument must be greater than
or equal to zero. The integer appearing in each index argument must
be strictly less than the length of the corresponding list. In other
words, the `lset` command cannot change the size of a list. If an
................................................................................

+*lmap* 'varList list ?varList2 list2 \...? body'+

`lmap` is a "collecting" `foreach` which returns a list of its results.

For example:

----
    . lmap i {1 2 3 4 5} {expr $i*$i}
    1 4 9 16 25
    . lmap a {1 2 3} b {A B C} {list $a $b}
    {1 A} {2 B} {3 C}
----

If the body invokes `continue`, no value is added for this iteration.
If the body invokes `break`, the loop ends and no more values are added.

load
~~~~
+*load* 'filename'+
................................................................................
lrange
~~~~~~
+*lrange* 'list first last'+

+'list'+ must be a valid Tcl list. This command will return a new
list consisting of elements +'first'+ through +'last'+, inclusive.

See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'first'+ and +'last'+.

If +'last'+ is greater than or equal to the number of elements
in the list, then it is treated as if it were +end+.

If +'first'+ is greater than +'last'+ then an empty string
is returned.

................................................................................
If +'first'+ is less than zero then it refers to the first
element of +'list'+;  the element indicated by +'first'+
must exist in the list.

+'last'+ gives the index in +'list'+ of the last element
to be replaced;  it must be greater than or equal to +'first'+.

See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'first'+ and +'last'+.

The +'element'+ arguments specify zero or more new arguments to
be added to the list in place of those that were deleted.

Each +'element'+ argument will become a separate element of
the list.

................................................................................
lrepeat
~~~~~~~~
+*lrepeat* 'number element1 ?element2 \...?'+

Build a list by repeating elements +'number'+ times (which must be
a positive integer).

----
    . lrepeat 3 a b
    a b a b a b
----

lreverse
~~~~~~~~
+*lreverse* 'list'+

Returns the list in reverse order.

----
    . lreverse {1 2 3}
    3 2 1
----

lsearch
~~~~~~~
+*lsearch* '?options? list pattern'+

This command searches the elements +'list'+ to see if one of them matches +'pattern'+. If so, the
command returns the index of the first matching element (unless the options +-all+, +-inline+ or +-bool+ are
................................................................................
defer
~~~~~
+*defer* 'script'+

This command is a simple helper command to add a script to the '+$jim::defer+' variable
that will run when the current proc or interpreter exits. For example:

----
    . proc a {} { defer {puts "Leaving a"}; puts "Exit" }
    . a
    Exit
    Leaving a
----

If the '+$jim::defer+' variable exists, it is treated as a list of scripts to run
when the proc or interpreter exits.

open
~~~~
+*open* 'fileName ?access?'+
................................................................................

The `proc` command creates a new Tcl command procedure, +'name'+.
When the new command is invoked, the contents of +'body'+ will be executed.
Tcl interpreter. +'args'+ specifies the formal arguments to the procedure.
If specified, +'statics'+, declares static variables which are bound to the
procedure.

See <<_procedures,PROCEDURES> for detailed information about Tcl procedures.

The `proc` command returns +'name'+ (which is useful with `local`).

When a procedure is invoked, the procedure's return value is the
value specified in a `return` command.  If the procedure doesn't
execute an explicit `return`, then its return value is the value
of the last command executed in the procedure's body.
................................................................................
Output to files is buffered internally by Tcl; the `flush`
command may be used to force buffered characters to be output.

pipe
~~~~
Creates a pair of `aio` channels and returns the handles as a list: +{read write}+

----
    lassign [pipe] r w

    # Must close $w after exec
    exec ps >@$w &
    $w close

    $r readable ...
----

pwd
~~~
+*pwd*+

Returns the path name of the current working directory.

................................................................................
range
~~~~
+*range* '?start? end ?step?'+

Returns a list of integers starting at +'start'+ (defaults to 0)
and ranging up to but not including +'end'+ in steps of +'step'+ defaults to 1).

----
    . range 5
    0 1 2 3 4
    . range 2 5
    2 3 4
    . range 2 10 4
    2 6
    . range 7 4 -2
    7 5
----

read
~~~~
+*read* ?*-nonewline*? 'fileId'+

+'fileId' *read* ?*-nonewline*?+

+*read* 'fileId numBytes'+

+'fileId' *read* 'numBytes'+


In the first form, all of the remaining bytes are read from the file
given by +'fileId'+; they are returned as the result of the command.
If the +-nonewline+ switch is specified then the last
character of the file is discarded if it is a newline.

In the second form, the extra argument specifies how many bytes to read;
................................................................................
regexp
~~~~~~
+*regexp ?-nocase? ?-line? ?-indices? ?-start* 'offset'? *?-all? ?-inline? ?--?* 'exp string ?matchVar? ?subMatchVar subMatchVar \...?'+

Determines whether the regular expression +'exp'+ matches part or
all of +'string'+ and returns 1 if it does, 0 if it doesn't.

See <<_regular_expressions,REGULAR EXPRESSIONS>> above for complete information on the
syntax of +'exp'+ and how it is matched against +'string'+.

If additional arguments are specified after +'string'+ then they
are treated as the names of variables to use to return
information about which part(s) of +'string'+ matched +'exp'+.
+'matchVar'+ will be set to the range of +'string'+ that
matched all of +'exp'+. The first +'subMatchVar'+ will contain
................................................................................
Create a new reference containing +'string'+ of type +'tag'+.
If +'finalizer'+ is specified, it is a command which will be invoked
when the a garbage collection cycle runs and this reference is
no longer accessible.

The finalizer is invoked as:

----
    finalizer reference string
----


See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.

rename
~~~~~~
+*rename* 'oldName newName'+

Rename the command that used to be called +'oldName'+ so that it
is now called +'newName'+.  If +'newName'+ is an empty string
................................................................................
~~~~~~
+*setref* 'reference string'+

Store a new string in +'reference'+, replacing the existing string.
The reference must be a valid reference create with the `ref`
command.

See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.

signal
~~~~~~
Command for signal handling.

See `kill` for the different forms which may be used to specify signals.

................................................................................
    If +-clear+ is specified, any signals returned are removed and will not be
    returned by subsequent calls to `signal check` unless delivered again.

+*signal throw* ?'signal'?+::
    Raises the given signal, which defaults to +SIGINT+ if not specified.
    The behaviour is identical to:

----
    kill signal [pid]
----

Note that `signal handle` and `signal ignore` represent two forms of signal
handling. `signal handle` is used in conjunction with `catch -signal` or `try -signal`
to immediately abort execution when the signal is delivered. Alternatively, `signal ignore`
is used in conjunction with `signal check` to handle signal synchronously. Consider the
two examples below.

Prevent a processing from taking too long

----
    signal handle SIGALRM
    alarm 20
    try -signal {
        .. possibly long running process ..
        alarm 0
    } on signal {sig} {
        puts stderr "Process took too long"
    }
----

Handle SIGHUP to reconfigure:

----
    signal ignore SIGHUP
    while {1} {
        ... handle configuration/reconfiguration ...
        while {[signal check -clear SIGHUP] eq ""} {
            ... do processing ..
        }
        # Received SIGHUP, so reconfigure
    }
----

Note: signal handling is currently not supported in child interpreters.
In these interpreters, the signal command does not exist.

sleep
~~~~~
+*sleep* 'seconds'+
................................................................................

If +'splitChars'+ is an empty string then each character of
+'string'+ becomes a separate element of the result list.

+'splitChars'+ defaults to the standard white-space characters.
For example,

----
    split "comp.unix.misc" .
----

returns +'"comp unix misc"'+ and

----
    split "Hello world" {}
----

returns +'"H e l l o { } w o r l d"'+.

stackdump
~~~~~~~~~

+*stackdump* 'stacktrace'+
................................................................................
Perform one of several string operations, depending on +'option'+.
The legal options (which may be abbreviated) are:

+*string bytelength* 'string'+::
    Returns the length of the string in bytes. This will return
    the same value as `string length` if UTF-8 support is not enabled,
    or if the string is composed entirely of ASCII characters.
    See <<_utf_8_and_unicode,UTF-8 AND UNICODE>>.

+*string byterange* 'string first last'+::
    Like `string range` except works on bytes rather than characters.
    These commands are identical if UTF-8 support is not enabled.

+*string cat* '?string1 string2 \...?'+::
    Concatenates the given strings into a single string.
................................................................................
+*string first* 'string1 string2 ?firstIndex?'+::
    Search +'string2'+ for a sequence of characters that exactly match
    the characters in +'string1'+.  If found, return the index of the
    first character in the first such match within +'string2'+.  If not
    found, return -1. If +'firstIndex'+ is specified, matching will start
    from +'firstIndex'+ of +'string1'+.
 ::
    See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'firstIndex'+.

+*string index* 'string charIndex'+::
    Returns the +'charIndex'+'th character of the +'string'+
    argument.  A +'charIndex'+ of 0 corresponds to the first
    character of the string.
    If +'charIndex'+ is less than 0 or greater than
    or equal to the length of the string then an empty string is
    returned.
 ::
    See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'charIndex'+.

+*string is* 'class' ?*-strict*? 'string'+::
    Returns 1 if +'string'+ is a valid member of the specified character
    class, otherwise returns 0. If +-strict+ is specified, then an
    empty string returns 0, otherwise an empty string will return 1
    on any class. The following character classes are recognized
    (the class name can be abbreviated):
................................................................................
  +lower+;;  Any lower case alphabet character.
  +print+;;  Any printing character, including space.
  +punct+;;  Any punctuation character.
  +space+;;  Any space character.
  +upper+;;  Any upper case alphabet character.
  +xdigit+;; Any hexadecimal digit character ([0-9A-Fa-f]).
 ::
    Note that string classification does +'not'+ respect UTF-8. See <<_utf_8_and_unicode,UTF-8 AND UNICODE>>.
 ::
    Note that only +'lowercase'+ boolean values are recognized (Tcl accepts any case).

+*string last* 'string1 string2 ?lastIndex?'+::
    Search +'string2'+ for a sequence of characters that exactly match
    the characters in +'string1'+.  If found, return the index of the
    first character in the last such match within +'string2'+.  If there
    is no match, then return -1. If +'lastIndex'+ is specified, only characters
    up to +'lastIndex'+ of +'string2'+ will be considered in the match.
 ::
    See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'lastIndex'+.

+*string length* 'string'+::
    Returns a decimal string giving the number of characters in +'string'+.
    If UTF-8 support is enabled, this may be different than the number of bytes.
    See <<_utf_8_and_unicode,UTF-8 AND UNICODE>>.

+*string map ?-nocase?* 'mapping string'+::
    Replaces substrings in +'string'+ based on the key-value pairs in
    +'mapping'+, which is a list of +key value key value \...+ as in the form
    returned by `array get`. Each instance of a key in the string will be
    replaced with its corresponding value.  If +-nocase+ is specified, then
    matching is done without regard to case differences. Both key and value may
    be multiple characters.  Replacement is done in an ordered manner, so the
    key appearing first in the list will be checked first, and so on. +'string'+ is
    only iterated over once, so earlier key replacements will have no affect for
    later key matches. For example,

----
      string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc
----

 ::
    will return the string +01321221+.
 ::
    Note that if an earlier key is a prefix of a later one, it will completely mask the later
    one.  So if the previous example is reordered like this,

----
      string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc
----

 ::
    it will return the string +02c322c222c+.

+*string match ?-nocase?* 'pattern string'+::
    See if +'pattern'+ matches +'string'+; return 1 if it does, 0
    if it doesn't.  Matching is done in a fashion similar to that
................................................................................

+*string range* 'string first last'+::
    Returns a range of consecutive characters from +'string'+, starting
    with the character whose index is +'first'+ and ending with the
    character whose index is +'last'+.  An index of 0 refers to the
    first character of the string.
 ::
    See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'first'+ and +'last'+.
 ::
    If +'first'+ is less than zero then it is treated as if it were zero, and
    if +'last'+ is greater than or equal to the length of the string then
    it is treated as if it were +end+.  If +'first'+ is greater than
    +'last'+ then an empty string is returned.

+*string repeat* 'string count'+::
................................................................................
is performed: open and close brackets are treated as ordinary
characters with no special interpretation.

*Note*: when it performs its substitutions, subst does not give any
special treatment to double quotes or curly braces. For example,
the following script returns +xyz \{44\}+, not +xyz \{$a\}+.

----
    set a 44
    subst {xyz {$a}}
----


switch
~~~~~~
+*switch* '?options? string pattern body ?pattern body \...?'+

+*switch* '?options? string {pattern body ?pattern body \...?}'+
................................................................................
pattern should also be used as the body for this pattern (if the
next pattern also has a body of +-+ then the body after that is
used, and so on). This feature makes it possible to share a single
body among several patterns.

Below are some examples of `switch` commands:

----
    switch abc a - b {format 1} abc {format 2} default {format 3}
----

will return 2,

----
    switch -regexp aaab {
           ^a.*b$ -
           b {format 1}
           a* {format 2}
           default {format 3}
    }
----

will return 1, and

----
    switch xyz {
           a -
           b {format 1}
           a* {format 2}
           default {format 3}
    }
----

will return 3.

tailcall
~~~~~~~~
+*tailcall* 'cmd ?arg\...?'+

The `tailcall` command provides an optimised way of invoking a command whilst replacing
the current call frame. This is similar to 'exec' in Bourne Shell.

The following are identical except the first immediately replaces the current call frame.

----
  tailcall a b c
----

----
  return [uplevel 1 [list a b c]]
----

`tailcall` is useful as a dispatch mechanism:

----
  proc a {cmd args} {
    tailcall sub_$cmd {*}$args
  }
  proc sub_cmd1 ...
  proc sub_cmd2 ...
----

tell
~~~~
+*tell* 'fileId'+

+'fileId' *tell*+

................................................................................
~~~~
+*time* 'command ?count?'+

This command will call the Tcl interpreter +'count'+
times to execute +'command'+ (or once if +'count'+ isn't
specified).  It will then return a string of the form

----
    503 microseconds per iteration
----

which indicates the average amount of time required per iteration,
in microseconds.

Time is measured in elapsed time, not CPU time.

try
................................................................................
or as integers.

If +'resultvar'+ and +'optsvar'+ are specified, they are set as for `catch` before evaluating
the matching handler.

For example:

----
    set f [open input]
    try -signal {
        process $f
    } on {continue break} {} {
        error "Unexpected break/continue"
    } on error {msg opts} {
        puts "Dealing with error"
        return {*}$opts $msg
    } on signal sig {
        puts "Got signal: $sig"
    } finally {
        $f close
    }
----

If break, continue or error are raised, they are dealt with by the matching
handler.

In any case, the file will be closed via the 'finally' clause.

See also `throw`, `catch`, `return`, `error`.
................................................................................

If +'level'+ is '3' or +#0+ then the command will be executed
at top-level (only global variables will be visible).
The `uplevel` command causes the invoking procedure to disappear
from the procedure calling stack while the command is being executed.
In the above example, suppose 'c' invokes the command

----
    uplevel 1 {set x 43; d}
----

where 'd' is another Tcl procedure.  The `set` command will
modify the variable 'x' in 'b's context, and 'd' will execute
at level 3, as if called from 'b'.  If it in turn executes
the command

----
    uplevel {set x 42}
----

then the `set` command will modify the same variable 'x' in 'b's
context:  the procedure 'c' does not appear to be on the call stack
when 'd' is executing.  The command `info level` may
be used to obtain the level of the current procedure.

`uplevel` makes it possible to implement new control
................................................................................
`upvar` returns an empty string.

The `upvar` command simplifies the implementation of call-by-name
procedure calling and also makes it easier to build new control constructs
as Tcl procedures.
For example, consider the following procedure:

----
    proc add2 name {
        upvar $name x
        set x [expr $x+2]
    }
----

'add2' is invoked with an argument giving the name of a variable,
and it adds two to the value of that variable.
Although 'add2' could have been implemented using `uplevel`
instead of `upvar`, `upvar` makes it simpler for 'add2'
to access the variable in the caller's procedure frame.

................................................................................

+*os.gethostname*+::
    Invokes 'gethostname(3)' and returns the result.

+*os.getids*+::
    Returns the various user/group ids for the current process.

----
    . os.getids
    uid 1000 euid 1000 gid 100 egid 100
----

+*os.uptime*+::
    Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.

ANSI I/O (aio) and EVENTLOOP API
--------------------------------
Jim provides an alternative object-based API for I/O.
................................................................................

This command creates a socket connected (client) or bound (server) to the given
address.

The returned value is channel and may generally be used with the various file I/O
commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.

----
    . set f [socket stream www.google.com:80]
    aio.sockstream1
    . $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
    . $f gets
    HTTP/1.0 302 Found
    . $f close
----

Server sockets, however support only 'accept', which is most useful in conjunction with
the EVENTLOOP API.

----
    set f [socket stream.server 80]
    $f readable {
        set client [$f accept]
        $client gets $buf
        ...
        $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
        $client close
    }
    vwait done
----

The address, +'addr'+, can be given in one of the following forms:

1. For IPv4 socket types, an IPv4 address such as 192.168.1.1
2. For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
3. A hostname

................................................................................
~~~~~~
The optional, pure-Tcl 'binary' extension provides the Tcl-compatible `binary scan` and `binary format`
commands based on the low-level `pack` and `unpack` commands.

See the Tcl documentation at: http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm

Note that 'binary format' with f/r/R specifiers (single-precision float) uses the value of Infinity
in case of overflow.

oo: class, super
~~~~~~~~~~~~~~~~
The optional, pure-Tcl 'oo' extension provides object-oriented (OO) support for Jim Tcl.

See the online documentation (http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/) for more details.

................................................................................
    or 0 otherwise.

+*tcl_platform*+::
    This variable is set by Jim as an array containing information
    about the platform upon which Jim was built. The following is an
    example of the contents of this array.

----
    tcl_platform(byteOrder)     = littleEndian
    tcl_platform(engine)        = Jim
    tcl_platform(os)            = Darwin
    tcl_platform(platform)      = unix
    tcl_platform(pointerSize)   = 8
    tcl_platform(threaded)      = 0
    tcl_platform(wordSize)      = 8
    tcl_platform(pathSeparator) = :
----

+*argv0*+::
    If jimsh is invoked to run a script, this variable contains the name
    of the script.

+*argv*+::
    If jimsh is invoked to run a script, this variable contains a list