Variable size/Set: Difference between revisions

(add C example)
Line 42:
 
In Perl, memory is readily and happily traded for expressiveness and ease of use.
 
=={{header|Tcl}}==
In Tcl, all values are (Unicode) strings. Their size is measured in characters, and the minimum size of a string is of course 0.
However, one can arrange, via write traces, that the value of a variable is reformatted to bigger size. Examples, from an interactive [[tclsh]] session:
<lang Tcl>
% proc format_trace {fmt _var el op} {upvar 1 $_var v; set v [format $fmt $v]}
 
% trace var foo w {format_trace %10s}
% puts "/[set foo bar]/"
/ bar/
 
% trace var grill w {format_trace %-10s}
% puts "/[set grill bar]/"
/bar /
%
</lang>
 
{{Omit From|E}}
{{Omit From|Tcl}}
Anonymous user