This tutorial assumes you have some familiarity with Scheme and Java. It shows how to access Java objects from Scheme.
SILK adds several functions to Scheme that provide access to Java. In each case, the arguments can be either strings or symbols.
> (class "java.lang.Class") class java.lang.Class > (class "javax.swing.JFrame") class javax.swing.JFrame
> (define ht (constructor "java.util.Hashtable" "int"))
ht
> (define h (ht 20))
h
> h
{} ; An empty HashTable.
> (define put (method "put" "java.util.Hashtable" "java.lang.Object" "java.lang.Object"))
put
> (put h "fern" 3)
()
> (put h "bar" 4)
()
> h
{bar=4, fern=3}
> (import "java.util.Hashtable") importing java.util.Hashtable in 40 ms. #tThis has the following effect:
> Hashtable.class class java.util.Hashtable
> (Hashtable? h) #t > (Hashtable? 3) #f
> (define h (Hashtable 20)) h
For an example see ../src/elf/GCMonitor.scm which constructs a garbage collection monitor. It uses ../src/elf/Listen.java to provide Java event listeners that execute Scheme code.