This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) | |
;;; 普通递归版本 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun loop-random (times) | |
(with-output-to-string (*standard-output*) | |
(loop | |
:for i :from 1 :to times | |
:do (format t "~A" (random 10))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void func(int data) { | |
long time = getTime(); // 如果没有惰性,那么这里一定会被求值。 | |
switch(data) { | |
case 1: | |
funcNeedTime1(data, time); // 需要使用time变量 | |
break; | |
case 2: | |
funcNeedTime2(data, time); // 需要使用time变量 | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 这是《Lisp in Small Piece》上第9页的eprogn函数的定义,实际上这样子的定义 | |
;;; 是为了可以让调用eprogn的返回值可以是最后一个被求值的表达式。 | |
(define (eprogn exps env) | |
(if (pair? exps) | |
(if (pair? (cdr exps)) | |
(begin (evaluate (car exps) env) | |
(eprogn (cdr exps) env)) | |
(evaluate (car exps) env)) | |
'())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 下面的函数定义中参数c没有使用到,在我的系统上使用SBCL,在TopLevel中输入下面的表达式会抛出警告,说变量c没有使用。 | |
(defun my-plus (a b c) | |
(if (zerop b) | |
a | |
(my-plus (1+ a) (1- b) nil))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :com.liutos.del0-interp | |
(:use :cl) | |
(:nicknames :del0-interp | |
:interp)) | |
(in-package :interp) | |
(defvar *env0* '()) | |
(defun ext-env (x v env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :com.liutos.max-incseq | |
(:use :cl) | |
(:nicknames :max-incseq) | |
(:documentation "计算一个序列的最长递增子序列")) | |
(in-package :max-incseq) | |
(defun max-incseq/aux (vec) | |
"返回中间结果的数组,存储了到达各个数的最长递增子序列的长度。" | |
(declare (type vector vec)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :com.liutos.editance | |
(:use :cl)) | |
(in-package :com.liutos.editance) | |
(defmacro for ((var start end) &body body) | |
`(do ((,var ,start (1+ ,var))) | |
((> ,var ,end)) | |
,@body)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let maxSubseq seq = | |
let aux = Array.create (Array.length seq) 0 | |
and len = Array.length seq | |
and iStart = ref 0 | |
and iEnd = ref 0 | |
and max = ref 0 | |
in | |
begin | |
aux.(0) <- seq.(0); | |
max := seq.(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* main.c | |
* | |
* | |
* | |
* Copyright (C) 2012-10-01 liutos | |
*/ | |
#include "type.h" | |
#include <stdio.h> |