Version 84 of Call Procedure Like Fortran Example

Updated 2020-10-10 15:15:54 by gold

Call Procedure Fortran like Example


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. Thanks, gold 12Dec2018



Introduction


gold Started roughly 2011-05-18. Here is an TCL 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. A call procedure is a possible sugar for many TCL core commands and subroutines. This "sugar" concept was initially developed in upvar sugar, Salt and Sugar, and Math sugar,Radical Language Modification,and Functional Programming by RS, LV, RLE, and others on the wiki. Also, a similar procedure for Call Return in a TCL subroutine is possible. The call statement may be 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. Usually the Fortran dogma was a conditional STOP or END statement at the end of a punched card deck or subroutine deck to prevent endless loops. Some multiple termination statements like STOP;END; and RETURN;STOP;END; were not uncommon in Fortran_4 subroutines. So 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 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 source code library TCLLIB>. But I am not sure this routine adds much to what is already available on TCL.


gold 10Oct2020. Using a list of "call subroutines" is a simple way of organizing a main program with successive subroutines. Although in TCL, the subroutine procs usually have to be defined first at the head of 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 ones organized thoughts more apparent to the reader. The easy eye console was used as a testbed for one liners programs in TCL on Windows 10. The easy eye console has large black type on green background. The easy eye console may include extra Self_help under the normal Help button of console display


gold 10Oct2020. A console program was modified for experiment 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 <king buy 30 grain> or <king sell 20 land>, lower case. English is 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 noun or verb, as in please exit though the exit.

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:


More References




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

    1% call subroutine2 call
       subroutine 2 active6
    % call
      0
    7% call call
    0
    8% call  call call
    0
    #trivial (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 control flow statements
        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, this license .


Hidden Comments Section



Please place any comments here with your wiki MONIKER and date, Thanks.gold12Dec2018