摘要: The Why of Y Richard P. Gabriel Lucid, Inc. and Stanford University 翻译:硅胶鱼 你有没有好奇过Y组合子是如何工作的以及怎么会有人能把牠给搞出来?在这篇文章里我将会试着向你解释牠是如何工作的,以及更牛的——神牛是怎么把牠发明出来的,我将使用Scheme语言的记号,因为把函数作为参数传递时,这样写更容易理解。 Y的意义就是牠提供不使用内建方法而实现自引用程序的机制(就是说Y能实现函数的匿名递归——译者注)。Scheme语言提供了几种实现递归的机制,比如定义全局函数和使用关键字letrec。下面就是Scheme中阶乘... 阅读全文
posted @ 2012-04-01 21:58 硅胶鱼 阅读(639) 评论(0) 推荐(0) 编辑
摘要: scheme并不提供list comprehension特性,但是在stackoverflow上可以看到几个提供list comprehension的库(Swindle已经是个语言了):Swindleis primarily a CLOS emulator library, but it has list comprehensions too. I've used them, they're convenient, but the version I used was buggy and incomplete. (I just needed generic functions. 阅读全文
posted @ 2012-03-31 23:13 硅胶鱼 阅读(712) 评论(0) 推荐(0) 编辑
摘要: [song] LyricsbyBob Kanefsky, sung byJulia EcklarI was taught assemblerin my second year of school.It's kinda like construction work —with a toothpick for a tool.So when I made my senior year,I threw my code away,And learned the way to programthat I still prefer today.Now, some folks on the Inter 阅读全文
posted @ 2012-03-31 22:20 硅胶鱼 阅读(278) 评论(0) 推荐(0) 编辑
摘要: lisp语言哲学就是:你不该写代码,你应该写宏,让这些宏来为你自动生成代码作为lisp家族的主要成员之一的scheme拥有最先进的现代宏系统,利用模式匹配写个通用图灵机是非常简单的,下面就是完整代码:#!r6rs(import(rnrs))(define(get-stateconfiguration)(carconfiguration))(define(get-tapeconfiguration)(cadrconfiguration))(define(get-positionconfiguration)(caddrconfiguration))(define-syntaxcompile-tra 阅读全文
posted @ 2012-03-28 21:30 硅胶鱼 阅读(808) 评论(0) 推荐(0) 编辑
摘要: 在用syntax-case的时候,多处使用quasisyntax,unsyntax,unsyntax-splicing会把代码搞的跟咒语一样:;无法嘲笑perl了(syntax-case#'(a123)()[(name.args)#`(name#,@#'args)]这个时候with-syntax就又用了,能让代码可读性好很多:;又可以嘲笑perl了(syntax-case#'(a123)()[(name.args)(with-syntax([(a...)#'args])#'(namea...))])宏的模板部分就简单多了with-syntax语法跟let 阅读全文
posted @ 2012-03-28 11:42 硅胶鱼 阅读(314) 评论(0) 推荐(0) 编辑
摘要: scheme目前其实有至少三套宏系统:完全hygiene的syntax-rules(define-syntax)可以hygiene也可以dirty的syntax-case(define-syntax)逐步被淘汰的lisp传统宏系统define-macro(有些实现里叫defmacro)syntax-rules的能力是受限的,不能引入新的syntax-object,只能写一些简单的宏.但是用syntax-rules写出来的宏肯定比用syntax-case或define-macro写的更优雅.syntax-case完全不受限制,扩展能力与传统lisp宏(defmacro)是一样的,但由于它自带模式 阅读全文
posted @ 2012-03-27 23:32 硅胶鱼 阅读(1074) 评论(0) 推荐(0) 编辑