From: Olof-Joachim Frahm Date: Wed, 18 May 2016 12:35:35 +0000 (+0200) Subject: More ABCL/LIRE. X-Git-Url: http://repo.macrolet.net/gitweb/?p=blog.git;a=commitdiff_plain;h=c73cb164351ec6e6e2219c05fbcd7802724f6f93 More ABCL/LIRE. --- diff --git a/abcl-and-lire.post b/abcl-and-lire.post index fc1814f..dc84b1f 100644 --- a/abcl-and-lire.post +++ b/abcl-and-lire.post @@ -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"