Skip to content

Instantly share code, notes, and snippets.

View Liutos's full-sized avatar

LiuTao Liutos

View GitHub Profile
@Liutos
Liutos / diary.jl
Created March 1, 2012 14:13
The content of my diary.jl script
sawfish-client -e '(display-message "写篇日记吧~")'
echo "Test" /tmp/test.txt
@Liutos
Liutos / defun-partial
Created April 21, 2012 06:25
定义能够进行一次自动partial apply的函数的宏及其辅助函数
(defun cons-lambda-expr (fn arglist rest-args)
(eval `(lambda ,rest-args
(apply ,fn (append ',arglist (list ,@rest-args))))))
(defmacro defun/partial (name arglist &body body)
(let ((args (gensym))
(func (gensym))
(argc (length arglist))
(arity (gensym))
@Liutos
Liutos / read-file-demo.lisp
Created June 15, 2012 05:49
Demo of reading file
(with-open-file (stream "/home/liutos/src/lisp/foo.lisp"
:direction :input)
(loop
(let ((line (read-line stream nil)))
(if line
(format t "~A~%" line)
(return)))))
2011-cufp-scribe-preprint.pdf
A Manual for Hyperref.pdf
A Users' Manual for MetaPost.pdf
Asymptote中的常见问题.pdf
Beamer Guide.pdf
Blender从入门到精通.pdf
Computability and Complexity.pdf
Concatenative Programming - ICSOFT.2009.pdf
Conky中文文档.pdf
C教程测试版第二章.pdf
@Liutos
Liutos / row->instance-of-class.lisp
Created June 26, 2012 01:40
The definition of macro ROW->INSTANCE-OF-CLASS
(defmacro row->instance-of-class (row class &body slots)
"Create an instance of class `class' filled with values extracted from `row'. The `slots' is a list of symbols. The symbols would be used as both the place indicator and each would converts to keyword symbol for using in a implicit MAKE-INSTANCE call."
(let ((_row_ (gensym))
(_class_ (gensym)))
`(let ((,_row_ ,row)
(,_class_ ,class))
(destructuring-bind ,slots ,_row_
(make-instance ,_class_
,@(mapcan #'(lambda (sym)
`(,(read-from-string
@Liutos
Liutos / cps.lisp
Created July 13, 2012 04:28
转换普通代码为CPS代码
(defun multinit-list (len init-fn)
(loop :for i :from 1 :upto len :collect (funcall init-fn)))
(defun split-funcall (form)
(let ((args (rest form)))
(values args
(let ((argv (multinit-list (length args) #'gensym)))
`(lambda ,argv ,(cons (first form) argv))))))
(defun append1 (list obj)
@Liutos
Liutos / cont-trans.lisp
Created July 20, 2012 02:37
实现了对非CPS的普通函数调用进行转换生成对应的CPS代码的函数cont-trans
(defpackage :cps
(:use :cl))
(in-package :cps)
(defun append1 (list obj)
(append list (list obj)))
(defun cps-symbol (op)
(intern (format nil "~S&" op)))
@Liutos
Liutos / compile-cps.lisp
Created July 20, 2012 03:27
将普通的函数调用表达式变换为更具过程式味道的代码
(defpackage :com.lt.compile-cps
(:use :cl)
(:export :compile-cps))
(in-package :com.lt.compile-cps)
;;; 当且仅当expr为括号表达式,并且第一个符号为应用于CPS的变体,即符号名字符串的最后一个字符为&时
;;; 才为真。
(defun cpsed-p (expr)
"Return non-nil if the EXPR has been processed by function CONT-TRANS defined
@Liutos
Liutos / wc.lisp
Created August 17, 2012 02:31
计算字符串中单词个数的函数word-count
(defun same-kind-chars (c1 c2)
(or (and (alpha-char-p c1)
(alpha-char-p c2))
(and (not (alpha-char-p c1))
(not (alpha-char-p c2)))))
(defun singleton-list (list)
(and list (null (cdr list))))
;;; 普通递归版本