{"id":6021,"date":"2022-12-20T18:57:51","date_gmt":"2022-12-20T21:57:51","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/lreplace-mann\/"},"modified":"2022-12-20T18:57:51","modified_gmt":"2022-12-20T21:57:51","slug":"lreplace-mann","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/lreplace-mann\/","title":{"rendered":"lreplace (mann)"},"content":{"rendered":"<h1 align=\"center\">lreplace<\/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\">lreplace \u2212 Replace elements in a list with new elements<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>lreplace<\/b> <i>list first last<\/i> ?<i>element element &#8230;<\/i>? ______________________________________________________________________________<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>lreplace<\/b> returns a new list formed by replacing zero or more elements of <i>list<\/i> with the <i>element<\/i> arguments. <i>first<\/i> and <i>last<\/i> are index values specifying the first and last elements of the range to replace. The index values <i>first<\/i> and <i>last<\/i> are interpreted the same as index values for the command <b>string index<\/b>, supporting simple index arithmetic and indices relative to the end of the list. 0 refers to the first element of the list, and <b>end<\/b> refers to the last element of the list.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If either <i>first<\/i> or <i>last<\/i> is less than zero, it is considered to refer to before the first element of the list. This allows <b>lreplace<\/b> to prepend elements to <i>list<\/i>. If either <i>first<\/i> or <i>last<\/i> indicates a position greater <big>\u2502<\/big> than the index of the last element of the list, it is treated as if it <big>\u2502<\/big> is an index one greater than the last element. This allows <b>lreplace<\/b> to <big>\u2502<\/big> append elements to <i>list<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>last<\/i> is less than <i>first<\/i>, then any specified elements will be inserted into the list before the element specified by <i>first<\/i> with no elements being deleted.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>element<\/i> arguments specify zero or more new elements to be added to the list in place of those that were deleted. Each <i>element<\/i> argument will become a separate element of the list. If no <i>element<\/i> arguments are specified, then the elements between <i>first<\/i> and <i>last<\/i> are simply deleted.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Replacing an element of a list with another:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">% <b>lreplace<\/b> {a b c d e} 1 1 foo <br \/> a foo c d e<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Replacing two elements of a list with three:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">% <b>lreplace<\/b> {a b c d e} 1 2 three more elements <br \/> a three more elements d e<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Deleting the last element from a list in a variable:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">% set var {a b c d e} <br \/> a b c d e <br \/> % set var [<b>lreplace<\/b> $var end end] <br \/> a b c d<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">A procedure to delete a given element from a list:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">proc lremove {listVariable value} { <br \/> upvar 1 $listVariable var <br \/> set idx [lsearch -exact $var $value] <br \/> set var [<b>lreplace<\/b> $var $idx $idx] <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Appending elements to the list; note that <b>end+2<\/b> will initially be <big>\u2502<\/big> treated as if it is <b>6<\/b> here, but both that and <b>12345<\/b> are greater than <big>\u2502<\/big> the index of the final item so they behave identically: <big>\u2502<\/big><\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">% set var {a b c d e} <big>\u2502<\/big> <br \/> a b c d e <big>\u2502<\/big> <br \/> % set var [<b>lreplace<\/b> $var 12345 end+2 f g h i] <big>\u2502<\/big> <br \/> a b c d e f g h i <big>\u2502<\/big><\/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), lset(n), lrange(n), lsort(n), string(n)<\/p>\n<h2>KEYWORDS <a name=\"KEYWORDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">element, list, replace<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  lreplace \u2212 Replace elements in a list with new elements <\/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":[2698,2635],"class_list":["post-6021","post","type-post","status-publish","format-standard","hentry","category-n-comandos-tcl-tk","category-sin-categoria","tag-lreplace","tag-mann"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6021","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=6021"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6021\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}