A place where I capture raw, quick notes worth remembering.

October 12, 2022

emacs wsl

Emacs on Windows WSL2

So, it turns out that WSL2 is actually kind of neat, where it runs a Linux image at almost native speed, and also supports Wayland.

So, what’s the first thing you do in WSL2? Install Emacs of course!

Below is the script I use to install Emacs on an Ubuntu image.

To know what the latest stable version on master is, I look at this Github issue from Jim Myhrberg, who keeps track of those.

# Checkout Emacs
$ git clone git://git.sv.gnu.org/emacs.git

# Checkout latest stable version, see note above.
$ git checkout 8febda4

# Vanilla Emacs requirements
$ sudo apt install build-essential autoconf libgtk-3-dev libgnutls28-dev libtiff5-dev libgif-dev libjpeg-dev libpng-dev librsvg2-dev libxpm-dev libncurses-dev texinfo adwaita-icon-theme-full

# Native compilation requirements
$ sudo apt install libgccjit-11-dev

# Required for Native JSON
$ sudo apt install libjansson4 libjansson-dev

# Required for tree-sitter support
$ sudo apt install libtree-sitter-dev

$ cd emacs
$ export CC=/usr/bin/gcc-11 CXX=/usr/bin/gcc-11
$ ./autogen.sh
$ ./configure --with-pgtk --with-native-compilation --with-tree-sitter --with-json --without-pop
$ make -j$(nproc)
$ sudo make install

And, sometimes when you update the repository, it refuses to build. I usually fix that with running make bootstrap er make distclean.

Permalink

September 7, 2022

wsl

Syncthing on WSL2

I like to use Syncthing to sync files between accounts and machines, and now even between my Windows subsystem and Windows itself.

To run Syncthing on WSL I use this script:

#!/usr/bin/env bash
SERVICE="syncthing"
USER="petar"
PORT=2103
OPTS="
        --no-browser
        --home=/home/$USER/.config/syncthing
        --gui-address=http://127.0.0.1:$PORT
        --logfile=/home/$USER/.config/syncthing/syncthing.log
"

if ! pgrep -x "$SERVICE" >/dev/null
then
        daemonize /usr/bin/syncthing serve "$OPTS"
fi

Make sure to change your username and to make the port unique, if you run multiple Syncthings on your machine.

Permalink

September 5, 2022

rust

Rust Analyzer from Source

I’m developing on a FreeBSD machine and rust-analyzer is not available as a pre-build release.

Luckily, it’s easy to build rust-analyzer from source. Just clone the repository and run:

cargo xtask install --server

I’m on Emacs, so I only need the server, hence the --server argument. If you are using Visual Studio Code, don’t add it.

Permalink

June 10, 2022

lisp quicklisp

How to install Quicklisp

Before starting, make sure you have installed SBCL. Then, get the quicklisp file, which lets you bootstrap and install Quicklisp.

cd ~/downloads
curl -O http://beta.quicklisp.org/quicklisp.lisp
sbcl --load quicklisp.lisp

Now you are in the REPL, and you can install Quicklisp. By default, it will be installed in ~/quicklisp, but I like to keep my home directory clean and install it in ~/.local/share/quicklisp. Thus the :path argument.

(quicklisp-quickstart:install :path "~/.local/share/quicklisp/")

I also prefer Quicklisp to be available when I start SBCL, so I add it to my init file:

(ql:add-to-init-file)

That’s it! Happy Lisping!

Permalink

May 10, 2022

lisp asdf

Switch the current working directory in the REPL

If you start a REPL in the wrong directory, you can switch it by using UIOP.

UIOP is the portability layer of ASDF, supplying an abstraction on top of different implementations or OS’es.

For example, to change to a new project do:

(uiop:chdir "~/lisp/fangorn/")

Permalink

Make your own packages available to Quicklisp

In Lisp it’s quite common to have your own helper libraries, which are packaged as ASDF packages. To be able to use your libraries in other projects, you need to let ASDF know how to find them.

First create the directory ~/.config/common-lisp/source-registry.conf.d/

There create a file with any name of your choice but with the type conf, for instance 50-petar-lisp.conf.

In this file, add the following line to tell ASDF to recursively scan all the subdirectories under /home/petar/lisp/ for .asd files: (:tree "/home/petar/lisp/").

Permalink

May 9, 2022

lisp

Template for a new Common Lisp Project

To easily start a new Common Lisp project, I’m making use of the CL-Project from the famed Lisper Eitaro Fukamachi.

You can either install it through roswell with ros install cl-project or through the use of Quicklisp with (ql:quickload :cl-project).

The benefit of install it through Roswell is that you also get a binary.

To create a project through the REPL:

(cl-project:make-project #p"lisp/cl-sample/"
  :author "Eitaro Fukamachi"
  :email "[email protected]"
  :license "LLGPL"
  :depends-on '(:clack :cl-annot))

Or by using the binary:

make-project /home/user/common-lisp/sample \
    --name sample \
    --description "sample project." \
    --author "Your name" --license LLGPL \
    --depends-on alexandria split-sequence`

Permalink

April 14, 2022

rust

Cargo modules

Today I learned about the cargo-modules, a cargo plugin which shows you an overview of your crates modules.

I like to check the tree and my public interface with:

cargo modules generate tree --with-types

Permalink

January 2, 2022

command-line fish

November 15, 2021

lisp ai

From Lisp to Python, but why Peter?

Peter Norvig is a well-known educator on AI and used to be one of the key figures in the Lisp movement.

His books used to use Lisp in their exercises, but he switched to Python at some point. Today, I came across the Lex Fridman podcast, where he interviewed Peter Norvig and asked him why he made that change.

He gives a surprisingly simple answer at the 43-minute mark.

I was expecting deeper reasons, but his students were having difficulty grasping Lisp, and a questionnaire showed that Python mimicked the pseudocode from the book the most. That’s it.

In the short amount of time he had to educate them on AI, he could not spare the time to educate them on Lisp.

Coincidentally, I also came across this gem at smuglispweeny blog:

At ILC 2002 former Lisp giant now Python advocate Peter Norvig was for some reason allowed to give the keynote address like Martin Luther leading Easter Sunday mass at the Vatican and pitching Protestantism because in his talk Peter bravely repeated his claim that Python is a Lisp.

When he finished Peter took questions and to my surprise called first on the rumpled old guy who had wandered in just before the talk began and eased himself into a chair just across the aisle from me and a few rows up.

This guy had wild white hair and a scraggly white beard and looked hopelessly lost as if he had gotten separated from the tour group and wandered in mostly to rest his feet and just a little to see what we were all up to. My first thought was that he would be terribly disappointed by our bizarre topic and my second thought was that he would be about the right age, Stanford is just down the road, I think he is still at Stanford – could it be?

“Yes, John?” Peter said.

I won’t pretend to remember Lisp inventor John McCarthy’s exact words which is odd because there were only about ten but he simply asked if Python could gracefully manipulate Python code as data.

“No, John, it can’t,” said Peter and nothing more, graciously assenting to the professor’s critique, and McCarthy said no more though Peter waited a moment to see if he would and in the silence a thousand words were said.

Permalink