Skip to content

Instantly share code, notes, and snippets.

View flambard's full-sized avatar

Markus Flambard flambard

  • Ping Payments
  • Örebro, Sweden
View GitHub Profile
@flambard
flambard / use.lisp
Created February 24, 2016 15:19
Implementation of the 'use' construct described in the video Object-Oriented Programming is Bad by Brian Will
(defmacro precompiled-lambda (lambda-list &body body)
(compile nil `(lambda ,lambda-list ,@body)))
(defmacro use ((&rest vars) &body body)
`(funcall (precompiled-lambda ,vars ,@body) ,@vars))
@flambard
flambard / chip-8-program.lisp
Last active August 29, 2015 13:57
Macro for recompiled chip-8 code.
(defmacro chip-8-program (subroutines &body code)
`(let ((v0 0) (v1 0) (v2 0) (v3 0) (v4 0) (v5 0) (v6 0) (v7 0)
(v8 0) (v9 0) (vA 0) (vB 0) (vC 0) (vD 0) (vE 0) (vF 0)
(I 0) (DT 0)
(memory (make-ram)))
(declare (type (unsigned-byte 16) I))
(declare (type (unsigned-byte 8) DT
v0 v1 v2 v3 v4 v5 v6 v7
v8 v9 vA vB vC vD vE vF))
(labels ,subroutines
@flambard
flambard / defun-multi.lisp
Created March 19, 2014 21:33
Naive implementation of multi-arity defun in CL.
(defmacro defun-multi (name &body clauses)
(let ((vars-sym (gensym "VARS")))
`(defun ,name (&rest ,vars-sym)
(ecase (length ,vars-sym)
,@(loop
for (vars . body) in clauses
collect `(,(length vars)
(destructuring-bind ,vars ,vars-sym ,@body))))) ))
@flambard
flambard / optima-simple-vector.lisp
Last active August 29, 2015 13:55
Pattern matching simple vectors in Optima.
(defstruct (simple-vector-pattern (:include constructor-pattern)
(:constructor make-simple-vector-pattern (&rest subpatterns))))
(defmethod destructor-equal ((x simple-vector-pattern) (y simple-vector-pattern))
(= (constructor-pattern-arity x)
(constructor-pattern-arity y)))
(defmethod destructor-predicate-form ((pattern simple-vector-pattern) var)
`(typep ,var '(simple-vector ,(constructor-pattern-arity pattern))))
@flambard
flambard / timelog.el
Created May 31, 2010 12:04
Extension to GNU Emacs timeclock that I use at work.
(require 'timeclock)
(require 'cl)
(defun timelog-read-date ()
(save-excursion
(beginning-of-line)
(buffer-substring-no-properties (+ 2 (point)) (+ 12 (point)))))
(defun timelog-read-time (&optional use-current-time-if-eobp)
(if (and (eobp) use-current-time-if-eobp)
@flambard
flambard / match.lisp
Created May 29, 2010 20:08
MATCH macro for Common Lisp
;; MATCH -- A CASE-like construct with pattern matching.
;; Syntax:
;;
;; (match expr
;; (pattern1 . body1)
;; (pattern2 . body2)
;; ...
;; (patternN . bodyN))
;;