Fork me on GitHub
lkl的博客


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 日程表

  • 站点地图

land of lisp 笔记

发表于 2018-10-24 | 分类于 lisp

land of lisp note

by lkl

section 1

chapter 1-2

定义全局变量:
(defparameter small 1)
(defvar small 2)

定义局部变量:

1
2
3
4
5
6
(let (variable declarations)
...body...)
> (let ((a 5)
(b 6))
(+ a b))
11

ash(arithmetic shift functionv),算数位移方法,

1
2
3
4
5
> (ash 11 1)
22

> (ash 11 -1)
5

1
2
3
4
> (let ((a 5)
(b 6))
(+ a b))
11

chapter 3

定义全局函数

1
2
> (defun function_name (arguments) 
...)

定义局部函数

1
2
3
4
5
6
7
8
(flet ((function_name (arguments)       
...function body...))
...body...)

> (flet ((f (n)
(+ n 10)))
(f 5))
15

比较两个符号是否相同:

1
2
> (eq 'fooo 'FoOo)
T

求幂:

1
2
> (expt 53 53)
24356848165022712132477606520104725518533453128685640844505130879576720609150223301256150373

显示字符串:

1
2
3
> (princ "Tutti Frutti")
Tutti Frutti
"Tutti Frutti"

链接任何两个数据(无论类型):

1
2
3
4
5
6
> (cons 'chicken 'cat)
(CHICKEN . CAT)
> (cons 'pork (cons 'beef (cons 'chicken ())))
(PORK BEEF CHICKEN)
> (cons 'pork '(beef chicken))
(PORK BEEF CHICKEN)

从第一个cell中取出元素:

1
2
> (car '(pork beef chicken))
PORK

从第二个cell或剩下所有cell中取出元素:

1
2
> (cdr '(pork beef chicken))
(BEEF CHICKEN)

可以将car和cdr串联到cadr,cdar或cadadr等新功能中。 可以简洁地从复杂列表中提取特定数据。 输入cadr与使用car和cdr一样,它从列表中返回第二项。 (第二个cons单元格的第一个cell将包含该项目。)看一下这个例子:

1
2
3
4
5
6
7
8
> (cdr '(pork beef chicken))
(BEEF CHICKEN)
> (car '(beef chicken))
BEEF
> (car (cdr '(pork beef chicken)))
BEEF
> (cadr '(pork beef chicken))
BEEF

在这里注意:

1
2
> (cddddr '(pork beef chicken fish apple orange ))
(APPLE ORANGE)

c*r最多可达四级。

这里成功取出了最后两个元素,但是当按照同样的方法取最后一个元素时:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
> (cdddddr '(pork beef chicken fish apple orange ))

*** - EVAL: undefined function CDDDDDR
The following restarts are available:
USE-VALUE :R1 Input a value to be used instead of (FDEFINITION 'CDDDDDR).
RETRY :R2 Retry
STORE-VALUE :R3 Input a new value for (FDEFINITION 'CDDDDDR).
ABORT :R4 Abort debug loop
ABORT :R5 Abort debug loop
ABORT :R6 Abort debug loop
ABORT :R7 Abort debug loop
ABORT :R8 Abort debug loop
ABORT :R9 Abort debug loop
ABORT :R10 Abort debug loop
ABORT :R11 Abort debug loop
ABORT :R12 Abort debug loop
ABORT :R13 Abort debug loop
ABORT :R14 Abort debug loop
ABORT :R15 Abort debug loop
ABORT :R16 Abort debug loop
ABORT :R17 Abort main loop

构建列表:

1
2
> (list 'pork 'beef 'chicken)
(PORK BEEF CHICKEN)

以下三种创建列表的方式没有区别:

1
2
3
4
5
6
> (cons 'pork (cons 'beef (cons 'chicken ())))
(PORK BEEF CHICKEN)
> (list 'pork 'beef 'chicken)
(PORK BEEF CHICKEN)
> '(pork beef chicken)
(PORK BEEF CHICKEN)

section 2

chapter 4

java 套接字

发表于 2018-05-24 | 分类于 java

java.net Socket:

阅读全文 »

js的两种属性

发表于 2018-03-08 | 分类于 javascript

javascript创建对象

1. 工厂模式

函数内创建Object,并通过函数传入参数构建各属性,最后返回该Object.

1
2
3
4
5
6
7
8
9
10
11
12
function createPerson(name, age, job){
var o = new Object();
o.name = name;
o.age = age;
o.job = job;
o.sayName = function(){
alert(this.name);
};
return o;
}
var person1 = createPerson("Nicholas", 29, "Software Engineer");
var person2 = createPerson("Greg", 27, "Doctor");

2. 构造函数模式

1
2
3
4
5
6
7
8
9
10
11
12
function createPerson2(name,age,job)
{
this.name = name;
this.age = age;
this.sayName = function(){
alert(this.name);
}
}

var p1 = new createPerson2("lilin",22);
alert(p1.name);
p1.sayName();

js的两种属性

发表于 2018-03-08 | 分类于 javascript

js中包括两种属性:数据属性和访问器属性

阅读全文 »

java布局管理器

发表于 2018-02-06 | 分类于 java

java awt 布局管理器

FlowLayout布局管理器

在FlowLayout布局管理器中组件像水流一样向某方向流动,遇到边界就会折回,重头开始排列。默认从左往右排列。Panel和Applet默认使用FlowLayout布局管理器。

FlowLayout有三个构造器:

  • FlowLayout(): 使用默认对齐方式、默认垂直、水平间距创建FlowLayout布局管理器。

  • FlowLayout(int align): 使用指定对齐方式、默认垂直、水平间距创建FlowLayout布局管理器。

  • FlowLayout(int align,int hgap,int vgap): 使用指定对齐方式、指定垂直、水平间距创建FlowLayout布局管理器。

align表明FlowLayout中组件的排列方向,该参数使用FlowLayout类的静态常量:FlowLayout.LEFT、FlowLayout.CENTER、FlowLayout.RIGHT。

阅读全文 »

Hello World

发表于 2018-01-23

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

lkl

lkl

6 日志
3 分类
GitHub
© 2018 lkl
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.4