Skip to content

Instantly share code, notes, and snippets.

View lukego's full-sized avatar

Luke Gorrie lukego

View GitHub Profile
(defun same (key-fn list &key (test #'eql))
"True if KEY-FN returns the same value for every element of LIST.
Example: (same #'length '((a b c) (d e f) #(1 2 3))) => T"
(or (null list)
(loop with v = (funcall key-fn (first list))
for x in (rest list)
always (funcall test v (funcall key-fn x)))))
@lukego
lukego / 0README.md
Last active July 4, 2024 15:49
CLIME installation instructions
(defun my-image-map-demo ()
(interactive)
(let ((buf (get-buffer-create "*image-map*")))
(with-current-buffer buf
(let* ((svg "<svg width=\"150\" height=\"150\"><g><rect x=\"25\" y=\"25\" width=\"50\" height=\"50\" fill=\"red\"></rect><rect x=\"75\" y=\"25\" width=\"50\" height=\"50\" fill=\"green\"></rect><rect x=\"25\" y=\"75\" width=\"50\" height=\"50\" fill=\"blue\"></rect><rect x=\"75\" y=\"75\" width=\"50\" height=\"50\" fill=\"yellow\"></rect></g></svg>")
(image-map '(((rect . ((25 . 25) . (75 . 75)))
area-red
(help-echo "red" pointer hourglass))
((rect . ((75 . 25) . (125 . 75)))
area-green
(with-output-to-emacs (s)
(loop for y from 0 to 500 by 100 do
(loop for x from 0 to 500 by 100 do
(with-output-as-presentation (s (alexandria:random-elt (list-all-packages)) t)
(draw-circle* s x y 40 :ink (make-contrasting-inks 8 (random 8)))))))
@lukego
lukego / bootstrap.nix
Last active May 4, 2021 06:06
Nix expressions for Lisp/Emacs
#! /usr/bin/env nix-shell
#! nix-shell bootstrap.nix --run generate
# This script uses ql2nix to generate dependency definitions as Nix
# expressions in the current directory. Quicklisp and all packages are
# installed in a temporary directory.
# Quicklisp packages default root set.
let default-packages = [
"1am"
@lukego
lukego / acid.svg
Created May 2, 2021 15:29
:map on SVG image not working
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Howdy!
I've started hacking on a SLIME frontend ("backend") for McCLIM. It's super early days but there's a WITH-OUTPUT-TO-EMACS macro that lets you use CLIM drawing commands and have the final result rendered as an inline image in the SLIME REPL.
There's lots to add e.g. a way to choose a CLIM command to execute and a way to click on presentations to select them as arguments. If anyone wants to help that would be most welcome!
The problem this solves is being able to write and debug CLIM code from the comfort of Emacs. It should also be suitable for writing user interfaces that don't need really fast response times (I'm planning to use it for a CAD drawing application in the style of KiCad.) The backend is based on SVG under the hood so in principle it could be made browser-friendly too.
Anyway! Initial demo screenshot attached & linked: https://imgur.com/a/4MdaXTb
; processing (DEFUN MEMBERV ...)
; file: /nix/store/b4hql89wrcfm1kmcsx8cnbi6fs69bjsy-nixlisp-bundle-1.0.0/lib/common-lisp/bundle/software/screamer-20190710-git/screamer.lisp
; in: DEFUN MEMBERV
; (DOLIST (SCREAMER::ELEMENT SEQUENCE)
; (SCREAMER::ATTACH-NOTICER! #'(LAMBDA () (COND (# #) (# #)))
; SCREAMER::ELEMENT))
; --> BLOCK LET SB-KERNEL:THE*
; ==>
; SEQUENCE
;
This file has been truncated, but you can view the full file.
these derivations will be built:
/nix/store/j0gms1jkhr1w98fnkb3g2gwlw8rcmiwx-nixlisp-bundle-1.0.0.drv
building '/nix/store/j0gms1jkhr1w98fnkb3g2gwlw8rcmiwx-nixlisp-bundle-1.0.0.drv'...
mkdir: cannot create directory '/homeless-shelter': Permission denied
unpacking sources
patching sources
configuring
no configure script, doing nothing
building
This is SBCL 2.1.2.nixos, an implementation of ANSI Common Lisp.