摘要:深入链表(most on lists)The list data type has some more methods. Here are all of the methods of list objects:list.append(x)Add an item to the end of the list; equivalent toa[len(a):]=[x].list.extend(L)Extend the list by appending all the items in the given list; equivalent toa[len(a):]=L.list.insert(i,x 阅读全文
Why Functional Programming Matters
2013-11-17 01:26 by youxin, 517 阅读, 0 推荐, 收藏,
摘要:http://hi.baidu.com/lhurricane/item/35b57e12a1e3c5ddbf9042a7http://blog.csdn.net/ddwn/article/details/984390http://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf 阅读全文
函数fold 或reduce用法
2013-11-17 01:23 by youxin, 2097 阅读, 0 推荐, 收藏,
摘要:http://yi-programmer.com/2011-02-24_fold.htmlhttp://c2.com/cgi/wiki?FoldFunctionhttp://rwh.readthedocs.org/en/latest/chp/4.htmlThePythonLanguagecalls itreduce; this is a left fold: reduce(operator.add, [1,2,3,4]) reduce(lambda x,y: x+y, [1,2,3,4])You can get the effect of the parameter callediniti.. 阅读全文
Lisp之根源
2013-11-17 01:05 by youxin, 394 阅读, 0 推荐, 收藏,
摘要:原文:http://www.paulgraham.com/rootsoflisp.html约翰麦卡锡于1960年发表了一篇非凡的论文,他在这篇论文中对编程的贡献有如 欧几里德对几何的贡献.1他向我们展示了,在只给定几个简单的操作符和一个 表示函数的记号的基础上, 如何构造出一个完整的编程语言. 麦卡锡称这种语 言为Lisp, 意为List Processing, 因为他的主要思想之一是用一种简单的数据 结构表(list)来代表代码和数据.值得注意的是,麦卡锡所作的发现,不仅是计算机史上划时代的大事, 而且是一种 在我们这个时代编程越来越趋向的模式.我认为目前为止只有两种真正干净利落, 始终如一 阅读全文
scheme Continuation
2013-11-17 00:19 by youxin, 1496 阅读, 0 推荐, 收藏,
摘要:Continuation Pass Style在函数式编程(FP)中有一种被称为Continuation Passing Style(CPS)的风格。在这种风格的背后所蕴含的思想就是将处理中可变的一部分抽象为一个function,并将其作为一个参数传入。这是高度抽象的方法,所带来的表达的威力也是无与伦比的。下面举一个例子,实现CPS描述的fold函数。在此之前需要简单介绍一下fold概念,在FP中这是一个非常有效的处理list的工具。一般它的signature是fold(f,initial,list)。它所对应的效果是:f(e0,f(e1,….f(en,initial)…),e0到en也就是l 阅读全文
scheme 宏macro写法
2013-11-16 23:20 by youxin, 4653 阅读, 0 推荐, 收藏,
摘要:scheme里的宏不同的实现有不同的写法:1.mzscheme的define-macro (mzscheme也就是pltschme,也就是drracket,没有define-macro这个关键字)语法:(define-macro macro-name (lambda macro-args) macro-body ......)例如:定义when(define-macro when (lambda (test . branch) `(if ,test (begin ,@brach))))其中“·”重音号引入模版,逗号开始的符号为参数,逗号和@开始的被... 阅读全文
scheme 模拟queue
2013-11-16 22:03 by youxin, 316 阅读, 0 推荐, 收藏,
摘要:[code 1] shows a implementation of queue. The functionenqueue!returns a queue in that theobjis added at the last of thequeue. The functiondequeue!removes the first item from the queue and return the first item.[code 1](define (make-queue) (cons '() '()))(define (enqueue! queue obj) (let ((lo 阅读全文
scheme I/0 输入输出操作
2013-11-16 19:33 by youxin, 1959 阅读, 0 推荐, 收藏,
摘要:2.1.open-input-file,read-char, andeof-object?The function (open-input-filefilename) is available to open a file. This function return a port for input. The function (read-charport) is to read a character from theport. As this function returnseof-objectwhen it reaches the end of the file (EOF), you c 阅读全文
scheme递归
2013-11-16 17:25 by youxin, 543 阅读, 0 推荐, 收藏,
摘要:主要参考:http://www.shido.info/lisp/scheme7_e.htmlFunctionfactthat calculates factorials.(define (fact n) (if (= n 1) 1 (* n (fact (- n 1)))))(fact 5) is calculated like as follows:(fact 5)⇒ 5 * (fact 4)⇒ 5 * 4 * (fact 3)⇒ 5 * 4 * 3 * (fact 2)⇒ 5 * 4 * 3 * 2 * (fact 1)⇒ 5 * 4 * 3 * 2 * 1⇒ 5 *... 阅读全文
MIT-scheme安装
2013-11-16 16:49 by youxin, 1809 阅读, 0 推荐, 收藏,
摘要:下载地址:http://www.gnu.org/software/mit-scheme/下载windows版本,安装。The MIT-Scheme can be installed by just downloading and executing the installer.Go tothe homepage of MIT/GNU Schemeand download the Windows binary,mit-scheme-N.N.N-ix86-win32.exe.Double click the downloaded installer. The installer asks some 阅读全文
浙公网安备 33010602011771号