Java Prolog

I’ve mentioned before that I’m working with a C# implementation of Prolog. Is anyone here working with one of the Java implementations, e.g. GitHub - jiprolog/jiprolog: JIProlog is a Prolog interpreter, pure Java 100%, cross-platform and Open Source. ? If yes, how easy is the implementation to work with and how fast is it?

1 Like

I keep thinking that technology is really a very small part of a coding effort. Most important to me is that there is a community of active users and that that the technology is actively developed.

I feel that if you can find a way to get swi-prolog work in an embedded fashion on android – i think this is what you are looking for – then it would be the preferred route.

@grossdan , I agree – but swi-prolog cannot run locally on a mobile platform. It can only be accessed on mobile through some kind of wrapped call to a server. I feel my best bet is to find an actively developed mobile version of Prolog that is standard compliant. I don’t expect to switch from C# to Java, at least not right now. I’m just interested in hearing people’s experiences with various implementations.

I don’t recall right now to detail, but if i recall correctly, i once tried out to run my swi prolog application on android by first installing an android linux “box” and command line and it worked.

Not sure how this would enable using swi prolog as a backend though, but perhaps its possible via some kind of RPC / socket mechanisms.

But, on another track – is there an inherent limitations to get swi-prolog run on android – it does work on raspberri pi …

It would be great to have swi-prolog on Android & iOS and be able to make an app to sell in the major app stores. But, I can’t expect users to first install a version of Linux. The Pi’s are cool little computers, but I don’t think it is a good target market for a commercial app. I’m going to have to compromise on the Prolog implementation I think.

But, i guess this shows that it can swi prolog can run on android – what would it take to get swi prolog compiled as a c based library for android apps …

I’m sure it’s do-able – after all, there are plenty of examples of Javascript communicating with a backend using sockets. But wouldn’t it be better to simply have a self-contained app? And could that be done by using wasm? (There seem to be projects on github for running wasm under android … targeting Java probably is trickier because Android uses a different byte-code than “standard” Java)

I experimented with TermUX, that has swipl available and localhost, and (to my surprise) from Chrome I was able to easily call the Prolog server.

@CapelliC this is good to hear, but, I agree with @peter.ludemann’s thinking–a self-contained app would be better. This likely requires compromising on something without swi-prolog’s bells and whistles. I’m considering delaying that decision as long as possible by focusing on vanilla Prolog development.

Well, I agree, the VB like experience is difficult to forget… but consider that today is common to write portable apps in Javascript. For instance Expo (based on React Native), would make your app runnable on Android, iOS, and Web…

I’m not familiar with Expo. I’ll take a look. Thanks!

I’ve been told by people I know who ought to know, that the cool kids are now using Flutter, which uses Dart rather than JavaScript, and supposedly the whole thing is cleaner than React …

Looks like DART has an ffi to get c based external libraries working …

FWIW, I do know (a bit of) Flutter, but so far my experience has not been positive, when compared to Expo…

Maybe Google has the power to redefine the world behaviour, but Expo sees 3 (!) mayor SW player ‘cooperating’: Google itself, behind NodeJS, Facebook, driving Expo and React (Native), and Microsoft, that launched the (awesome, I must say) TypeScript.

And WordPress has recently courageously switched to React…

Bottom line is that there are several ways to deal with SWI-Prolog in Android

  • Run it on a server and connect using the network
  • Run it locally using e.g. temux and connect using the (localhost) network
  • Get JPL running. That has (as I quickly browsed this topic) not been raised. SWI-Prlog can be compiled to a working library on Android and JNI should allow to use that from Java. It most likely does require some work to get the ciompilation and linking to work. Anyone experienced with build tools and Android should be able to figure that out (possibly with some help from here to figure out the Prolog steps of the build). Ok, the result uses native code and rthus will only work on compatible hardware. Same should work for C#.
  • Use the WASM version.

I was going to suggest JNI, but @jan beat me to it. I only used it once, many years ago, and it was a nightmare…but presumably that would be the best performance and least compromises in capabilities.

Just in case it helps, I have open-sourced today LeanProlog, a fairly fast, compiled Java-based Prolog. It might be an easy port to C# as most of it is written in Prolog itself and has a small runtime system, see:

1 Like

Thank you! It may indeed come in handy in the future.

I’ve gotten pretty far using Yield prolog, where prolog source is compiled to c#

Never got to production because we had to change focus, but imho Yield prolog feels like it could be very useful.

1 Like

Thanks @peter.ludemann , @CapelliC , @grossdan . I’m going to move away from software development (GUI and deployment targets) for a few weeks to refocus on the “smarts”: ontologies, logic programming, planning & scheduling, etc. When I get back to the GUI, I’ll look at flutter, expo, etc. One concern I have is IP protection–I’d like to hide what the GUI sends to the backend “smarts”.