Mobile App Development in PicoLisp - VII: Basic App Components

Search for a command to run...

Hi Mia, menu (the one discussed in the blog above) is defined in assets/run/App.l.
It may be corrected in the blog.
Very nice blog 👍 "menu is defined in assets/run/lib:" Where exactly is menu defined in ~/lib?
In this series, we will see how to write Android apps in PicoLisp.
In the last posts, we have seen how we can access the Java API from PicoLisp, and how a PicoLisp app looks like in general. Now I would like to start a little series of small independent "Apps". We will start with a little "Camera" app. The functiona...
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 this post, we will see what files and components are needed to write an Android app in PicoLisp.
First of all, let's return to the original pilBox.apk that you can download here. Let's unzip it to take a look at the sources. We can find the Android Manifest, the Java classes and a few other documents there.
Note: if you are interested in the complete data (like the original Java sources), you can get it here: PilBox-complete; installation details in the ReadMe.
What we are interested in specifically is the folder assets/run, which specifies the PicoLisp environment. For example, we can find the PicoLisp libraries in assets/run/lib.
Now let's take a look at assets/run/App.l. It is titled "Generic PicoLisp App" and defines the environment of the apps, such as loaded libraries, namespaces and so on.
"Generic PicoLisp App"
(load "@lib/net.l" "@lib/misc.l" "@lib/btree.l" "@lib/db.l" "@lib/pilog.l")
(msg *Pid " " (stamp))
# Generic PilBox App
(allowed ()
"!pb0" "!pbHome" "!pbRepl" "@lib.css" "@lib/phone.css" "!pb.css"
"!pbSettings" "!pbList" "!pbCat" "!work" )
...
(symbols (setq *PbSymbols '(android pico)))
...
Now with that in mind, we will check out some of the demo applications.
Let's begin with the hello.zip demo app, which is truly minimal. After unzipping it, we get a folder hello with a single file inside, which is App.l. This is it's content:
"Hello World"
(menu "Hello World!"
(<h1> "center fh" "Hello, World!") )
The first string is the description title of the list which is rendered to the home screen button.

Since we didn't specify a logo, the standard PicoLisp logo is used.
The menu function is rendered to this:

menu is defined in assets/run/App.l:
(de menu (Ttl . Prg)
(unless *SesId (forbidden))
...
(action
(html 0 Ttl
(if (hasFile "lib.css")
(list "@lib.css" "@lib/phone.css" @)
'("@lib.css" "@lib/phone.css" "!pb.css") )
...
((0 0 'main)
(prog
(<div> @
(run Prg 1) )
...
It basically defines the header with the logo and settings wheel and the HTML and CSS environment for the program to be executed. In our case, the title is "Hello World!" and the program is (<h1> "center fh" "Hello, World!") ) which just prints a string.
crash demo appNow let's take a look at a slightly more complex example: the "Crash" app. Besides the App.l it contains a file called logo.png which is displayed on the Home screen and in the upper left corner.
By clicking on the "Crash me!" button, you can provoke an error.
(menu "Crash me"
(form NIL
(<div> "center"
(<h2> NIL "Crash me")
(gui '(+Button) "Crash now!"
'(/ 1 0) ) ) ) )

The code is defined in the PicoLisp error handler *Err in assets/run/App.l of the PilBox source code (line 361):
(de *Err
(println '==== *Pid (symbols))
(for ("L" (trail T) "L")
<...>
(println '====)
(loadTxt
"<style type=\"text/css\">body{color:white;background-color:red}</style>"
"<h1>☹</h1><pre>" (sym ^) "</pre>"
"<pre>" *Msg "</pre>" )
(wait 420) )
where *Msg is a PicoLisp global variable holding the last recently issued error message.
As long as no smartphone-specific functions are required, we have now all the knowledge to create purely PicoLisp-based apps. Basically the structure will be the same like in the Web Apps tutorials, except that the code is not executed on the server but by the PilBox.
Some good examples for this are in the demo app:
In the next couple of posts, we will discuss apps which use the java interface to access device functions such as camera and GPS.