{"id":6087,"date":"2022-12-20T18:57:54","date_gmt":"2022-12-20T21:57:54","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/lset-mann\/"},"modified":"2022-12-20T18:57:54","modified_gmt":"2022-12-20T21:57:54","slug":"lset-mann","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/lset-mann\/","title":{"rendered":"lset (mann)"},"content":{"rendered":"<h1 align=\"center\">lset<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#KEYWORDS\">KEYWORDS<\/a> <\/p>\n<hr>\n<p>______________________________________________________________________________<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">lset \u2212 Change an element in a list<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>lset<\/b> <i>varName ?index &#8230;? newValue<\/i> ______________________________________________________________________________<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>lset<\/b> command accepts a parameter, <i>varName<\/i>, which it interprets as the name of a variable containing a Tcl list. It also accepts zero or more <i>indices<\/i> into the list. The indices may be presented either consecutively on the command line, or grouped in a Tcl list and presented as a single argument. Finally, it accepts a new value for an element of <i>varName<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If no indices are presented, the command takes the form:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>lset<\/b> varName newValue<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">or<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>lset<\/b> varName {} newValue<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In this case, <i>newValue<\/i> replaces the old value of the variable <i>varName<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When presented with a single index, the <b>lset<\/b> command treats the content of the <i>varName<\/i> variable as a Tcl list. It addresses the <i>index<\/i>\u2019th element in it (0 refers to the first element of the list). When interpreting the list, <b>lset<\/b> observes the same rules concerning braces and quotes and backslashes as the Tcl command interpreter; however, variable substitution and command substitution do not occur. The command constructs a new list in which the designated element is replaced with <i>newValue<\/i>. This new list is stored in the variable <i>varName<\/i>, and is also the return value from the <b>lset<\/b> command.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>index<\/i> is negative or greater than the number of elements in <i>$varName<\/i>, then an error occurs.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>index<\/i> is equal to the number of elements in <i>$varName<\/i>, then the given element is appended to the list.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The interpretation of each simple <i>index<\/i> value is the same as for the command <b>string index<\/b>, supporting simple index arithmetic and indices relative to the end of the list.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If additional <i>index<\/i> 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 (or append elements to sublists). The command,<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>lset<\/b> a 1 2 newValue<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">or<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>lset<\/b> a {1 2} newValue<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">replaces element 2 of sublist 1 with <i>newValue<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The integer appearing in each <i>index<\/i> argument must be greater than or equal to zero. The integer appearing in each <i>index<\/i> argument must be less than or equal to the length of the corresponding list. In other words, the <b>lset<\/b> command can change the size of a list only by appending an element (setting the one after the current end). If an index is outside the permitted range, an error is reported.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">In each of these examples, the initial value of <i>x<\/i> is:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">set x [list [list a b c] [list d e f] [list g h i]] <i><br \/> \u2192 {a b c} {d e f} {g h i}<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The indicated return value also becomes the new value of <i>x<\/i> (except in the last case, which is an error which leaves the value of <i>x<\/i> unchanged.)<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>lset<\/b> x {j k l} <i><br \/> \u2192 j k l<\/i> <b><br \/> lset<\/b> x {} {j k l} <i><br \/> \u2192 j k l<\/i> <b><br \/> lset<\/b> x 0 j <i><br \/> \u2192 j {d e f} {g h i}<\/i> <b><br \/> lset<\/b> x 2 j <i><br \/> \u2192 {a b c} {d e f} j<\/i> <b><br \/> lset<\/b> x end j <i><br \/> \u2192 {a b c} {d e f} j<\/i> <b><br \/> lset<\/b> x end-1 j <i><br \/> \u2192 {a b c} j {g h i}<\/i> <b><br \/> lset<\/b> x 2 1 j <i><br \/> \u2192 {a b c} {d e f} {g j i}<\/i> <b><br \/> lset<\/b> x {2 1} j <i><br \/> \u2192 {a b c} {d e f} {g j i}<\/i> <b><br \/> lset<\/b> x {2 3} j <i><br \/> \u2192 list index out of range<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In the following examples, the initial value of <i>x<\/i> is:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">set x [list [list [list a b] [list c d]]  <br \/> [list [list e f] [list g h]]] <i><br \/> \u2192 {{a b} {c d}} {{e f} {g h}}<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The indicated return value also becomes the new value of <i>x<\/i>.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>lset<\/b> x 1 1 0 j <i><br \/> \u2192 {{a b} {c d}} {{e f} {j h}}<\/i> <b><br \/> lset<\/b> x {1 1 0} j <i><br \/> \u2192 {{a b} {c d}} {{e f} {j h}}<\/i><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n), lsort(n), lrange(n), lreplace(n), string(n)<\/p>\n<h2>KEYWORDS <a name=\"KEYWORDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">element, index, list, replace, set<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  lset \u2212 Change an element in a list <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3783,1],"tags":[2756,2635],"class_list":["post-6087","post","type-post","status-publish","format-standard","hentry","category-n-comandos-tcl-tk","category-sin-categoria","tag-lset","tag-mann"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6087"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6087\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}