Recursion in Tclprocs

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Recursion in Tclprocs

  • Creator
    Topic
  • #50240
    garry r fisher
    Participant

      Hi,

      I have a requirement where I need to use recursion in a Tclproc but I can’t figure out how to do it.

      I’ve tried using a namespace for the recursed proc that I can’t get it to work. So is there a way of doing it?

      Any thoughts on this would be greatly appreciated.

      Regards

      Garry

    Viewing 5 reply threads
    • Author
      Replies
      • #65295
        Charlie Bursell
        Participant

          I don’t know what problems you are having but Tcl does support recursion to a limit.  I think the limit right now is 1000 levels.  Of course, this also assumes you don’t overrun 32-bit limits of numbers, etc.

          Go to comp.lang.tcl on Google and search for recursion

        • #65296
          garry r fisher
          Participant

            Hi Charlie,

            I’m not having a problem with recursion in Tcl – My problem is how do you use recursion in a Tclproc. It maybe the way I was taught but how do you call a proc from within the same proc in Cloverleaf?

            Regards

            Garry

          • #65297
            Charlie Bursell
            Participant

              Just call it  For example, from comp.lang.tcl

              proc fact num {

               if {$num==1} {

                 return 1

               } else {

                 set num [expr {[fact [expr {($num-1)}]]*$num}]

                 return $num

               }

              }

            • #65298
              garry r fisher
              Participant

                I’m happy with that.

                My scenario is if I have a tps that calls aonther proc – and that other proc then calls itself – How would I set this up in Cloverleaf? Ican’t get this to work using a namespace for the second proc – Is that the right way of doing it or should it be in a separate library?

                Garry

              • #65299
                Robert Milfajt
                Participant

                  I am not sure I understand your question.

                  If your TCL proc is defined in the directory with all your others, and you ran mktclindex, you should be able to reference that proc from any other proc including itself.

                  Robert Milfajt
                  Northwestern Medicine
                  Chicago, IL

                • #65300
                  Jim Kosloskey
                  Participant

                    Garry,

                    Send me an email directly and I will send you an example proc I think addresses your needs.

                    Also, Welch’s book on Tcl has a pretty good explanation of the use of namespaces.

                    email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

                Viewing 5 reply threads
                • The forum ‘Cloverleaf’ is closed to new topics and replies.