Updating Apologue

I've been working on Apologue 1.7 and Parable updates for a while now. There's still some work to do, but I'm going to change the way I proceed on this a little. Beta testing is nice, but I only get feedback from two people, and I want to expand the feedback pool to include everyone using this. 

The 1.7 release will be submitted for review tomorrow. The documentation could still use some improvements, and there's probably still some bugs I haven't identified, but it's stable enough for use, and the improvements to Parable are worth making available to everyone.

Following this, I'll be doing a series of smaller releases (1.7.x) releases, to incorporate documentation updates and continued improvements to Parable.

On the interface, the smaller releases will bring refinements as I get more feedback. I have a few general plans, but any input on this would be appreciated.

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 !

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 !

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

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