I’m please to announce a new release of Kojo, with support for Worksheets (this feature is inspired by Worksheets in the Scala Eclipse Plugin).
With this feature, you can run any script in the Script Editor as a Worksheet – to see the type and value of each expression in the script right next to the expression. This makes playing with functions (as opposed to commands) very productive.
There are a couple of samples (dealing with prime numbers and prime factors) under the Samples -> Arithmetic menu item that show the Worksheet feature in action.
Here are some useful-to-know things about the Worksheet feature:
- There’s a new Run as Worksheet button to run a script as a worksheet. Hitting Shift-Enter on the keyboard accomplishes the same thing.
- You can put // #worksheet inside a script to force it to run as a worksheet
- If you want to run a subset of the code inside the Script Editor as a worksheet, just select the code you want to run and hit Shift-Enter (or press the Run as Worksheet button).
- The smallest unit of code you can run as a worksheet is a line. If you select a portion of a line and try to run it as a worksheet, the whole line will get evaluated (this is actually quite convenient when you want to run single lines as worksheets – you can just select any single random character on a line instead of the whole line and hit Shift-Enter). Note – for normal (non-worksheet) code running, precisely the selected code gets evaluated, and sub-line selections do not result in the evaluation of the whole line.
- Beware of forward references in your code. If function1 refers to function2 which is defined later in your script, and you modify function2, function1 will see a stale copy of function2 (from the previous run) the first time you run your code after the modification (because when you run your script as a worksheet, it is evaluated line-by-line). If you run your code again, you should be fine. But this can be confusing, so there’s a new resetInterpreter() command which you can put at the beginning of your script to make Kojo forget previous definitions of functions.
- (This one’s not specific to the worksheet feature but it’s useful to know anyway) If your code goes into an infinite loop and makes no interruptable calls (to commands like println), you will not be able to stop the runaway code with the Stop button. In cases like this, you have no option but to restart Kojo.
Feedback welcome. As always, the new version is available from the Kojo Download Page.