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

an alternative InteractiveShell

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.1-rc-3
    • None
    • None

    Description

      The other day Jon Aquino posted a short groovy script that works as an interactive shell. I was inspired by that idea and have come up with this interactive shell written in groovy.

      The model is actually similar to a line editor that happens to run the content everytime a new expression is entered or a block of {} enclosed statement has been received.

      Here is the help information it prints:

      : | ? | help print this help.
      <enter> | :ls list the entire script.
      :x | :q | exit quit.
      :d drop the last script entry.
      :da drop all.
      :clear drop all.
      :d<n> drop the <n>th entry of the script.
      :d<low>..<hi> drop the entries in the range of [<low>..<hi>].
      :d<low>.. drop the entries from <low> till the end.
      :d..<hi> drop the entries in the range of [0..<hi>].
      :r run the entire script.
      :r<n> run the script up to the <n>th entry.
      /<statement> evaluate but not save the statement/expression.

      you get the idea.

      Compared to the shell in the distro, it has advantages in

      1. highly interactive. it always returns the value of the last statement. Say goodbye to print/println
      2. the interactive session can be thought of as a session to build a groovy script. I have commands to manipulate the entries in a couple of ways. I can drop entries as I wish; I can run the entire script or just part of it; I can also evaluate an expression without saving it in the history.
      3. Exceptions are carefully handled so that I only see the short and meaning part of it.
      4. I can redefine functions and classes, by dropping and recreating them. (The script uses a new instance of GroovyShell everytime I hit enter, thus avoid all the class definiton problems.)

      I have found it to be much more fun and handy than the Java version of the InteractiveShell, albeit a little slower.

      Single file. Grab it and try it out! More enhancement is on the way.

      Attachments

        1. Groovish.groovy
          10 kB
          Bing Ran
        2. Groovish.groovy
          10 kB
          Bing Ran

        Activity

          People

            user57 Jason Dillon
            bingran Bing Ran
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: