loading...
Heroku

An ode to GNU Artanis

nocnica profile image Nočnica Fee ・5 min read

In Feburary of 2013, NalaGinrut brought Artanis to a GNU Guile hack-potluck. Seven years hence, the Christmas of 2019, she released the first stable version, Artanis 0.4.1. Over the course of these 7 years, Artanis has become a stunningly modern Web Application Framework (WAF).

Artanis is fully open source and written in Guile Scheme. It is fully extensible. Plus, it has an asynchronous, non-blocking server core. Sadly, however, Artanis, and its accompanying documentation, is still pretty beta. Many of Artanis' promised features are as ambitious as they are ambiguous. However, the goal of the project is really straightforward: Artanis will gather all the disparate needs of a WAF into the functional embrace of s-expressions. And I, for one, proclaim that mission noble and true!

GNU Artanis, Functional Warrior

GNU Artanis sticks to the KISS principle while wrestling the various components of the Model-View-Controller web application into the Functional Paradigm. Artanis eschews Domain Specific Language for a variety of "Scheme-On-Rails" solutions; It eschews Object Relational Mapping for It seeks to do away with Object Relational Mapping in favor of purely functional and stateless Functional Programming Relational Mapping. Sadly, the latter is still in a fledgling state, so Artanis' Symbolic-expression SQL is more viable at present.

But why? Other web application frameworks might depend on side effects to provide prefabricated solutions that "just work". Some folks reckon that a functional way of doing things is ultimately more elegant. Cleaner code means a cleaner implementation, less prone to the sort of problems that come with object orientation with multiple threads. Because it doesn't rely on side effects, atomising and threading is much safer. The scope of a process is it;s pown continuation and nothing else, so data races are much easier to avoid. This is especially important for this new world of light solutions to heavy problems. efficiency is the name of the game in the 21st century of technology. With stateless, functional solutions, like Artanis, you evade the most fundamental problems with implementing asynchronous, non-blocking web solutions.

An Artanis Project from the Ground Up

Installing Artanis

Artanis is installed, at present, from scratch. The only team packaging it is Guix. So unless you already have Guix, it's probably best to just go ahead and follow NalaGinrut's instructions. They proceed like this:

First we need Guile 2.2.2. Earlier versions of Guile will not work. We are getting Guile directly from the GNU website and just building it straight away. Run these commands to get Guile 2.2.2.

wget -c ftp://ftp.gnu.org/gnu/guile/guile-2.2.2.tar.xz

tar xvJf guile-2.2.2.tar.xz

cd guile-2.2.2

./configure && make

sudo make install

Then there's the DBI, or Database Interface. We need that, naturally, for playing with the database for our application. The buildchain is about the same, it just uses an autogen script instead of a configure script to make the makefiles.

wget -c https://github.com/opencog/guile-dbi/archive/guile-dbi-2.1.7.tar.gz

tar xvzf guile-dbi-2.1.7.tar.gz

cd guile-dbi-guile-dbi-2.1.7/guile-dbi

./autogen.sh && make

sudo make install

You may have noticed we skipped over the root of the previous archive to get at the guile-dbi files. That's because the guile-dbi-2.1.7 archive bundles the DBI with various Database Drivers, or DBDs. Let's leave that be for now. Artanis' database support is still in its infancy. Should you ever need to, install the appropriate dbd.

For now, we're ready to grab Artanis from GNU.org. Once we configure, make, make install Artanis, we are on our mark!

wget -c http://ftp.gnu.org/gnu/artanis/artanis-latest.tar.bz2

tar xvjf artanis-latest.tar.bz2

cd artanis-0.4.1/

./configure && make

sudo make install

Now for the art

Artanis comes with a utility called art. It provides helper functions for creating, running, and updating our app. For now, we will just follow these steps.

First, run:

art create artanis-demo

This will create a new application in the directory artanis-demo. Let's take a look.

cd artanis-demo && ls

Alt Text

Here we see the basic framework of an Artanis app. Most of our work will show in the app directory. It keeps subdirectories for controllers, models, and views. The conf directory contains a single file, but it is of multitudinous importance. The artanis.conf file contains the general configuration of the whole application vis-à-vis Django's "settings.py" or Ruby-on-Rails' "application.rb". The other directories are backend for the most part. Directory db contains database files, lib for libraries, prv for private, pub for public (or static---depending where you are from I suppose), sys houses locale data and default pages for 404s and the like, test keeps space for testing routines, and tmp is for, well, temporary files. That just leaves ENTRY. ENTRY is the appropriately named entry point of the app.

Let's make a fresh new controller to demonstrate. Run the next art command.

art draw controller article show

Art draw drafts a new controller, model, or migration. In our case, we are generating a controller called article with a method called show. This breaks down the command into this synopsis:

art draw {controller,model,migration} name [methods ...]

We can look in the app subdirectories now and see the newly generated files.

Alt Text

An "article.scm" in controllers, and an "show.html.tpl" in views/article.

We map the newly generated controller to the RESTful api with:

art api -c

Once that's done, we can locally host our auto generated page by running:

art work

Alt Text

Here we see art starting with the ENTRY file and progressing from there into our article controller.

Lets take a look by directing our favorite web browser to "localhost:3000/article/show".

Alt Text

Now we're off to the races!

Broad strokes with a big brush

The rest is really just Guile Scheme. That's the real beauty of Artanis. It doesn't require much special API lingos or DSLs to get up and running with it. It's really just symbolic-expressions and functions all the way down. NalaGinrut offers some really helpful hints for developers coming from other programming backgrounds.

Should you get lost in the documentation, refer to the GNU Artanis mailing list.

Take the time to try out GNU Artanis for yourself, and see how easy it really is!

Posted on by:

nocnica profile

Nočnica Fee

@nocnica

Actually the pug from Dune (1984)

Heroku

Heroku is a container-based cloud Platform as a Service (PaaS). Developers use Heroku to deploy, manage, and scale modern apps. Our platform is elegant, flexible, and easy to use, offering developers the simplest path to getting their apps to market.

Discussion

markdown guide