关于'抄袭'这个事情,事实上我们(lispers)有三个观点: 1,很多语言抄袭了最初来自LISP的特性; 2,没有一种语言在抄袭时抄到了该LISP特性的精髓; 3,即使没抄到精髓却也已经够用了; ——————田春冰河
首先要看着顺眼,再来考虑语言特性什么的。 ——————E.T
;;; 换个思路? | |
;;; 先算出一百万以下的所有素数 | |
;;; 基于这个素数表,对每一个数字d都进行快速的因数分解 | |
;;; 得到数字d的质因数后,用筛法计算出互质的数字的个数 | |
(defun generate-prime-numbers (limit) | |
"计算出所有不大于LIMIT的素数。" | |
(let ((bitmap (make-array limit :initial-element 1)) | |
(result '())) | |
(dotimes (i limit (nreverse result)) | |
(let ((ele (aref bitmap i))) |
(ql:quickload 'cl-ppcre) | |
(defun all-first-registers-to-strings (regex target-string) | |
"返回TARGET-STRING中所有匹配正则表达式REGEX的字符串属于第一个register的内容。" | |
(check-type regex string) | |
(check-type target-string string) | |
(let ((pos 0) | |
(strs '())) | |
(loop | |
(multiple-value-bind (start end register-begins register-ends) |
;;;; Code Examples but the language wasn't implemented yet. | |
;;; 定义函数factorial | |
defun factorial (n) ;; 注释以两个分号开始,至一行的末尾结束。 | |
if 0 = n ;; 表示两个对象之间的关系的函数用中缀形式表示 | |
1 | |
n * factorial(n - 1) ;; if的alternate部分的表达式比起consequence的部分向左移动一个空格,但是其实并非像Python那样用缩进决定语法结构。 | |
;;; 尾递归版本的factorial,使用了内部的辅助函数。 | |
;;; 可以这样表达的内部函数需要语言支持词法作用域,并且defun也应该是这样的,而不是像CL那样定义全局函数。 |
#include <stdio.h> | |
#include <stdlib.h> | |
#define MASK 0x8000 | |
// 计算一个字节中最高位开始的连续为1的位的数量 | |
int count1(char byte) { | |
int count = 0; | |
while ((byte & MASK) == MASK) { | |
count++; |
(defun parse-params (s) | |
(labels ((aux (acc s) | |
(declare (optimize (speed 3))) | |
(let ((i1 (position #\= s)) | |
(i2 (position #\& s))) | |
(cond (i1 (aux (cons (cons (intern (string-upcase (subseq s 0 i1))) | |
(decode-param (subseq s (1+ i1) i2))) | |
acc) | |
(and i2 (subseq s (1+ i2))))) | |
((equal s "") nil) |
关于'抄袭'这个事情,事实上我们(lispers)有三个观点: 1,很多语言抄袭了最初来自LISP的特性; 2,没有一种语言在抄袭时抄到了该LISP特性的精髓; 3,即使没抄到精髓却也已经够用了; ——————田春冰河
首先要看着顺眼,再来考虑语言特性什么的。 ——————E.T
typedef enum { | |
LPARENTHESIS, | |
RPARENTHESIS, | |
SYMBOL_TOKEN, | |
EOF_TOKEN, | |
}; | |
void consume(lexer_t lexer) | |
{ | |
if (lexer->c != '\0') { |
(* 定义变量a的值为1 *) | |
let a = 1 | |
(* 定义匿名函数,接收一个整数作为参数,返回结果为其参数的两倍 *) | |
function x -> x*2 | |
(* 定义名为doubel的函数,功能和上面的匿名函数相同 *) | |
let double = function x -> x*2 | |
(* 等价的写法,即语法糖 *) | |
let double x = x*2 |
(truncate 10 3) ;一般情况下返回值为3,即10除以3的商,余数被丢弃了。 | |
(multiple-value-bind (q r) | |
(truncate 10 3) | |
(format t "~D and ~D" q r)) ;输出结果为"3 and 1"。truncate实际上是会返回 | |
;多个值(即多重返回值)的一个函数,不过一般只会得 | |
;到一个,所以要用宏multiple-value-bind来捕捉 | |
;所有的返回值。相当于把(truncate 10 3)的第一个 | |
;返回值赋值给了q,第二个赋值给了r。 |
(defpackage :com.liutos.binary-tree | |
(:use :cl)) | |
(in-package :com.liutos.binary-tree) | |
(defclass tree-node () | |
((value :initarg :value | |
:accessor tree-node-value) | |
(left :initarg :left | |
:accessor tree-node-left) |