8/27/2009

Locked into a juicy apple

A bit more than 2 years ago I got bored by my usual XP+cygwin box (and I had given up on Linux anyway), and thought I would try a mac. Meanwhile I have tried macs a lot, spent a fortune on software. Sigh, I am having quite some hardware issues, but fortunately everything so far was covered by warranty or apple care. Anyway, my house is the perfect Mac Family place: several MacBook[pro]s, a time capsule, an iPhone, several editions of all the basic software (iWork, iLive, Mac OS -- Snow Leopard pre-ordered), and a good deal of pay and freeware (e.g., several kinds of screen/video capture/recording).

Here is the problem: I have gotten addicted to apples.

So let me self-diagnose whether I can get rid of that addiction:
  1. I write texts with web apps or with LaTeX. Other Oss can do this too.
  2. I use .key for slides. Some bits would get lost in translation to .ppt[x].
  3. iTunes seems to be platform-independent, no?
  4. iPhoto. Who needs that? I am using Picasa above it anyway.
  5. iWeb. Why did I ever start using it? It is sooo constraining anyway!
  6. I have some minor utilities that I would need to find counterparts for ...
  7. Sure my kids will miss PhotoBooth.
  8. I will miss iMovie; it helped me to understand that I need 4 GB.
Based on such preliminary reflection, I claim that there is an Ok transition path to W7. It's good to have a choice.

PF

8/26/2009

SWI-Prolog's Java Interface JPL

I would like to mix Java and Prolog code on a number of occasions. Together with a student of mine (Joachim Pehl), we just convinced ourselves that the JPL library of SWI-Prolog is really cool. Basically JPL allows you to call Prolog from Java and Java from Prolog.

But the question is, of course, how easy is it and can you easily go back and forth. For instance, can we call Prolog from Java and call back Java from Prolog and share Java state throughout? Sure it works!


PROLOG PORTION FOLLOWS


% This library is all we need to call Java from Prolog
:- ensure_loaded(library(jpl)).

main
:-
% Create an object
jpl_new(class([],['Test']), [], X),

% Printing objects is like printing object ids
write(X),nl,

% Access a field of the object; happens to be static
jpl_get(X, state, Y),

% Prints whatever the state's value is
write(Y),nl.


JAVA PORTION FOLLOWS


// This jar is all we need to call Prolog from Java
import jpl.*;

public class Test {

public static int state = 0;

public static void main(String[] args) {

// Consult a Prolog file
Query q1 = new Query("consult", new Term[] { new Atom("Test.pro") });

// Prints boolean success/failure value
System.out.println(q1.query());

// Affect static field.
// This way we can see whether Prolog sees the same JVM instance.
Test.state = 42;

// Invoke a predicate
Query q2 = new Query("main");

// Prints boolean success/failure value
System.out.println(q2.query());
}
}


BUILDING and RUNNING BOTH

javac -cp $CLASSPATH:/opt/local/lib/swipl-5.6.62/lib/jpl.jar:. Test.java
java -cp $CLASSPATH:/opt/local/lib/swipl-5.6.62/lib/jpl.jar:. -Djava.library.path="/opt/local/lib/swipl-5.6.62/lib/i386-darwin9.5.0" Test
true
@(J#00000000000016809476)
42
true


SO WHAT?

Hence, we can start a Java app, have it start a Prolog engine and consult the Prolog portion of our app, then delegate from Java to Prolog, where we in turn call back on Java in the same JVM and can access some state that we left off in Java before we were calling Prolog.

PF

8/25/2009

The same guy as "Grammarware, Haskellware, XMLware"

What's wrong with the old blog?

I have been using http://blogs.msdn.com/ralflammel/ for some blogging until now. I created that blog when I was still a MS employee and it may be inappropriate to keep using this blog forever. Not that I have any plans to say anything controversial about MS in the future, but some of my personal opinions may be inappropriate on a blogger's domain that is mostly used by MS employees with often more MS-related content. Actually I really like some MS technologies, and I think I can speak about them much more easily when not being hosted on msdn.

Why "Professor Fish"?

I was looking for a content-free title and so I recalled that one of the more offensive students in one of my courses called me a "fish" in a newsgroup. I actually like that name because I like the sea and I like to swim and I like sea food. Anyway, the name is still better than "grammarware, haskellware, xmlware" (the name of my msdn blog) because I also want to (potentially) blog about non-CS stuff.

See me on Twitter.
http://twitter.com/notquiteabba

Regards,
PF