Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-390

Closure cannot be used to invoke recursive function

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.0-JSR-1
    • class generator
    • None

    Description

      def re {
      if (i ==1) return i
      1.times

      { re(--i) }

      }

      print re(4)

      The re(--i) was not recognized inside the closure.

      If this is supposed to be such, it's a real limitation.

      Suppose I want to visit a tree...

      def visit(node) {
      if (node is a leaf)

      { //.. }

      else {
      node.children.each

      { visit(it) }

      }
      }

      Attachments

        1. test.groovy
          0.2 kB

        Activity

          People

            blackdrag Jochen Theodorou
            bingran Bing Ran
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: