*** Call Procedure Fortran like Example *** ---- [gold] 12Dec2018: This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any Internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page. ---- <> ---- ** Introduction ** ---- [gold] Started roughly 2011-05-18. Here is a TCL script on Call Procedure [Fortran] like. A call statement has some advantages in both the [Fortran] and [TCL] languages. In some variants/versions of [Fortran], the call statement is used to control program flow and invoke subroutines. For example, a Call Exit could be used to halt the program execution. A similar procedure for Call Return is also possible in a TCL subroutine. For math in TCL, a call procedure or other math procedures can be developed that do require brackets. A call procedure is a possible "sugar" concept for many TCL core commands and subroutines. ---- ** Discussion ** ---- [gold] 10Oct2020. This "sugar" concept was initially developed in [upvar sugar], [Salt and Sugar], [Math sugar], [Radical Language Modification], and [Functional Programming] by [RS], [LV], [RLE], and others on the wiki. The call statement may be used to organize programs into a list of subroutines and to exit the program. In the early days of programming, exiting a program was not a trivial function. Usually the Fortran dogma was a conditional STOP or END statement at the end of a punched card deck or subroutine deck, preventing endless loops. In Fortran_4 subroutines some multiple termination statements like STOP;END; and RETURN;STOP;END; were not uncommon. A statement like "call exit" seemed pretty swank to beginner Fortran programmers. 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. ---- [gold] 10Oct2020. A list of "call subroutines" is a simple way to organize a main program with successive subroutines, although in TCL the subroutine procedures usually have to be defined first at the head of the main deck. An alternate method is to wrap the subroutine list into a collective proc. The collective proc can be placed at the head and makes one's organized thoughts more apparent to the reader. The "easy eye" console was used as a testbed for one-liner programs in TCL on Windows 10. Essentially, the experimental code is translating Fortran and Quickbasic control-flow statements into one-liner programs. The "easy eye" console has large black type on green background for bad eyes. It may include an extra Self_help button under the normal Help button of console display. ---- [gold] 10Oct2020. A console program was modified for experiments on Natural Language, if the King's English is a natural language. The console program was based on the antique program King Hamurabi.bas, ref [Game kingdom of strategy]. The idea was a limited set of input commands in the King's English, SVO as subject verb object. The initial commands in the computer game were or , lower case. English is an ambiguous language in that terms can either be used as verbs or objects. For example, the above term exit could either be used as a verb, noun, or adjective, as in "please exit though the exit under the exit sign". ---- *** Conclusion *** ---- [gold] 12Dec2018. I have been informed that an advanced TCL user has added and checked this Call Exit subroutine into his homebrew TCL interpreter on his local copy of TCL on a PC system. I have added this subroutine code to my local TCL copy. Meaning the subroutine code may be added to source code library in TCLLIB. But I am not sure these subroutines add much to what is already available on TCL. ---- ** Pseudocode Section ** ---- Using a list of successive "call subroutines". ---- ====== # 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: ====== ---- *** Screenshot Section *** ---- *** Screenshot 1 *** ---- [Call Procedure Fortran like Example screenshot 2] ---- *** Screenshot 2 *** [Call Procedure Fortran like Example screenshot 3] ---- *** References *** * [upvar sugar] * [Salt and Sugar] * [Math sugar] * [A little math language] * [args] * [RS] * [LV] * [Radical Language Modification] * [Functional Programming] * [Custom curry] * [Playing with recursion] * [Sample Math Programs] * Professor Frisby's Mostly Adequate Guide to Functional Programming [https://github.com/MostlyAdequate/mostly-adequate-guide] * [expr shorthand for Tcl9] * [Steps towards functional programming] * [Tacit programming] * The fortran call statement appeared in Fortran2 (1958). example of call exit, fortran 4 * Thocp code, http://www.thocp.net/software/languages/fortran.htm * [Natural User Interface] * [Natural Languages] category * [Game kingdom of strategy] * wikipedia.org wiki The_Sumerian_Game * [A Program That Learns] ---- *** More References *** ---- * [Evan Rempel] * [MDD] * [Find all words] * [Things German] * [How to synthesize a query] * [Writing Tk programs so that the user can extend or interact with them without modifying the application] * [Ruslish] * [Accumulator Generators] * [Accumulator Generator] * [Whadjasay] * disassemble byte code [https://www.magicsplat.com/blog/disassemble/] ---- ---- **** Pretty-Print Version **** ====== # autoindent syntax from ased editor. # call procedure like fortran example # written on Windows XP on eTCL # working under TCL version 8.5.6 and eTCL 1.0.1 package require Tk console show proc call {args} {uplevel catch [list $args]} proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] } proc list_subroutines { variable } { call initilize ;# list variables call subroutine1 1 ;# set up inputs call subroutine2 2 ;# calculations call subroutine3 3 ;# error checks call subroutine4 4 ;# print results call math sin (.5) if { 1 == 1 } { puts "bye bye" }} proc initilize {aa} { puts "subroutine initilize active" return } proc subroutine1 {aa} { puts "subroutine 1 active" return } proc subroutine2 {aa} { puts "subroutine 2 active" return } proc subroutine3 {aa} { puts "subroutine 3 active" return } proc subroutine4 {aa} { puts "subroutine 4 active" call math sin (.5) if { 1 == 1 } { puts "bye" } if { 1 == 2 } { call exit } return } call list_subroutines 1 #end of deck ====== ---- ====== # console output 0.479425538604203 bye 0.479425538604203 bye bye ====== **** Appendix Code **** **** appendix TCL programs and scripts **** ** Example 2, 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 ** Example 3, 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 ** Example 4, Code scraps ** ====== #ref. func proc from http://wiki.tcl.tk/14006 #Tacit programming #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]} ;# RS func atand aa (180./[pie])*atan($aa) ;# RS 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]} ;# RS func atand aa (180./[pie])*atan($aa) set aaa [ atand 1. ] puts $aaa #end of deck ====== ---- ** Example 5, Code scraps ** ---- output from console with program loaded, [gold] ====== call subroutine2 call ;# returns subroutine 2 active6 call ;# returns 0 call call ;# returns 0 call call call ;# returns 0 # trivial as zero list, but no errors from multiple calls. ====== ---- ** Example 6, Call Procedure Fortran like V2 ** ---- ====== # pretty print from autoindent and ased editor # call procedure like fortran V2 # easy eye console V3, large black type on green # used as testbed for one liners programs # written on Windows 10 on TCL # working under TCL version 8.6 # base one liner derived from # gold on TCL WIKI , 10Sep2020 # includes Self_help under Help # tap of console display package require Tk package require math::numtheory package require math::constants package require math::trig package require math namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory math::trig math::constants } set tclprecision 17 proc call {args} {uplevel catch [list $args]} proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] } # successive subroutines of main listed in one liner proc # foreach list organizes control to pass through numbered subroutines proc list_subroutines { variable } {foreach item {1 2 3 4 } {subroutine$item $item }} # translating Fortran and Quickbasic control flow statements # into one liners programs proc stop {} { return } proc end {} { exit } proc pause {} { wait .00010} proc C {args} { set C # } proc REM {args} { set REM # } ;# attack of bots from Quickbasic proc write {args} { puts $args } proc print {args} { puts $args } ;# attack of bots from Quickbasic proc SUBROUTINE {args} { proc $args } proc SUB {args} { proc $args } ;# attack of bots from Quickbasic proc initilize {aa} { puts "subroutine initilize active" call return } proc subroutine1 {aa} { puts "subroutine 1 active" puts " fired subroutine $aa " call return } proc subroutine2 {aa} { puts "subroutine 2 active" puts " fired subroutine $aa " call return } proc subroutine3 {aa} { puts "subroutine 3 active" puts " fired subroutine $aa " call return } proc subroutine4 {aa} { puts "subroutine 4 active" call math sin (.5) write " fired subroutine $aa " if { 1 == 1 } { puts "bye" } if { 1 == 2 } { call exit } print " *******************************" REM testing Quickbasic control words too print " attack of bots from Quickbasic " print " testing Quickbasic control words too " print " Quickbasic bots now in retreat " print " *******************************" # swapping C args for # comments C messege to terminal, operator stop or proceed C pause C redundant subroutine terminators C return control from subroutine to main program return C stop means stop execution to subprogram or main program stop C end means end execution to subprogram or main program end } # # successive subroutines of main listed in one liner proc above list_subroutines 1 call math sin (.5) if { 1 == 1 } { puts "bye bye" } console show console eval {.console config -bg palegreen} # normally use extra big font 40 and but # big fonts 30 or 40, rectangle 40x20 do not display well on wiki console eval {.console config -font {fixed 20 bold}} console eval {wm geometry . 20x20} console eval {wm title . " Call procedure like Fortran V2, screen grab and paste from console 2 to texteditor"} console eval {. configure -background orange -highlightcolor brown -relief raised -border 30} console eval { proc self_helpx {} { set msg "in TCL, large black type on green from TCL, self help listing Conventional text editor formulas grabbed from internet screens can be pasted into green console # Call procedure like Fortran V2 # testbed for one liner programs # loading math ops, TCLLIB components # suggest maintain dead spaces and air gaps near expr, brackets, etc # Note spaces near expr statement must be maintained # or program deck will not work. # blanks _b must be there # pretty print from autoindent and ased editor # call procedure like fortran V2 # easy eye console V3, large black type on green # used as testbed for one liners programs # written on Windows 10 on TCL # working under TCL version 8.6 # control passes in sucesssion through 4 subroutines # example >> math .5 # example >> call math .5 # example >> call exit # example >> math 1*2*3*4*5*6*7*8*9 # example math 5 * 5 * [tand 1.] # gold on TCL Club , 10Sep2020 " tk_messageBox -title "self_helpxx" -message $msg } } console eval {.menubar.help add command -label Self_help -command self_helpx } puts "******************************************************* " puts " console session >> loads Fortran like call into console " puts " console session >> self_help specific loaded in console help " puts " creating new commands inside TCL deck " puts " example >> math .5 " puts " example >> call math .5 " puts " example >> call exit " puts " example >> math 5 * 5 * [tand 1.] " puts " ******************************************************* " # End of deck ====== ---- ---- [gold] This page is copyrighted under the TCL/TK license terms, [http://tcl.tk/software/tcltk/license.html%|%this license]. ---- ** Hidden Comments Section ** ---- <> ---- Please place any comments here with your wiki MONIKER and date, Thanks.[gold]12Dec2018 ---- <> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI ---- <> Development | Concept| Algorithm|Language|programming language| Fortran |Natural Languages ---- <> Functional Programming | Arts and Crafts of Tcl-Tk Programming ----