More ABCL/LIRE.
authorOlof-Joachim Frahm <olof@macrolet.net>
Wed, 18 May 2016 12:35:35 +0000 (14:35 +0200)
committerOlof-Joachim Frahm <olof@macrolet.net>
Wed, 18 May 2016 12:35:35 +0000 (14:35 +0200)
abcl-and-lire.post

index fc1814f..dc84b1f 100644 (file)
@@ -80,7 +80,7 @@ specifies all names:
 
 ```
 (defun read-image (pathname)
-  (jstatic "read" "javax.imageio.ImageIO" (jnew "java.io.FileInputStream" (namestring pathname))))
+  (jstatic "read" "javax.imageio.ImageIO" (jnew "java.io.File" (namestring pathname))))
 ```
 
 Though with a combination of JSS and cached lookup it could be nicer,
@@ -88,10 +88,10 @@ even though the setup is more verbose:
 
 ```
 (defvar +image-io+ (jclass "javax.imageio.ImageIO"))
-(defvar +file-input-stream+ (jclass "java.io.FileInputStream"))
+(defvar +file+ (jclass "java.io.File"))
 
 (defun read-image (pathname)
-  (#"read" +image-io+ (jnew +file-input-stream+ (namestring pathname))))
+  (#"read" +image-io+ (jnew +file+ (namestring pathname))))
 ```
 
 At this point without other improvements (auto-coercion of pathnames,
@@ -237,6 +237,19 @@ Generally this would be appropriate, except for places where we'd really
 want the Java side to receive a Lisp object.  Having a special variable
 to *disable* conversion might be enough for these purposes.
 
+If we were to forego the nice properties of JSS by requiring a function
+form, the following would be another option:
+
+```
+(defun read-image (pathname)
+  $(read 'ImageIO (new 'FileInputStream pathname)))
+```
+
+Where `$(...)` would be special syntax indicating a Java method call.
+Of course the exact syntax is not very relevant, more importantly static
+properties could be used to generate a faster, early bound call by
+examining the supplied arguments as a limited form of type inference.
+
 ## Summary
 
 After introducing the necessary steps to start using ABCL with "native"