Skip to content

Instantly share code, notes, and snippets.

@zacque0
zacque0 / if.lisp
Last active July 18, 2025 00:24
"IF-" by RUDYARD KIPLING
;; My comment to https://old.reddit.com/r/lisp/comments/1m1bezg/kiplings_if_art_poetry_and_lisp_a_challenge/
(defpackage "IF- by RUDYARD KIPLING"
(:use "CL"))
(in-package "IF- by RUDYARD KIPLING")
(defvar *you*)
(defmacro *you* (&body body)
@zacque0
zacque0 / longest-length-1.c
Last active January 21, 2025 05:56
CL's read-char vs C's getchar
// Modified version of: https://github.com/soffes/k-and-r/blob/master/examples/1.9-1.c
// Compile with the command: gcc longest-length.c
#include <stdio.h>
#define MAXLINE 1000 // Maximum input line size
// Note: renamed from `getline` to `gline` since `getline` is already defined
int gline(char line[], int maxline);
void copy(char to[], char from[]);
@zacque0
zacque0 / main.org
Created April 13, 2022 14:19
GNU Guix and SBCL CFFI

A simple note about how GNU Guix and SBCL CFFI can work together to easily write a wrapper around the shared library.

guix shell sbcl sbcl-cffi sbcl-slime-swank sqlite

Then you need to invoke from shell with preceding LD_LIBRARY_PATH=…:

LD_LIBRARY_PATH="$GUIX_ENVIRONMENT/lib" sbcl --eval '(require :asdf)' --eval '(asdf:load-system :swank)' --eval '(swank:create-server :dont-close t)' --eval '(asdf:load-system :cffi)'
@zacque0
zacque0 / encoder.sml
Last active November 21, 2021 07:34
Standard ML Simple Unicode Codepoint -> UTF-8 Encoder
(* Algorithm based on http://www.herongyang.com/Unicode/UTF-8-UTF-8-Encoding-Algorithm.html *)
exception EncodeError
(* Take a code point as input, and encode it into a list of bytes using UTF-8. *)
fun encodeUTF8 (codepoint : int) : Word.word list =
let val andb = Word.andb
val orb = Word.orb
val >> = Word.>>
val fromInt = Word.fromInt
infix andb orb >>