jp scratchpad Homepage

Copyright (C) 2000 Samuele Pedroni

The homepage contains the readme and the minitutorial with its output plus a  screenshot from a tutorial run.

Back to sourceforge.net project main/download page.


readme (0.5t)

** Highlights **

The minor fixes in this release make jppad able to be run with
python.security.respectJavaAccessibility=false.
This makes it more suited for interactive testing, etc.

**Intro**

jp scratchpad is an interactive execution environment for jpython, it does
not resemble a shell nor it is an IDE, it is mostly like mathematica notebooks.
jp scratchpad should be valuable for simple algorithms prototyping and
API exploring.
You can redirect jpython and java output and error streams to the work area,
an output window or the console.
Further it has some capabilities for unloading/reloading of java classes
without having to restart a whole new session.

**What you need and how to run the environment**

You will need:
 JPython 1.1 (http://www.jpython.org)
 Finn Bock's errata for it (http://sourceforge.net/projects/bckfnn-modules)
and you should run the whole under some java2 environment
(java 1.1 will not work).
NOTE: The reloading/unloading support for java classes is known to work
properly only under jdk/jre 1.3 !!!
TECH: the point is not reloading, but the consistency
checks in the support, their purpose is to avoid confusion, but they have shown
to fail under other jvms.

jp scratchpad comes with an executable jpython jar file jppad.jar, something
like
 jpython -jar jppad.jar
should work to start it.

**Once it has been started (tutorial)**

There is a mini tutorial in the stuff directory of the distribution.
Once started you can bring up a context popup menu with the usual mouse button
for your system, and then use the menu entries 'include¦w/>>chunks'
to load stuff/minitutorial.jppad then follow the instructions.
The tutorial assume that you are familiar with jpython/python.
To exit: just close jp scratchpad window.
NOTE: if the popup menu does not appear try something like
 jpython -Djppad.popupbug=BUTTONx -jar jppad.jar
where x=1|2|3 and then try again with the corresponding mouse button.


**Options**

You can configure some aspects of jp scratchpad trough the
system properties or a jppad.props file in your home directory.
An example for jppad.props is in the distribution stuff directory,
all possible properties with their default values are listed there.
All the properties names are of the form jppad.* .

**Shortcomings**

(i) I do not pretend in any way that jp scratchpad is clean code, it has
been written while working on other projects to be a somehow useful tool.
(ii) Working with it, you maybe will encounter some bug that are jpython hidden
bugs, for example if you load an interface from the dyn-class-path
(see minitutorial) and try to subclass it, you get an error.

**Feedback**

I have set up a mailing list for open discussion on jppad:

 jppad-interest@lists.sourceforge.net

At the moment it is open for posting for everyone.
I'm interested in constructive comments or critics (maybe destructive too ;))
otherwise I will never be able to improve it.
I will try to do my best effort also to answer to related problems and questions
trough the mailing list.

**License**

    jp scratchpad 0.5t
    Copyright (C) 2000  Samuele Pedroni

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
    USA.


Minitutorial text & Output


-- Mini tutorial

-- One can evaluate simple python statements. Try pressing Shift+Enter
 on the next line.
1+2
>>
 3

-- Simple statement boundaries are recognized. Try Shift+Enter on any
 line of the following statement.
for i in range(1,4):
 print i,
 print 2*i
>>
 1 2
 2 4
 3 6

-- '--' starts comment/inactive text chunks
 Shift+Enter on a statement invoke evaluation.
-- Multiple statements can be put together and executed at once
 gathering them in a block starting with a '!' line and using
 indentation. Let's do some cleanup. As before Shift-Enter
 somewhere on it.
!
 print dir()
 del i
 print dir()
>>
 ['__doc__', '__name__', 'i']
 ['__doc__', '__name__']


-- Some more features.
 First execute this assignment
a=3
>> ok

-- The output is None but you still get an '>>ok' feedback.
 Then try this block. Do not erase the output.
!
 a=a+1
 print a
>>
 5

-- Now try to press Shift-Enter on one of the output lines ('>>',' 4').
 The statement is evaluated again and the output changed accordingly.

-- Error handling.
 The next statement is not lexically correct. Try Shift-Enter.
a=$+3
  ^Lexical error at line 1, column 3.  Encountered: "$" (36), after : ""

-- This is not syntactically correct. Try.
if
   ^invalid syntax

-- This statement should continue. Try.
if a==6:
...

-- y is not defined raising an exception. Try.
!
 print a
 y
>>
 5**err*
  **exc*
   traceback (innermost last)
    File "<!>", line 2, in ?
   NameError: y

-- Line numbers make sense.

-- One can execute statements in on-the-fly created modules.
 First.
!module0
 x=3
>> ok

-- Then try:
!
 import module0
 print module0.x
>>
 3

-- The default module is:
print __name__
>>
 __pad__


-- Unloading of java classes.
 First one should set a path where unloadable classes are
 located. This can be a set of directories and/or jar files and
 must be disjoint from the usual classpath.
 There is an escape command for this.
 ex.: +dyn-class-path-append [...]/y [...]/x.jar
 For the tutorial we need to reach the directory stuff/xper
 of jppad installation. Modify the following as necessary and
 execute it as always with Shift+Enter.
-- On Windows you need something like x:/jppad/stuff/xper
+dyn-class-path-append /home/user/jppad/stuff/xper
>> ok

-- NOTE: The reloading/unloading support for java classes is known to work
 properly only under jdk/jre 1.3 !!! See the README file.


-- Notice: xper contains X.class, X.clazz and X.java-v0, X.java-v1
 that are the source code for the two bytecode compiled classes.
 Try the following.
!
 import X
 print X.v()
>>
 version 0

-- With this esc command every python-object defined in the session
 is discarded and the java classes from the dyn-class-path are unloaded
 too.
+forget
>> ok

-- Note: The dyn-class-path remains valid and set.
 In order to discard it too one should use
  +forget-forget-dyn-class-path

-- Now try the following. Modify the first line as necessary.
!
 xper='/home/user/jppad/stuff/xper'
 import os
 def toggle():
  os.rename(os.path.join(xper,'X.class'),os.path.join(xper,'X.cla__'))
  os.rename(os.path.join(xper,'X.clazz'),os.path.join(xper,'X.class'))
  os.rename(os.path.join(xper,'X.cla__'),os.path.join(xper,'X.clazz'))
 toggle()
 import X
 print X.v()
 toggle()
>>
 version 1


-- More.
 Attached to this window there is a contextual popup with many
 functions.
 For example indent/dedent which operate on the selection.
 Ctrl-I, Ctrl-D do the same.
 Functions to include/export text from/to files (ev. filtering the
 outputs '>>...')
 There is also an output window and the popup contains actions
 for redirecting the various python or java err or out streams
 here, to that window or to the console.
 E.g. per default java System.err is redirected to the out-win.
 Try.
!
 from java.lang import System
 System.err.println('xx')
>> ok

-- And.
!
 import java
 raise java.lang.Exception()
>>
 **err*
  **exc (java)*
   traceback (innermost first)
    File "<!>", line 2, in ?
   java.lang.Exception: java.lang.Exception


-- Hack.
 Before trying this use the popup to redirect java out here.
 xper should still be in the dyn-class-path.

!
 import Y # from xper, the source is also there
 import Z # from xper, the source is also there
 Z.sendSELmsg(Y())
 a=3
>>
 loading Y
 loading Z
 ** Y *

+dyn-reload
>> ok

!
 print a
 Z.sendSELmsg(Y())
>>
 3
 loading Y
 loading Z
 ** Y *

-- The semantics of +dyn-reload is a bit hackward.
 It reloads all classes from the dyn-path, but no instances or
 derived pyclasses should be around and only names at  top-level
 in every module can be bound to these classes and then get rebound
 to the reloaded versions. If something fails you get a feedback
 on the involved classes and you can fix it and issue a +retry.