Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile solution #34

Open
Anniepoo opened this issue Oct 24, 2015 · 11 comments
Open

Mobile solution #34

Anniepoo opened this issue Oct 24, 2015 · 11 comments

Comments

@Anniepoo
Copy link
Member

Find solution for Android and iOS

@JanWielemaker
Copy link
Member

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
Copy link

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
Copy link
Member

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:

  • Use the native SWI-Prolog to do the boot compilation on the machine on which you
    (cross-)compile. Problem is that the native version must have the same (32/64 bit)
    word-length. That could be changed in the intermediate code, but that requires significant
    work in the VM representation on files for `indirect terms' such as floats, strings and big integers.
  • Do the boot compilation lazily on the target machine.

@wouterbeek wouterbeek changed the title mobile solution Mobile solution Dec 24, 2015
@wouterbeek
Copy link

@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
Copy link
Member Author

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

@wouterbeek
Copy link

@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
Copy link
Member Author

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
Copy link

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
Copy link
Member

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
Copy link

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 wn', IOS),
concat_atom([3, '+', 4], ' ', SingleArg),
term_to_atom(Term, SingleArg),
Val is Term,
format('Result is wn', [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:

  • When I saw a comment about a multi stage build process, I was afraid that the swipl.prc is platform dependent but it isn't so I create one (with my modifications to toplevel.pl) on Mac, and simply copy it into the Xcode project.

  • There was some license issues mentioned above. I played with Squeak Smalltalk some time (including compiling that for iOS devices). Our community can claim some credit; as the Squeak's leader Alan Kay was a good friend with Steve Jobs, and Alan asked Steve to allow apps written in other language interpreters.

  • My changes to the Prolog side uses symbols such as ios, but eventually it should be adapted for other mobile platforms where they don't have terminals.

Again, any comments and help would be really welcome!

@yoshikiohshima
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants