Mobile App Development in PicoLisp - IV: Using the PilBox REPL

Search for a command to run...

Hi Mia, just a suggestion. Here (! ls -l) parentheses might be removed. Just highlighting ! ls -l is better I feel. :)
In this series, we will see how to write Android apps in PicoLisp.
In the last post, we have checked out the REPL. If you have used it, you might agree that it is not really adequate to write complex program. Typing on the phone is not easy, the window is too small and we cannot properly test the code. Today we will...
In our previous post, we introduced how to utilize Discrete Event Simulation (DES) in PicoLisp. Now, let's explore another application: a railroad model simulation that includes tracks and trains. The visualization is ASCII-based, so feel free to unl...

The Dining Philosophers

In this post, we will introduce the concept of co-routines and how they are handled in PicoLisp. This will be the foundation for the subsequent posts on Discrete Event Simulation and finally a couple of examples, including an ASCII model railway simu...

One of the many nice things of PicoLisp is that it comes with a built-in database. This makes it easy to collect and store our own data, for example via a mobile app. But not all data is best represented in tables and lists: sometimes a colorful litt...

In the last two posts, we have built a little app that shows the current location and displays the nearest ice cream shops: https://picolisp-explored.com/an-openstreetmap-app-written-in-picolisp-pt-1 https://picolisp-explored.com/an-openstreetmap-ap...

In the last post, we have downloaded and checked the source code of some demo applications. Now let's see what we can do with the other built-in tool: the REPL.
The PilBox REPL provides us with a PicoLisp interpreter and a very simple shell on our phone. However, typing on the phone can be quite tedious, and it is not adequate for complex operations. A little teaser: In the next post, we will see how to get a proper PilBox shell from your PC.
But for now, let's try to understand how the built-in shell works.
When you open the REPL page (by clicking on the PicoLisp icon in the top left side), you can see a big white field and a small input field below.
Before the input field comes the current namespace, which is currently android. This means that the interpreter first searches the android namespace for a given function and after that the standard 'pico' namespace.

We have two ways to interact with it:
!.
In the example above, you can see that I checked the current system with the shell command ! uname -a, and executed the PicoLisp code (* 3 4).
In other words, with this we have a simple shell on our current phone. whoami returns the PilBox user, which in my case is u0_a384, and ls -la shows us all the files in the current directory. Here you can see what the "sandbox" concept in Android means: all files in the folder belong to user u0_a384 and no other user (process) has access to it.

Of course it also means that we cannot call commands that require higher privileges: for example (! ifconfig) returns No file /proc/net/dev: Permission denied.
Next to the "eval" button, you can find an "edit" button. This button takes the current text in the input field and opens a file of the corresponding name. If no such file exists, a new one is created (but it will only be saved after we have typed something).
Let's try: We could open the main file (App.l) from the "hello"-demo and modify the code. It can be found in the hello/ folder:

Let's tap into the field and change "Hello World" to "Hello, Goodbye". When we click on the top left icon and then on our "Hello" app, we will see that it has changed:

The list of files, viewed with ! ls -l, also shows two interesting files: log and log-. Both of them are log files; while log contains the data of the current process, log- contains the data of the previous process. Accordingly, it can contain important information if your app suddenly stops working.
You can check the content of the files by typing log and press the EDIT-button, or even easier, type ! cat log / ! cat log-.
There are two more buttons: "Clear Cache" and "Debug". When you press "clear cache", you usually won't see much, unless you changed for example the CSS-file: In this case clearing the cache will automatically load the new CSS file (otherwise it might take up to 24 hours).
If you tap the debug-button, you will enter the "debug" mode. This loads all necessary files, and after that the button gets disabled and can't be tapped again. Debug mode is enabled automatically if we connect the smartphone to the computer via a pseudo-tty, as we will see in the next post.