Skip to content

Instantly share code, notes, and snippets.

@m2ym
m2ym / sqcamlite-concept.ml
Created January 13, 2011 14:26
SQCamLite Design Concept
open Sqlite3
module ExtList = struct
include List
let iteri f list =
let rec iteri f n = function
| [] -> ()
| x::xs -> f n x; iteri f (n+1) xs
in
(defun f () :foo)
(defun g () (funcall #'f))
(setf (symbol-function 'f) (lambda () :bar))
(g) ; => :FOO or :BAR
@m2ym
m2ym / ccl.bash
Created March 7, 2011 08:48
A wrapper shell script for Clozure CL
#!/bin/bash
CCL_HOME="$HOME/opt/ccl"
OS="$(uname -s)"
MARCH="$(uname -m)"
if [ "$OS" = Linux ]; then
if [ "$MARCH" = x86_64 ]; then
bin=lx86cl64
@m2ym
m2ym / enum-bench.lisp
Created April 20, 2011 09:36
(member ...) vs (typep x '(member ...)
(in-package :cl-user)
(declaim (optimize (speed 3)))
(defconstant n 1000000)
(defconstant m 10000)
;; Use alexandria:define-constant if you have a problem
(defconstant enum-const (loop repeat 1000 collect (random m)))
(defvar enum-var enum-const)
@m2ym
m2ym / objective_list.ml
Created July 14, 2011 07:22
Objective List and map method implementation in OCaml
module OList = struct
type 'a recv = {
send : 'b. <
iter : ('a -> unit) -> unit;
map : ('a -> 'b) -> 'b recv
>
}
type 'a t = 'a recv
let rec of_list : 'a. 'a list -> 'a t =
@m2ym
m2ym / pa_visitor.ml
Created July 18, 2011 08:58
Generate visitor code using camlp4 + type-conv
open Camlp4
open PreCast
open Ast
open Pa_type_conv
let pp_ctyp =
let module PP = Camlp4.Printers.OCaml.Make (Syntax) in
let pp = new PP.printer () in pp#ctyp
@m2ym
m2ym / ksprintf.ml
Created July 29, 2011 04:05
Format.ksprintf in my mind
let ksprintf f fmt =
let buf = Buffer.create 16 in
Format.kfprintf
(fun ppf ->
Format.pp_print_flush ppf ();
f (Buffer.contents buf))
(Format.formatter_of_buffer buf)
fmt
let () =
@m2ym
m2ym / anything-kill-bufferss.el
Created August 3, 2011 12:17
Fixed version anything-kill-buffers
(defun anything-kill-buffers ()
"Preconfigured `anything' to kill buffer you selected."
(interactive)
(anything
'(((name . "Kill Buffers")
(type . buffer)
(candidates . anything-c-buffer-list)
(action
("Kill Buffer" . (lambda (candidate)
(kill-buffer candidate)
@m2ym
m2ym / with-open-file-atomically.lisp
Created August 26, 2011 13:16
WITH-OPEN-FILE-ATOMICALLY
(defmacro with-open-file-atomically-1 ((var filename . args) &body body)
(alexandria:once-only (filename)
(alexandria:with-gensyms (tempfile stream done)
`(let ((,tempfile (merge-pathnames ".tem" ,filename)) ,stream ,done)
(unwind-protect
(multiple-value-prog1
(let ((,var (setq ,stream (open ,tempfile :if-exists :error ,@args))))
,@body)
(setq ,done t))
(when ,stream
@m2ym
m2ym / .cl.lisp
Created September 9, 2011 11:02
Common Lisp startup file
(in-package :cl-user)
#+(or sbcl openmcl)
(progn
(declaim (optimize (debug 3)))
(when (find-package :quicklisp)
(defun :qa (&rest args)
(apply (find-symbol "SYSTEM-APROPOS" :ql) args))