SWI-Prolog / roadmap

Discuss future development
20 stars 3 forks source link

Mobile solution #34

Open Anniepoo opened 8 years ago

Anniepoo commented 8 years ago

Find solution for Android and iOS

JanWielemaker commented 8 years ago

At least IOS requires changing the license. That is in progress. For both, the Qt swipl-win can work. So can the SWISH ide, possibly using the Qt browser. For now, SWISH provides a server side solution for playing.

thetrime commented 8 years ago

In the very short term, I don't know that changing the license is necessary to compile an iOS version; just to distribute it via the App Store. With the latest version of Xcode, it's now allowed to install apps to iOS devices without a developer license, so it's a bit more accessible for someone with a mac and an iDevice to experiment. Only; first we need to actually work out how to compile it!

JanWielemaker commented 8 years ago

Whow! Apple opening up :) I thought you once managed to compile it? Cross-compilation should be fairly well organized since we cross-compile using MinGW for Windows. The main issue is that this path assumes you can run the compiled Prolog using Wine. That is in general no the case. I see two solutions:

wouterbeek commented 8 years ago

@Anniepoo Is this issue about SWI-Prolog development on Android and iOS devices, i.e., running the IDE, or is it about easily running SWI-Prolog applications by end users?

Anniepoo commented 8 years ago

the latter, at least at first. Of course the IDE is a SWI-Prolog application, hopefully one day it'd run as well.

wouterbeek commented 8 years ago

@Anniepoo Running a SWI program is already difficult on Windows/Linux/Apple (see #13). There the only short-term solution I see is deployment of the SWI program as a Web Service. Could the same solution work on iOS/Android? Or does a Web app bar access to some of the essential iOS/Android APIs, e.g. sensors?

Anniepoo commented 8 years ago

web apps are becoming more powerful with HTML5 supporting many sensors, but inherently are not a native app. And, on mobile, remember that connectivity can be intermittent. So no, we need a native implementation. Of course the ideal implementation would make web/app implementation transparent to the developer. How that happens in iOS's closed world I don't know.

I built a location based game for Oregon State University as a mobile web app. The game involved running around campus looking for people with various majors located in squares of a grid imposed over the campus. One issue we discovered was that connectivity became part of the terrain of the game.

thetrime commented 8 years ago

A lot of time has passed here, but I should add that Jan's summary is approximately right. I could compile SWI-Prolog on my mac and deploy it to my iPhone, but there were substantial problems getting the boot file. My approach required an incredibly complicated multi-stage build process: First, build the runtime, then load the (bare) runtime onto the device as a signed 'app' using undocumented iTunes API calls, then send it the boot information to compile into the PRA, get that data back, and complete the build on the host. Practically speaking, it's probably not something a typical developer would want to have to go through, but it only has to be done once (per architecture) if we make the compile libs available to others. Then, however, we have the licensing problem if we're making it available to others for binary redistribution...

JanWielemaker commented 8 years ago

In theory, cross-compilation could use a native (host) version of Prolog, provided the word-length (32/64 bits) of the host and target are the same. The alternative might be to skip the boot compilation all together and perform it lazily on the target (i.e., if boot file is missing and we can find the boot directory, perform the boot compilation and proceed happily).

yoshikiohshima commented 6 years ago

Hello!

I am playing with the idea of having a Prolog engine running on iPhone, and came across this thread. Sure, why not? So I spent a few days to compile the interpreter for iPhone. The current (WIP) code is here:

https://github.com/yoshikiohshima/swipl-devel

As you can see, the changes are relatively small. I put some generated files in the repo so that one can just compile it in their XCode.

It is now running on the emulator as well as my iPhone. (The image here is a screen shot of it running on the emulator.)

iphone emu

The result showing "Result is 7" is produced from code:

!/usr/bin/env swipl

:- initialization(go, main). go :- current_prolog_flag(ios, IOS), format('ios is ~w~n', IOS), concat_atom([3, '+', 4], ' ', SingleArg), term_to_atom(Term, SingleArg), Val is Term, format('Result is ~w~n', [Val]).

The way it currently works is that it looks for the file called main.pl, and run it as if it is specified on the command line argument for the interpreter.

I am now trying to get the input into Prolog... But am running out steam and needing a help. What I want to do is to call a query with the string stored in the input field. As of now, there is a very crude way to get the text value into a variable that the interpreter can access (set_ios_input_string() function in pl-read.c), and in the pl_raw_ios_read(), I want to create a memory based stream, call pl_raw_read2(), and bind the result to the term. (There maybe an easier way.) But I just came to a point where trying to figure that out by myself feels really slow. So if somebody look at pl_raw_ios_read() (and all other changes), that would be great! (I am even ignoring the issue of getting next results, but that needs to be worked out, too.)

What I really want is to make this interpreter an embedded decision making engine for an app. So the fact that the app uses Prolog would be hidden. While the app is running, it would send queries to the interpreter from the Obj-C code when needed (as I am trying to do in doButton method in ViewController.m), getting out values, and do something on the Obj-C side.

I do want to use a high level language to develop such decision engine, and Prolog seems to fit the bill. (What do people use if they are not doing this Prolog?) So, I want to evolve the I/O of the interpreter to have easier interaction with Objective-C code over time.

A few other comments:

Again, any comments and help would be really welcome!

yoshikiohshima commented 6 years ago

I even was not aware of this page: http://www.swi-prolog.org/pldoc/man?section=calling-prolog-from-c. And also I found a message on the forum: https://groups.google.com/forum/#!topic/swi-prolog/sg1CxnMcjJI (using load_files/2 with the stream option from the C++ interface) about the 'load_string' technique. I'll try to follow those and see if I can make progress.