Using Parable Offline on iOS (Part 2)

Earlier I mentioned that I was working on adapting pre, the minimal interface to Parable, for use with Pythonista on iOS. I'm pleased to announce that this is now done, and ready for use.

To set it up you need to do the following: 

  • Create a new script named pre.py
  • Copy/paste the pre code into this file
  • Create a new text file named source.p
  • Put your Parable code in this file, then run pre.py to see the results.

It's extremely spartan, but should work well enough to allow Parable code to run offline. This is still subject to memory constraints: I've capped the MAX_SLICES at 8000. Length of the slices is subject to whatever memory is left unused by Pythonista; it should be enough for most programs on reasonibly modern hardware. (I use a device with 1GB of RAM; use on older devices with 512MB may be problematic).

But it's here, and working now. I'd like to eventually fold this into Apologue, but I'm in the early stages of exploring this, and time constraints are making this a slow process. 

Using Parable Offline on iOS

To do this properly, I need to either find a good way to build/embed a Python system in the app, or rewrite the language in Objective C. Neither one of these options are feasible at this point due to time constraints (though I'm now leaning towards the former, as it'd let me maintain one codebase for the actual compiler/VM).

For now, it's possible to use Parable offline if you have Pythonista installed. Due to app store restrictions on importing code, it's not the easiest thing to set up, but it can certainly be done.

Currently doing this requires creating and copy/pasting several scripts, and doing some manual edits to both parable.py and the listener UI to remove the interactive bits. It's messy, and I'm not happy with it.

So I'm going to update pre, adding support for Pythonista. Once done, it'll scale down the MAX_SLICES to an amount that should fit in iOS memory constraints, and look for a source.p to run.  I am planning to have this in the repository tonight or tomorrow afternoon at the latest. More to come as work progresses...

The Preserve Combinator

On C.L.F., humptydumpty posted some code to provide a form of variable that could be saved/restored. His post provided an example:

defvar X                               
: testx  X ? ;           
: testlet 99 X let testx X unlet ;
1 X !
testx
testlet
testx

Parable and Retro support this functionality via the preserve combinator:

"parable example"
'x' variable
[ &x @ . ] 'testx' define
[ &x [ #99 &x ! testx ] preserve ] 'testlet' define
#1 &x !
testx
testlet
testx
show-tob


( retro example )
variable x
: testx x @ putn ;
: testlet x [ 99 x ! testx ] preserve ;
1 x !
testx
testlet
testx

In the case of Parable, this goes slightly further in that it saves and restores the entire slice passed to it. This becomes useful with arrays, since many of the array functions modify the arrays passed into them directly. E.g., if we wanted to count the even and odd items in an array:

[ #1 #100 expand-range ] array-from-quote '1..100' define
&1..100 [ &1..100 [ even? ] array-filter ] preserve #0 [ + ] array-reduce
&1..100 [ &1..100 [ odd? ] array-filter ] preserve #0 [ + ] array-reduce

Retro for iOS 1.3.1

I'm pleased to announce that the iOS version of Retro has a small update. This release fixes a bug that was causing the editor contents to be lost when switching views under certain circumstances. It also addresses the performance issues that were present when switching projects.

As before, it's a free update, or $0.99 for new users.