Call Procedure Fortran like Example
This page is under development. Comments are
welcome, but please load any comments
in the comments section
at the middle of the page. Thanks,[gold]
[gold] Here is an eTCL script on
Call Procedure Fortran like.
A call statement has some advantages in both
fortran and TCL languages.
In some of the fortran
language versions, the call statement was used
to call subroutines. For example,
a call exit could
be used to halt the program execution.
For TCL, a call procedure can
be developed that does not have to use brackets.
The call statement is used
to organize programs
into a list of subroutines
and to exit the program.
Exiting a program was not
a trivial function in the
early days of programming.
So a statement like
"call exit" seemed pretty swank.
Below, a generic TCL program
passes control through various
dummy procedures.
Some "puts bye " and math statements
are used to show
control is passing through the procedures.
pseudocode:
console show
proc call {args} {uplevel catch [list $args]}
call initilize # list variables
call subroutine1
call subroutine2
call subroutine3
call subroutine4
call exit # stop statement
proc initilize
return
proc subroutine1
return
proc subroutine2
return
proc subroutine3
return
proc subroutine4
call math sin(.5)
return
... pseudocode:
***Screenshots Section***
----
'''Comments Section'''
Please place any comments here, Thanks.
References:
Radical Language Modification
http://wiki.tcl.tk/495
http:http://wiki.tcl.tk/9546
Functional Programming
expr shorthand for Tcl9
Steps towards functional programming
*************
*FIRST VERSION
#start of deck
#start of deck
#start of deck
#start of deck
# call procedure like fortran example
# written on Windows XP on eTCL
# working under TCL version 8.5.6 and eTCL 1.0.1
# gold on TCL WIKI , 4oct2010
console show
proc call {args} {uplevel catch [list $args]}
proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] }
proc initilize {aa} {
return }
proc subroutine1 {aa} {
return }
proc subroutine2 {aa} {
return }
proc subroutine3 {aa} {
return }
proc subroutine4 {aa} {
call math sin (.5)
if { 1 == 1 } { puts "bye" }
if { 1 == 2 } { call exit }
return }
call initilize # list variables
call subroutine1 1
call subroutine2 2
call subroutine3 3
call subroutine4 4
call math sin (.5)
if { 1 == 1 } { puts "bye bye" }
#end of deck
#end of deck
#end of deck
#end of deck
#end of deck
#end of deck
% console output
0.479425538604203
bye
0.479425538604203
bye bye
Appendix Code
appendix TCL programs and scripts
Example2, code scraps
console show
proc pie {} {expr acos(-1)}
proc writer {args } { puts $args }
proc call {args} {uplevel catch [list $args]}
call writer "jack" "&" "jill"
call writer jack & jill went up the hill with [pie]
% console output
jack & jill
jack & jill went up the hill with 3.141592653589793
Example3, Code scraps
console show
proc pie {} {expr acos(-1)}
proc writer {args } { puts $args }
proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] }
proc mathx { args } { set tcl_precision 17; return [ expr [ expr { $args } ] ] }
proc call {args} {uplevel catch [list $args]}
call math 5 + 5
call math 5 + 5
call math sin (.5)
set ccc [ mathx sin (.5) ]
puts " value $ccc "
% console output
10
10
0.479425538604203
value 0.479425538604203
Example4, Code scraps, ref. func proc from Tacit programming.mht,RS
console show
proc pie {} {expr acos(-1)}
set aa 1
proc call {args} {uplevel catch [list $args]}
proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] }
proc func {name argl body} {proc $name $argl [list expr $body]}
func atand aa (180./[pie])*atan($aa)
puts " [atand 1. ] "
console show
proc pie {} {expr acos(-1)}
set aa 1
proc call {args} {uplevel catch [list $args]}
proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] }
proc func {name argl body} {proc $name $argl [list expr $body]}
func atand aa (180./[pie])*atan($aa)
set aaa [ atand 1. ]
puts $aaa