Thursday | 21 NOV 2024
[ previous ]
[ next ]

Book of Hare

Title:
Date: 2023-11-11
Tags:  languages

Table of Contents

  1. Impetus
  2. Installation

I learned about hare just before it was announced, and it was fun to see the reaction from the masses. Most people seemed to be interested but not sure what it was for and I still think that. To me it seems like the language exists becase Drew DeVault wants it to exist which is a reason I can get behind.

I saw some code examples before but I didn't look super closely. I took a look now after someone mentioned that the error handling in hare is pretty good. I wanted to see how it was and compare it to zig as I really like zig's method of using the try and if not forcing the catch. The ! operator is also nice now that I'm getting used to it.

Hare Introduction Tutorial

Hare Blog

Impetus

What got me to create this page for Hare is that I looked at the error example and learned 2 things in a 4 line piece that just tests the example code.

$ hare run main.ha example.txt      # should work
$ mkdir test && chmod -w test       # make a directory we cannot write to
$ hare run main.ha test/example.txt # os::create fails
$ hare run main.ha /dev/full        # io::write fails

I never noticed that chmod takes the + to signify that it is adding that permission. In this case -w is taking away the write permission.

I never knew about /dev/full and that one just blew my mind when I checked my server. I actually thought maybe this was new. Stunned by it.

This is probably a sign that I should just run through the Hare tutorial because I'll probably learn a few things. This is similar to why I did the nasm tutorial. I didn't end up using it much but the logic of running a web server really crystalized when I followed that tutorial.

Installation

The installation instructions are a bit bare. I realized that I already installed hare before so I blew those directories away and did a fresh install so that I could get the latest version of things.

Installation Page

It isn't very helpful so I wrote up the steps that I took to get hare installed and usable.

Install the qbe backend:

git clone git://c9x.me/qbe.git
make
sudo make install

Install the docs:

git clone https://sr.ht/~sircmpwn/scdoc/
make
sudo make install

Install the bootstrap compiler:

git clone https://git.sr.ht/~sircmpwn/harec
cd harec
mkdir build
cd build
../configure
make
sudo make install

Now we can build hare:

git clone https://git.sr.ht/~sircmpwn/hare
cd hare
cp config.example.mk config.mk
make
sudo make install

Now we test it by compiling the example on the home page.

Save the below to main.ha:

use fmt;

export fn main() void = {
   const greetings = [
         "Hello, world!",
         "¡Hola Mundo!",
         "Γειά σου Κόσμε!",
         "Привіт, світ!",
         "こんにちは世界!",
   ];
   for (let i = 0z; i < len(greetings); i += 1) {
      fmt::println(greetings[i])!;
   };
};

Run it:

hare run main.ha

And to build it:

hare build -o example main.ha

With that we have hare installed and working!