Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tutorial lesson 15 uses listName inconsistently with lappend/linsert/lreplace

Openf8bc8efdf547eb8ddd92218ee1f8d91d0e0b4937Created 10 years agoUpdated 10 years ago
Descriptionplain2016-08-23 22:32:46
The command signatures for lappend, linsert, and lreplace are presented in Lesson 15 of the tutorial ("Adding & Deleting members of a list") as follows.

lappend listName ?arg1 arg2 ... argn?
linsert listName index arg1 ?arg2 ... argn?
lreplace listName first last ?arg1 ... argn?

The latter should read like this instead.

linsert list index arg1 ?arg2 ... argn?
lreplace list first last ?arg1 ... argn?

According to the tutorial, the following interactive session should set `otherlist` to `{{one} {oneandahalf} {two} {three} {four}}`, return `two` from the corresponding `lindex` command, set `replacementlist` to {{one} {two} {tres} {cuatro}}`, and return `cuatro` from the corresponding `lindex` command.

    % set mylist [list one two three]
    one two three
    % lappend mylist four
    one two three four
    % lindex $mylist 3
    four
    % set otherlist [linsert mylist 1 oneandahalf]
    mylist oneandahalf
    % lindex $otherlist 2
    % set replacementlist [lreplace mylist 2 3 tres cuatro]
    mylist tres cuatro
    % lindex $replacementlist 3
    %
neirbowjplain2016-08-24 00:03:17
Edited title and description to cover `lreplace` too.
Log in (anonymous is fine) to add a comment.