03 2015 档案
摘要:写作最快乐的事莫过于让作品成为阅读者心中的光芒。只要你敢,总会有光芒指引你。——韩寒(真是太忧伤了,刚才都写完了,不料Markdown被荡掉了,只能重写一遍了。)前些天读完了第三本韩寒的书——《我所理解的生活》,其实一直以来都觉得他的书名蛮有特色的——“他的国”、“1988:我想和这...
阅读全文
摘要:相信大家都会使用TextBox,但如果要让文本在TextBox中换行该怎么做呢?将TextWrapping属性设置为Wrap,将AcceptsReturn属性设置为True就好咯。PasswordBox很明显就是一个密码框了,和其他的控件相比其有2个特殊之处,一个是其可以用MaxLe...
阅读全文
摘要:练习4-5原文Exercise 4.5. Scheme allows an additional syntax for cond clauses, ( => ). If evaluates to a true value, then is evaluated. Its valu...
阅读全文
摘要:下面再来看看一些前面还没有讲过的控件,不过控件太多以至于无法全部列出来,大家只好举一反三啦。Button前面最常用的控件就是Button啦,Button还有一个有意思的属性呢,当把鼠标指针放在Button上时,就会在Button的头顶冒出一串文本啦。这个不太截图哎……Button有一...
阅读全文
摘要:添加控件的方式有多种,大家更喜欢哪一种呢? 1)使用诸如 Blend for Visual Studio 或 Microsoft Visual Studio XAML 设计器的设计工具。 2)在 Visual Studio XAML 编辑器中将控件添加到 XAML 标记中。 3)在代...
阅读全文
摘要:练习4-4原文Exercise 4.4. Recall the definitions of the special forms and and or from chapter 1: ● and: The expressions are evaluated from lef...
阅读全文
摘要:上一篇博客中大概的新建了一个应用,几乎是空白的。如果是初学者的话现在当然想往里面加点东西对不对。那么这篇博客就来看看页面的布局都是怎样的。首先安装上一篇博客中的顺序来新建一个项目。新建好之后就点开MainPage.xaml开始敲代码啦。^_^ ...
阅读全文
摘要:操作系统及SDK操作系统如果打算开发Windows App,那么你的电脑就不能再用老旧的Windows 7了。推荐使用Windows 8.1。写这篇博客的时候,我用的操作系统是Windows 10 Pro Technical Preview [Build 10041].操作系统除了在...
阅读全文
摘要:练习4-3原文Exercise 4.3. Rewrite eval so that the dispatch is done in data-directed style. Compare this with the datadirected differentiation pro...
阅读全文
摘要:练习4-2原文Exercise 4.2. Louis Reasoner plans to reorder the cond clauses in eval so that the clause for procedure applications appears before th...
阅读全文
摘要:练习4-1原文Exercise 4.1. Notice that we cannot tell whether the metacircular evaluator evaluates operands from left to right or from right to lef...
阅读全文
摘要:练习3-82原文Exercise 3.82. Redo exercise 3.5 on Monte Carlo integration in terms of streams. The stream version of estimate-integral will not hav...
阅读全文
摘要:练习3-81原文Exercise 3.81. Exercise 3.6 discussed generalizing the random-number generator to allow one to reset the random-number sequence so as...
阅读全文
摘要:练习3-77原文Exercise 3.77. The integral procedure used above was analogous to the “implicit” definition of the infinite stream of integers in sec...
阅读全文
摘要:练习3-72原文Exercise 3.72. In a similar way to exercise 3.71 generate a stream of all numbers that can be written as the sum of two squares in th...
阅读全文
摘要:练习3-71原文代码(define (Ramanujan s) (define (stream-cadr s) (stream-car (stream-cdr s))) (define (stream-cddr s) (stream-cdr (stre...
阅读全文
摘要:练习3-70原文代码(define (merge-weighted s1 s2 weight) (cond ((stream-null? s1) s2) ((stream-null? s2) s1) (else (let ((cars1 (stream-car ...
阅读全文
摘要:练习3-69原文代码(define (triples s t u) (cons-stream (list (stream-car s) (stream-car t) (stream-car u)) (interleave...
阅读全文
摘要:练习3-68原文Exercise 3.68. Louis Reasoner thinks that building a stream of pairs from three parts is unnecessarily complicated. Instead of separa...
阅读全文
摘要:练习3-67原文Exercise 3.67. Modify the pairs procedure so that (pairs integers integers) will produce the stream of all pairs of integers (i,j) (w...
阅读全文
摘要:练习3-66原文Exercise 3.66. Examine the stream (pairs integers integers). Can you make any general comments about the order in which the pairs are...
阅读全文
摘要:练习3-65原文Exercise 3.65. Use the series ln2 = 1- 1/2 + 1/3 - 1/4 + …… to compute three sequences of approximations to the natural logarithm of...
阅读全文
摘要:练习3-64原文Exercise 3.64. Write a procedure stream-limit that takes as arguments a stream and a number (the tolerance). It should examine the st...
阅读全文
摘要:练习3-63原文Exercise 3.63. Louis Reasoner asks why the sqrt-stream procedure was not written in the following more straightforward way, without t...
阅读全文
摘要:练习3-62原文Exercise 3.62. Use the results of exercises 3.60 and 3.61 to define a procedure div-series that divides two power series. Div-series ...
阅读全文
摘要:练习3-61原文 代码(define (reciprocal-series s) (cons-stream 1 (scale-stream (mul-series (stream-cdr s) ...
阅读全文
摘要:练习3-60原文Exercise 3.60. With power series represented as streams of coefficients as in exercise 3.59, adding series is implemented by add-stre...
阅读全文
摘要:练习3-59原文 代码a)(define (integrate-series s) (stream-map * (stream-map / ones integers) s))b)(define sine-series (cons-stream 0 (int...
阅读全文
摘要:练习3-58原文Exercise 3.58. Give an interpretation of the stream computed by the following procedure:(define (expand num den radix) (cons-str...
阅读全文
摘要:练习3-57原文Exercise 3.57. How many additions are performed when we compute the nth Fibonacci number using the definition of fibs based on the ad...
阅读全文
摘要:练习3-56原文Exercise 3.56. A famous problem, first raised by R. Hamming, is to enumerate, in ascending order with no repetitions, all positive in...
阅读全文
摘要:练习3-55原文Exercise 3.55. Define a procedure partial-sums that takes as argument a stream S and returns the stream whose elements are S0, S0 + S...
阅读全文
摘要:练习3-54原文Exercise 3.54. Define a procedure mul-streams, analogous to add-streams, that produces the elementwise product of its two input strea...
阅读全文
摘要:练习3-53原文Exercise 3.53. Without running the program, describe the elements of the stream defined by (define s (cons-stream 1 (add-streams s s)...
阅读全文
摘要:练习3-52原文Exercise 3.52. Consider the sequence of expressions(define sum 0) (define (accum x) (set! sum (+ x sum)) sum) (define seq (strea...
阅读全文
摘要:练习3-51原文Exercise 3.51. In order to take a closer look at delayed evaluation, we will use the following procedure, which simply returns its ar...
阅读全文
摘要:练习3-50原文Exercise 3.50. Complete the following definition, which generalizes stream-map to allow procedures that take multiple arguments, anal...
阅读全文
摘要:虽说叫做副作用显得不太好听,但在Lisp中副作用还是非常重要的。而相对于所有状态都必须显式地操作和传递额外参数的方式,如果引进赋值和将状态隐藏在局部变量中,那么就可以用更加模块化的方式来构造系统。正如你所知道的,不用任何赋值的程序设计称为函数式程序设计。相反,广泛采用赋值的程序设计称...
阅读全文
摘要:练习3-45原文Exercise 3.45. Louis Reasoner thinks our bank-account system is unnecessarily complex and error-prone now that deposits and withdrawa...
阅读全文
摘要:练习3-44原文Exercise 3.44. Consider the problem of transferring an amount from one account to another. Ben Bitdiddle claims that this can be acco...
阅读全文
摘要:练习3-42原文Exercise 3.42. Ben Bitdiddle suggests that it’s a waste of time to create a new serialized procedure in response to every withdraw an...
阅读全文
摘要:练习3-41原文Exercise 3.41. Ben Bitdiddle worries that it would be better to implement the bank account as follows (where the commented line has b...
阅读全文
摘要:改名的过程也是革新的过程。大到”苹果电脑公司“被改名为”苹果公司”,小到大学的校名更迭。甚至个人网名的更换也能印证其成长的岁月。联想收购ThinkPad和摩托罗拉之后都留了原名让粉丝们得到了些许安慰,不过我认为联想的ThinkPad远不如IBM的。至今依旧怀恋我的T30的键盘手感。今...
阅读全文
摘要:练习3-38原文Exercise 3.38. Suppose that Peter, Paul, and Mary share a joint bank account that initially contains 100. Concurrently, Peter deposi...
阅读全文
摘要:1-3月已读完书籍: 《环球科学》2014年12月号 《环球科学》2014年11月号 《环球科学》2015年2月号 《硅谷百年史——伟大的科技创新与创业历程(1900-2013)》 《了不起的盖茨比》 《古诗十九首》 《科学松鼠会》2014年4月 《码农增刊Linus与Linux》 ...
阅读全文
摘要:练习3-33原文Exercise 3.33. Using primitive multiplier, adder, and constant constraints, define a procedure averager that takes three connectors a...
阅读全文
摘要:练习3-28原文Exercise 3.28. Define an or-gate as a primitive function box. Your or-gate constructor should be similar to and-gate. 代码(define (or-g...
阅读全文
摘要:练习3-24原文Exercise 3.24. In the table implementations above, the keys are tested for equality using equal? (called by assoc). This is not alway...
阅读全文
摘要:练习3-23原文Exercise 3.23. A deque (“double-ended queue”) is a sequence in which items can be inserted and deleted at either the front or the rea...
阅读全文
摘要:你一事无成,还在那里傻乐。——韩寒《后会无期》过去的一年半,你踏入大学生活,接触了从未接触过的编程语言。你从一开始的C++语言跳到后来的C#语言,又从Common Lisp语言跳到Scheme语言,又从C语言跳到C#语言。直到现在算是定在了C#+Scheme。我不知道你还能坚持多久。...
阅读全文
摘要:练习3-22原文Exercise 3.22. Instead of representing a queue as a pair of pointers, we can build a queue as a procedure with local state. The local...
阅读全文
摘要:练习3-21原文Exercise 3.21. Ben Bitdiddle decides to test the queue implementation described above. He types in the procedures to the Lisp interpr...
阅读全文
摘要:练习3-8原文Exercise 3.8. When we defined the evaluation model in section 1.1.3, we said that the first step in evaluating an expression is to eva...
阅读全文
摘要:Office Open XML(缩写为:OpenXML或OOXML),为Microsoft开发的一种以XML为基础并以ZIP格式压缩的电子档案规范,支持档案、表格、备忘录、幻灯片等档案格式。从Office 2007开始,Open XML格式以及成为Office的预设文档格式——DOC...
阅读全文
摘要:关于数据抽象,有两个很重要的思想。一是在构建一些水平的抽象障碍在这个系统中。用某些对象来代换这些单独使用的抽象屏障。二是当需要使用某种形式的数据对象时,往往可以由其他人来将其实现,而我们并不需要知道具体操作。这都是在数据抽象方面非常强大的编程方法。但是这还不足以完成一个真正复杂的系统...
阅读全文
摘要:在书中符号数据一节中,作者写了关于微积分的演算规则的程序。这是一个很程序化的程序,我们所做的是在讲这些(数学)规则翻译成计算机语言。因为它有程序化的行为和结构,那么存在其他的方法使书写这个程序更加清晰吗?这些规则都具有左右两侧。左侧是我们想要采取的导数的表达式,有右边则是其的替代。用...
阅读全文
摘要:为添加…… 版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。
阅读全文
摘要:在学习书中第二章的时候有个问题一直让我很困扰,那就是2.2.4节的实例,因为没法输出书中华丽的图案,只能是一对英文字母。这在几个月前浅浅的学了一会Common Lisp的时候也是如此,当时看到书中有个实例是书中输出了很赞的线条,而我只会输出一堆点。后来才知道让Lisp输出图形化界面是...
阅读全文
摘要:上一篇博文对应的是书中的第一章的一二两节,我们已经大致的有了一种构造的感觉不是么。书中展示了很多有趣的句法(syntax)。现在我们要让思想进一步的抽象,写这篇博客的时候并未学完整本书,更不敢说对书中的内容有一个多深的领悟。但我一路学习过来,就感觉书中的示例越来越抽象,作者所引导我们...
阅读全文
摘要:《计算机程序的构造和解释》这本书的目标并不是讲解一门编程语言的语法等,它是一种方法。不是在向你陈述知识,而是在教你如何做到想要做的东西。它是一个过程,一个精神。这些引导过程的东西就是所谓的程序规则的模式。书中用了许多的例子来诠释书名,我才疏学浅就不再举例往博客上推了,仅仅归纳一点总结...
阅读全文
摘要:display在common lisp中有format,在scheme中则有display,轻松应对各种输出。(display(+ 1 2 3 4))10;Unspecifiedreturn value(display‘(1 2 3 4))(12 3 4);Unspecifiedre...
阅读全文
摘要:赋值因为Scheme是函数式语言,通常来说,你可以编写不使用赋值的语句。然后如果使用赋值的话,有些算法就可以轻易实现了。尤其是内部状态和继续(continuations)需要赋值。R5RS中规定的用于赋值的特殊形式是set!,set-car!,set-cdr!,string-set!...
阅读全文
摘要:Scheme的数据结构在前面的博文中我们使用了list等等,像其他的编程语言一样,Scheme也有字符(Character),字符串(String),符号(Symbol),向量(Vector)等数据结构。下面我们来一一介绍。字符在某个字符前添加#\来表面该物是一个字符。例如,#\a表...
阅读全文
摘要:高阶函数的介绍高阶函数的英文名称是Higher Order Function,它们是以函数为参数的函数。主要用于映射(mapping)、过滤(filtering)、归档(folding)和排序(sorting)表。高阶函数让程序更具模块性,让函数更加通用。函数sort具有2个参数,一...
阅读全文
摘要:对象的比较eq?这个函数用来比较2个对象的地址,如果相同的话就返回#t。在Scheme中真用#t表示,假则用#f。 例如,(eq? str str)返回#t,因为str本身的地址的是一样的,但是”scheme”和”scheme”则被存储在不同的地址中,因此函数返回#f。注意,不要用e...
阅读全文
摘要:quotient、remainder、modulo和sqrt函数quotient用于求商数(quotient)。 函数remainder和modulo用于求余数(remainder)。 函数sqrt用于求参数的平方根(square root)。 以下是一些示例:(quotient73...
阅读全文
摘要:Edwin介绍Edwin是MIT Scheme系统的一个窗口式的编辑使用前端。启动Edwin实际是先启动Scheme系统,再启动也给Edwin前端。Edwin是一个使用Scheme写的交互式编辑器,其特点是支持Scheme表达式的编辑和求职。两种模式Edwin模式: 编辑Scheme...
阅读全文
摘要:练习3-7原文Exercise 3.7. Consider the bank account objects created by make-account, with the password modification described in exercise 3.3. Sup...
阅读全文
摘要:练习3-5原文Exercise 3.5. Monte Carlo integration is a method of estimating definite integrals by means of Monte Carlo simulation. Consider comput...
阅读全文
摘要:练习3-1原文Exercise 3.1. An accumulator is a procedure that is called repeatedly with a single numeric argument and accumulates its arguments int...
阅读全文
摘要:练习2-81这里再次需要用到第186页的创建表格部分内容。当然了现在完全可以只是将make-table加载到这道题中。还有我们前面几题中用到的apply-generic。a) 载入 Louis 的强制过程后,对两个复数调用exp会出现解释器假死的情况。b) Louis并没有纠正该...
阅读全文
摘要:练习2-79首先需要加载第125页的apply-generic函数,然后添加题中要求的通用型操作equ?。(define (equ? x y)(apply-generic ‘equ? x y))题目要求我们能够处理常规的数、有理数和复数。分别列出如下。常规数:(define (ins...
阅读全文
摘要:练习2.77我们首先来看看题目中描述的问题,当Louis Reasoner试着求值(magnitude z)时,程序中不断的寻找。一开始是通过apply-generic、而后是map,最后是get。这三个函数在书中都有很好的解释,我自知才疏学浅就不介绍了。最后一步的get中,最后由于...
阅读全文
摘要:练习2.76这是一道论述题了吧。首先是带有显示反派的通用型操作,这种策略要求使用者留意命名方面的冲突。如书上所说,这种策略具有不可加性,因为每当增加新类型的时候,所有通用型操作都要求做相应的修改以适配新的类型。至于增加新的操作,同样因为这一点而不适用。然后是数据导向的风格,如书上的大...
阅读全文
摘要:练习2.75通过模仿书上的make-from-real-imag函数来完成此题。(define (make-from-mag-ang x y) (define (dispatch op) (cond ((eq? op ‘real-part) ...
阅读全文
摘要:练习2.73a小题,这是由于Scheme对数字、变量的直接规定,前者会被当作数值类型,后者则会被当作符号类型。因此没必要将这两个谓词添加到数据导向分派中了。如果给数值类型或者符号类型加上一个标志,在get的过程中,又对已知的类型做判断,岂不是在浪费空间和时间。 b小题,我们根据书中已...
阅读全文
摘要:练习2.70既然要解码,那必须先将树给定义好了。(define tree (generate-huffman-tree ‘((A 2) (NA 16) (BOOM 1) (SHA 3) (GET 2) (YIP 9) (JOB 2) (WAH 1))然后就是来编码题目中给出的歌词了。...
阅读全文
摘要:练习2.69如题目中所说,传入给successive-merge的参数是一个有序的集合。而这个函数将通过不断的归并得到最终的一个元素。如果传入的集合为0,也就是说返回的表应该是空表。如果传入的集合为1,那么将传入的集合的car部分取出来,这就是Huffman树了。而如果传入的集合大于...
阅读全文
摘要:练习2.68先要导入练习2.67中的sample-tree。这道题要求我们写出能够根据给定的树产生出给定符号的二进制位表的函数encode-symbol,这个函数还要能够在遇到未在树中出现的符号时报错。这个函数将要在给定的树中查找给定符号的叶子节点,并记录下寻找过程中的左右方向,当然...
阅读全文
摘要:练习2.67我们先来把该导入的导入,然后就来测试了。(load "d:\\lisp\\tree.scm")(define sample-tree (make-code-tree (make-leaf 'A 4) (make-code-tree (make-leaf...
阅读全文
摘要:练习2.66这道题相当于二叉树在实际工程中的一个运用,我们依旧要用到前面所学到的三个过程:entry, left-branch, right-branch。这三者的作用分别是取出结点、左分支、右分支。而根据题目要求,这里还需要一个获取键值的key。当然了,就像书中上文所展示的那样,k...
阅读全文
摘要:练习2.65最后一道题了,来个总结倒是很不错。要完成两个函数,我们就要用到前面所学,首先用练习2.63中的函数将树变成表,这样有利于后续的处理,而根据前面的习题,用tree->list-2会更加快速。然后要实现并集或补集的功能,也要用到第104页相关的函数。题目要求的是平衡二叉树,因...
阅读全文
摘要:练习2.64一开始list->tree会调用partial-tree,而后者会将每次传入的表分成两部分,然后组合成一个平衡树。中间运用了迭代的技巧,而这是让众多树枝产生的源泉。如果我们对前面的表’(1 3 5 7 9 11)做计算,返回的结果将会是: (5 (1 () (3 () (...
阅读全文
摘要:练习2.63这两段代码的区别在于第二段用了迭代,相信可以大大减少计算时间。那么还是先来测试第一小题。需要的代码大家先敲进去。然后来定义图2-16中的三棵树了。(define tree-1 (make-tree 7 (make-tree 3 ...
阅读全文
摘要:练习2.62前面已经遇到过了,union-set是用来取并集的。我们要通过多种情况来完成这个程序。(define (union-set set1 set2) (cond ((and (null? set1) (null? set2)) '()) ((nul...
阅读全文
摘要:练习2.60这里的adjoin-set通过遍历后使用cons将表进行不断的组合,并在组合的过程中将x加到集合中去。(define (adjoin-set x set) (if (null? set) (list x) (let ((current-eleme...
阅读全文
摘要:练习2.59我们可以采用迭代来完成这个过程,至于怎么迭代的,接下来就是代码了。(define (union-set set1 set2) (define (union-set-iter set1 set2) (if (null? input) ...
阅读全文
摘要:练习2.58如果要由前序变成中序那就要有些大变动了。(define (make-sum a1 a2) (cond ((=number? a1 0) a2) ((=number? a2 0) a1) ((and (number? a1) (number?...
阅读全文
摘要:练习2.57看到题目中的能处理任意项就赶紧这道题挺难的,同时也想到了前面学过但还没怎么用过的点参数。题目中要能求和还能求乘积。我们先来写求和的函数吧。(define (make-sum a1 . a2)(if (single-operand? a2) (let ((a2 (car...
阅读全文
摘要:这道题的代码略长啊。不过我也是因此而知道Edwin上的代码居然可以复制到word上,以前还想当然的以为不能复制的,毕竟在Edwin上粘贴用的Ctrl+Y,而不是Ctrl+V。在这里我就只将书上没有的代码贴出来了。(define (deriv exp var) (cond ((nu...
阅读全文
摘要:练习2.55 书上已经说过了在求值过程中引号会被替换成quote。因为表达中有2个单引号,因此car得到了第二个单引号。如果是cdr则会得到后面的一串字母。(cdr ‘’abracadabra);Value: (abracadabra) ...
阅读全文
摘要:这些关于Scheme的基本知识在【Scheme归纳】系列博文总都有介绍。(define (equal? x y) (cond ((and (symbol? x) (symbol? y)) (symbol-equal? x y)) ...
阅读全文

浙公网安备 33010602011771号