Saturday, May 17, 2008

An Arc News Forum

For my monthly Day of Hacking, I decided to put together my own news forum, yc-style. Luckily, it's the demo app of Paul Graham's Arc.

Within a day, I got my own forum up and running, quick and dirty. But it took some effort drawing from multiple sources, so I thought I'd document the steps I took here, all in one place.

Setup a Host

Arc runs on top of MzScheme, which means you can't just run it on top of any old web host. Loosely following Liperati's tutorial on setting up a Scheme web server, I signed up for virtual hosting with Linode.

Once I signed up for Linode, I signed in and used their Linux Distribution Wizard to deploy a distribution. I chose Ubuntu 7.10 somewhat arbitrarily, but it saved a few steps installing MzScheme later. (You don't have to build it from source.)

Once my distro was deployed, which only took a few minutes, I booted my server and ssh-ed in. From there, I updated my system with apt-get. (The -y option automatically accepts, so if you'd rather get prompted before installs, omit this option.)
apt-get -y update
apt-get -y upgrade
apt-get -y install openssl
I found out (the hard way) that the news app depends on openssl, so you might as well install it now.

Install MzScheme

According to the Arc install page, Arc requires MzScheme version 352. I'm not sure if this is completely up to date, as I've heard people successfully use version 360. But I don't want to have to deal with issues, so I just used 352.
chmod a+x
See Steve Morin's Arc Installation for what that looks like. I accepted the defaults and installed system links.

Install Arc Itself

It turns out there are some bugs in the latest release of Arc (Arc2 as of this writing), and if you try to use it out of the box, you'll run in to a few problems. Instead, you'll want to download Anarki.

It's in a git repository, so you'll have to install git.
apt-get -y install git-core
Run the following to actually get a working copy of Arc and the news app.
git clone git://
There are some experimental (and unofficial) features of Arc in Anarki. I decided I wanted a stable version of Arc in the hopes that any code I add won't break in the next version. To use the stable branch, cd into the working directory and run the following commands.
cd arc
git branch stable origin/stable
git checkout stable

Run Arc

To run Arc, use the following command from the arc directory.
mzscheme -m -f as.scm
You should see the following with an Arc prompt.
Use (quit) to quit, (tl) to return here after an interrupt.

Start the News App

To run the news app, simply type (nsv) at the Arc prompt. You'll see something like the following printed back to you.
load items:
load users:
ready to serve port 8080
You should now be able to visit your news app by going to "http://<your-host-ip>:8080/news".

However, if you want to be able to modify your code at the REPL while the web server is running, run the news app in a separate thread and bind it, like so:
(= app (thread (nsv)))
The Arc prompt will come back to you, and you can simply re-bind symbols to modify them. Then, when you want to kill the app, use the following.
(break-thread app)
At any time at the Arc REPL, you can type (quit) to exit to your shell. You can also press Control-C to break into the Scheme REPL, where (exit) exits and (tl) returns to the Arc prompt.

While I was mucking with the source, I found Arcfn's index of Arc functions to be helpful. I have also been using screen to detach the process from the shell and allow the server to run continuously after logging out.

That's it. I hope someone finds this helpful.

No comments: