Created
December 25, 2011 16:37
-
-
Save anonymous/1519485 to your computer and use it in GitHub Desktop.
lists are passed as values in TCL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env tclsh | |
proc f {L} { | |
puts "f: before: L = $L" | |
lappend L 20 | |
puts "f: after: L = $L" | |
} | |
proc g {_L} { | |
upvar ${_L} L | |
puts "g: before: L = $L" | |
lappend L 30 | |
puts "g: after: L = $L" | |
} | |
set L {1 2 3} | |
puts "initial: L = $L" | |
lappend L 4 | |
puts "after lappend: L = $L" | |
f $L | |
puts "after calling f: L = $L" | |
g L | |
puts "after calling g: L = $L" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./list.tcl | |
initial: L = 1 2 3 | |
after lappend: L = 1 2 3 4 | |
f: before: L = 1 2 3 4 | |
f: after: L = 1 2 3 4 20 | |
after calling f: L = 1 2 3 4 | |
g: before: L = 1 2 3 4 | |
g: after: L = 1 2 3 4 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment