Skip to content

Instantly share code, notes, and snippets.

@kurohuku
kurohuku / sharp-backquote-reader.lisp
Created November 24, 2010 07:15
sharp-backquote-reader
(asdf:oos 'asdf:load-op :kmrcl)
(defun |#`-reader| (stream ch numarg)
(declare (ignore ch numarg))
(let (acc-fmt acc-args)
(loop
:for curr = (read-char stream)
:until (char= curr #\`)
:do
(if (char= curr #\\)
(asdf:oos 'asdf:load-op :cl+ssl)
(in-package :asdf-install)
(setf (symbol-function 'make-stream-from-url-old)
#'make-stream-from-url)
(setf (symbol-function 'url-host-old)
#'url-host)
(setf (symbol-function 'url-port-old)
(defvar *test-function-table* (make-hash-table))
;; clause -> ((arg1 arg2 ... ) result) = ((arg1 arg2 ... ) :eq result)
;; clause -> ((arg1 arg2 ... ) :not result)
;; clause -> ((arg1 arg2 ... ) :test test-fn)
(defparameter *test-report-function*
#'(lambda (fn-name args expected actual)
(format t "TEST FAILED. Form: (~A ~{~A~^ ~}), Expected: ~A, Actual: ~A~%"
fn-name args expected actual)))
(defmacro with-collects ((&rest syms) &body body)
(labels
((collector-expander (sym gtail)
`(,sym (arg)
(if (null ,sym)
(progn
(setf ,sym (cons arg nil))
(setf ,gtail ,sym)
arg)
(let ((last (cons arg nil)))
@kurohuku
kurohuku / named-let.lisp
Created November 16, 2010 07:45
named-let
(defmacro named-let (name binds &body body)
`(labels
((,name ,(mapcar #'car binds)
,@body))
(,name ,@(mapcar #'second binds))))
@kurohuku
kurohuku / jni_test.c
Created November 10, 2010 03:00
jni from c
#include <stdio.h>
#include <jni.h>
int main(){
JNIEnv *env;
JavaVM *jvm;
int res;
jclass clazz;
jmethodID mid;
jmethodID mid_to_str;
(defparameter *self* nil)
;; `class-name` property list -> { :metaclass-symbol, :member-variables, :class-variables, :attributes}
(defmacro class (name super &body body)
(let ((member-vars (collect-member-vars name body))
(class-vars (collect-class-vars name body))
(metaclass-name (get-metaclass-symbol name)))
(multiple-value-bind (methods inits attributes) (parse-body body)
;; method -> (def name (args) body)
@kurohuku
kurohuku / test.lsip
Created November 2, 2010 01:41
test
(defpackage net.phorni.unit-test
(:use :cl)
(:shadow cl:assert)
(:nicknames :utest)
(:export test-error
assert
define-condition
do-as-test
*unit-test-error-port*
*default-assert-error-message*
@kurohuku
kurohuku / generic.lisp
Created November 1, 2010 04:35
ref , size
(defun defmethods-args-expander (args specifiers)
(when (< (length args) (length specifiers))
(error "Too many specifiers"))
(labels
((inner (ar sr acc)
(if (null ar)
(nreverse acc)
(inner (cdr ar)
(cdr sr)
(defclass promise ()
((action :initarg :action :initform (error "Required :action"))
(is-called-p :initform nil)
(result :initform nil)))
(defmacro delay (action)
`(make-instance 'promise :action (lambda () ,action)))
(defun force (promise)